GraphRAG
Graph-based retrieval augmented generation — how MemNexus uses graph structure to answer complex queries.
GraphRAG combines graph traversal with retrieval augmented generation (RAG) to answer queries that flat search can't handle. It uses the relationships between memories, topics, entities, and communities to build richer context.
What is RAG?
Retrieval Augmented Generation (RAG) is a pattern where you:
- Retrieve relevant documents or data
- Augment a prompt with that context
- Generate a response using an LLM
Standard RAG retrieves documents by similarity. GraphRAG goes further — it traverses the knowledge graph to find connections, communities, and relationships that provide deeper context.
How GraphRAG works in MemNexus
Query: "What technical decisions shaped this project?"
│
├──→ Standard search: finds memories mentioning "decisions"
│
└──→ GraphRAG:
├── Finds memories mentioning decisions
├── Traverses to related topics (architecture, database, tooling)
├── Discovers communities (backend, infrastructure, frontend)
├── Follows entity relationships (Neo4j → Graph Database → MemNexus)
└── Synthesizes context from the entire subgraph
The result is a much richer answer that connects information across multiple memories and relationships.
GraphRAG vs. standard search
| Feature | Standard search | GraphRAG |
|---|---|---|
| Matching | Semantic similarity | Graph traversal + similarity |
| Scope | Individual memories | Connected subgraphs |
| Context | Single memory content | Relationships, communities, facts |
| Best for | Finding specific memories | Answering complex questions |
| Speed | Fast | Slower (graph traversal) |
Using GraphRAG
CLI
# Graph-based query
mx graphrag query --query "What technical decisions shaped this project?"
# Query across communities
mx graphrag query-communities --query "infrastructure changes" --limit 5
# Explain a memory's graph context
mx graphrag explain --memory-id mem_abc123
SDK
// Graph-based query
const results = await client.graphrag.query({
query: "What technical decisions shaped this project?",
});
// Community-based query
const communities = await client.graphrag.queryCommunities({
query: "infrastructure changes",
limit: 5,
});
MCP
MCP-connected agents can use the graphrag_query tool:
{
"query": "What technical decisions shaped this project?",
"depth": 2,
"includeRelationships": true
}
Community queries
Communities are groups of related topics detected by graph algorithms. Community queries search across these groups to find broad, thematic answers.
For example, if you ask "What's our infrastructure story?", a community query might:
- Find the "Infrastructure" community (containing deployment, Docker, CI/CD topics)
- Retrieve all memories in those topics
- Synthesize a summary across the entire community
This produces a comprehensive answer that spans multiple topics and time periods.
When to use GraphRAG
- Broad questions — "What are the main themes of this project?"
- Cross-topic queries — "How do our database and deployment decisions relate?"
- Summarization — "Give me an overview of recent technical decisions"
- Discovery — "What connections exist that I haven't noticed?"
For specific lookups ("what database do we use?"), standard search is faster and sufficient.
Graph traversal depth
The depth parameter controls how many relationship hops GraphRAG follows:
- Depth 1 — Direct relationships only (memory → topic, memory → entity)
- Depth 2 — Two hops (memory → topic → related topic → other memories)
- Depth 3+ — Broader exploration (slower, more comprehensive)
Start with depth 2 for most queries. Increase only if results feel incomplete.