Skip to content

[Bug]: visualize_graph() returns "No nodes found" while search() returns full graph (dataset routing bug) #3007

@shubhamdange123

Description

@shubhamdange123

Bug Description

Summary

cognee.api.v1.visualize.visualize.visualize_graph() reports "No nodes found in the database"
and produces an empty HTML, while cognee.search() on the same kernel session returns the
full populated graph. The root cause is that visualize_graph() calls
get_graph_engine() without resolving the user's dataset, so it opens the default
(empty) graph DB instead of the per-dataset DB that cognify() actually wrote to.

Environment

  • cognee version: <run pip show cognee | grep Version and paste>
  • Python: 3.12
  • Platform: Google Colab
  • Graph DB provider: ladybug (default)
  • LLM provider: anthropic
  • Embedding provider: fastembed (sentence-transformers/all-MiniLM-L6-v2, 384 dim)

Repro

import cognee, os
from cognee import SearchType

os.environ["LLM_API_KEY"] = "<key>"
cognee.config.set_llm_provider("anthropic")
cognee.config.set_llm_model("anthropic/claude-sonnet-4-20250514")
cognee.config.set_embedding_provider("fastembed")
cognee.config.set_embedding_model("sentence-transformers/all-MiniLM-L6-v2")
cognee.config.set_embedding_dimensions(384)

doc_text = "OmniTech Corp utilizes Aurora-Pay hosted on AWS. Sarah Jenkins leads the DevOps team and assigned a ticket to David Cho."

await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)
await cognee.add(doc_text)
await cognee.cognify()

# This works — returns 27 nodes, 40+ edges:
result = await cognee.search(
    query_text="MATCH (n)-[r]->(m) RETURN n, r, m",
    query_type=SearchType.CYPHER,
)
print(len(result[0]["search_result"]))  # > 0

# This fails — "No nodes found in the database":
from cognee.api.v1.visualize.visualize import visualize_graph
await visualize_graph(destination_file_path="graph.html")

Diagnosis

The default graph engine points at the install-dir default DB:
/usr/local/lib/python3.12/dist-packages/cognee/.cognee_system/databases/cognee_graph_ladybug

But cognify() wrote data to the per-dataset DB:
./.cognee_system/databases/<dataset_uuid>/<some_uuid>.lbug (1.6 MB)

visualize_graph() body:

async def visualize_graph(destination_file_path: str = None) -> str:
    graph_engine = await get_graph_engine()         # <-- no dataset context
    graph_data = await graph_engine.get_graph_data()
    ...

Compare with search(), which resolves get_default_user() and the authorized
datasets before constructing a dataset-scoped engine.

Suggested fix

visualize_graph() should mirror search()'s dataset resolution path so the
returned engine points at the dataset's actual DB file. Roughly:

async def visualize_graph(destination_file_path=None, datasets=None, user=None):
    user, datasets = await resolve_authorized_user_datasets(datasets, user)
    # build engine for these datasets, then get_graph_data()
    ...

Workaround

Pull the graph through CYPHER and feed cognee_network_visualization directly:

from cognee.modules.visualization.cognee_network_visualization import cognee_network_visualization
results = await cognee.search(
    query_text="MATCH (n)-[r]->(m) RETURN n, r, m",
    query_type=SearchType.CYPHER,
)
# reshape into (nodes, edges) tuple and call cognee_network_visualization(...)

Happy to send a PR if there's interest.

Steps to Reproduce

  1. Configure cognee with Anthropic LLM + fastembed embeddings on Google Colab:
   import cognee, os
   from cognee import SearchType

   os.environ["LLM_API_KEY"] = "<your-key>"
   cognee.config.set_llm_provider("anthropic")
   cognee.config.set_llm_model("anthropic/claude-sonnet-4-20250514")
   cognee.config.set_embedding_provider("fastembed")
   cognee.config.set_embedding_model("sentence-transformers/all-MiniLM-L6-v2")
   cognee.config.set_embedding_dimensions(384)
  1. Add some text and cognify:
   doc_text = "OmniTech Corp utilizes Aurora-Pay hosted on AWS. Sarah Jenkins leads the DevOps team and assigned a ticket to David Cho."

   await cognee.prune.prune_data()
   await cognee.prune.prune_system(metadata=True)
   await cognee.add(doc_text)
   await cognee.cognify()
  1. Confirm graph exists via CYPHER search — returns 27 nodes, 40+ edges:
   result = await cognee.search(
       query_text="MATCH (n)-[r]->(m) RETURN n, r, m",
       query_type=SearchType.CYPHER,
   )
   print(len(result[0]["search_result"]))  # > 0
  1. Try to visualize the same graph — fails with "No nodes found":
   from cognee.api.v1.visualize.visualize import visualize_graph
   await visualize_graph(destination_file_path="graph.html")
  1. Observe log output:

Expected Behavior

visualize_graph() should render the same graph that cognee.search() returns
on the same kernel session — in this case 27 nodes and 40+ edges from the cognified
document. The output HTML should contain populated nodes and links arrays
and render the interactive D3 graph view.

Actual Behavior

visualize_graph() reports "No nodes found in the database" and writes an HTML
file with empty nodes and links arrays, even though cognee.search() on the
same dataset, same session, returns the full graph through the CYPHER and
GRAPH_COMPLETION search types.

Root cause: visualize_graph() calls get_graph_engine() without resolving the
user's dataset, so it opens the default install-dir DB instead of the per-dataset
DB that cognify() wrote to.

The default engine points at:
/usr/local/lib/python3.12/dist-packages/cognee/.cognee_system/databases/cognee_graph_ladybug

But cognify wrote data to (1.6 MB):
./.cognee_system/databases/<dataset_uuid>/<file_uuid>.lbug

Compare visualize_graph() body:

async def visualize_graph(destination_file_path: str = None) -> str:
    graph_engine = await get_graph_engine()         # no dataset context
    graph_data = await graph_engine.get_graph_data()
    ...

with search(), which calls resolve_authorized_user_datasets() first and
builds a dataset-scoped engine.

Suggested fix: have visualize_graph() accept optional datasets / user
kwargs (matching search()) and resolve them before building the engine.

Workaround that works:

from cognee.modules.visualization.cognee_network_visualization import cognee_network_visualization
results = await cognee.search(
    query_text="MATCH (n)-[r]->(m) RETURN n, r, m",
    query_type=SearchType.CYPHER,
)
# Reshape triples into (nodes, edges) tuple and call cognee_network_visualization()

Environment

  • cognee version: <run pip show cognee | grep Version>
  • Python: 3.12
  • Platform: Google Colab
  • Graph DB provider: ladybug (default)
  • Vector DB provider: lancedb (default)
  • LLM provider: anthropic
  • Embedding provider: fastembed (sentence-transformers/all-MiniLM-L6-v2, 384 dim)

Logs/Error Messages

Additional Context

Expected behavior - visualize_graph() should render the same graph that cognee.search() returns
on the same kernel session — in this case 27 nodes and 40+ edges from the cognified
document. The output HTML should contain populated nodes and links arrays
and render the interactive D3 graph view.

Pre-submission Checklist

  • I have searched existing issues to ensure this bug hasn't been reported already
  • I have provided a clear and detailed description of the bug
  • I have included steps to reproduce the issue
  • I have included my environment details

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions