GraphRAG for Agent Memory

AI Engineergo watch the original →

Vector-based RAG struggles with complex, multi-hop reasoning because similarity is not a relationship. Storing agent memory as a graph allows for precise, auditable traversals that outperform markdown-based or vector-only memory systems.

The Breakthrough

Replacing flat markdown or vector-only memory stores with a graph-based memory system enables agents to perform multi-hop reasoning over connected data, allowing them to answer complex queries that vector similarity searches fail to resolve.

What Actually Worked

  • Hybrid Retrieval: Use vector search to identify initial "seed nodes" in the graph, then perform graph traversals to find related entities and relationships rather than relying on vector similarity alone.
  • Graph-Based Memory: Structure agent memory as a graph of nodes and edges with properties, which allows for precise, explainable, and auditable retrieval of information.
  • Cypher Generation: Leverage LLMs like Claude to generate Cypher queries for graph extraction and traversal, removing the need for deep manual expertise in graph database languages.
  • Digital Twin Modeling: Map complex environments (like a home lab or enterprise network) into a graph to track dependencies, such as linking specific servers to their OS versions and network exposure status.

Before / After

  • Vector-only agent: Failed to identify specific end-of-life software or exposed management ports, returning vague responses like "could not find specific details" or suggesting the user manually check configurations.
  • Graph-based agent: Successfully identified specific servers (e.g., "tinsterland") running outdated OS versions and correctly flagged exposed management ports (e.g., "haproxy") by traversing the network topology graph.

Context

Most current AI agents store memory as markdown files or raw vector embeddings. This approach consumes excessive tokens by forcing the agent to load large amounts of context, and it frequently fails at multi-hop reasoning because vector similarity does not represent actual logical relationships. By using a graph as a memory layer, agents can navigate structured data to provide accurate, context-aware answers that are traceable to specific nodes in the graph.

Notable Quotes

  • "Similarity in vector space is not the same as actual relationships, and so you get hallucinations."
  • "If you're not a graph expert, guess what? Claude can write Cypher better than I can."

Content References

  • book: GraphRAG: The Definitive Guide by Michael Hunger, Osus Barasa, and Stephen Chin, cited as a resource for graph-based agent memory.
  • tool: Neo4j, mentioned as the graph database backend.
  • tool: Cognite, mentioned as the memory management layer used in the demo.
  • tool: Goose, mentioned as an agentic automation tool using MCP.
  • tool: MCP (Model Context Protocol), mentioned as the standard for agent tool integration.
  • event: GraphAcademy, recommended as a free training resource for graph technology.
  • #ai
  • #rag
  • #graph-databases

summary by google/gemini-3.1-flash-lite. probably wrong about something. check the source.