Graph Visualization Guide
One of Cognee’s most powerful features is its ability to visualize knowledge graphs. This guide explains how to generate, view, and interpret graph visualizations with default setting using NetworkX.
Generating a Graph Visualization
Using API (no credentials required)
You can generate a visualization of your knowledge graph using the API:
import cognee
from cognee.api.v1.visualize.visualize import visualize_graph
import asyncio
async def main():
# Add some content first
await cognee.add("Albert Einstein was a theoretical physicist born in Germany.")
await cognee.add("Einstein developed the theory of relativity.")
# Process the content
await cognee.cognify()
# Generate an HTML visualization of your graph
await visualize_graph()
# The file is saved in your current folder
home_dir = os.path.expanduser("~")
html_file = os.path.join(home_dir, "graph_visualization.html")
display(html_file)
if __name__ == "__main__":
asyncio.run(main())
Using Graphistry
For this you will need to:
- create an account and API key from https://www.graphistry.com
- add the following environment variables to
.env
file:
GRAPHISTRY_USERNAME=""
GRAPHISTRY_PASSWORD=""
import cognee
from cognee.shared.utils import render_graph
import asyncio
async def main():
# Add some content first
await cognee.add("Albert Einstein was a theoretical physicist born in Germany.")
await cognee.add("Einstein developed the theory of relativity.")
# Process the content
await cognee.cognify()
# Generate the visualization
await render_graph()
# You will get the URL to graphistry something like:
# https://hub.graphistry.com/graph/...
if __name__ == "__main__":
asyncio.run(main())
Understanding the Visualization
The graph visualization shows:
Nodes
Nodes represent entities extracted from your content:
- People: Individuals mentioned in your content (e.g., “Albert Einstein”)
- Concepts: Abstract ideas or topics (e.g., “Theory of Relativity”)
- Organizations: Companies, institutions, etc.
- Locations: Places mentioned in your content
- Events: Occurrences or happenings
- Other entities: Various other types of information
Edges
Edges (lines connecting nodes) represent relationships between entities:
- The label on each edge describes the relationship (e.g., “developed”, “was born in”)
- The direction of the relationship is indicated by the arrow
Interacting with the Visualization
The visualization is interactive:
- Zoom: Use the mouse wheel to zoom in and out
- Pan: Click and drag to move around the graph
- Select: Click on nodes to highlight their connections
- Hover: Hover over nodes and edges to see more details
- Rearrange: Drag nodes to rearrange the layout
Example Interpretation
Let’s interpret a simple example:
- You add content about Albert Einstein
- The visualization shows:
- A node for “Albert Einstein” (Person)
- A node for “Germany” (Location)
- A node for “Theory of Relativity” (Concept)
- An edge from Einstein to Germany labeled “was born in”
- An edge from Einstein to Theory of Relativity labeled “developed”
This visualization helps you understand how different pieces of information are connected in your knowledge graph.
Troubleshooting
If you’re having trouble with the visualization:
- Empty graph: Make sure you’ve added content and run
cognee.cognify()
before generating the visualization - File not found: Check the system folder path and ensure the file exists
- Browser security: Some browsers restrict opening local files; try using Firefox or Chrome
- Large graphs: For very large graphs, the visualization may be slow; try filtering to include only specific node types
Next Steps
- Learn how to query your knowledge graph
- Explore advanced visualization options
- See how to build custom pipelines for specialized graph generation