Memgraph GraphRAG for Agent Systems (Language-Agnostic)
Build Graph Retrieval-Augmented Generation systems that combine vector similarity search with graph traversal, and expose retrieval as tools for agents across any programming language.
When to Use
Use this skill when:
- Designing a GraphRAG platform (not a single app)
- Supporting multiple client languages (Python, JS, Java, Go, etc.)
- Building agent tools for ingestion, retrieval, and diagnostics
- Combining document chunk retrieval with entity/relationship context
Do NOT use this skill for:
- Simple vector-only RAG or standalone chatbots
- Pure ETL without retrieval or agent workflows
- Use cases that require strict SQL semantics
Outcomes
By following this skill, you will deliver:
- A graph schema that supports hybrid retrieval
- A repeatable ingestion pipeline
- A retrieval tool contract usable by agents
- An evaluation plan for recall, latency, and groundedness
Architecture Overview
Sources (files, URLs, APIs)
│
▼
┌──────────────────────┐
│ Ingestion Pipeline │ Parse → chunk → entity extract
└──────────────────────┘
│
▼
┌──────────────────────┐
│ Memgraph │ Graph + embeddings + indexes
└──────────────────────┘
│
▼
┌──────────────────────┐
│ Hybrid Retriever │ Vector search + graph expansion
└──────────────────────┘
│
▼
┌──────────────────────┐
│ Agent Tools │ run_query / retrieve_context
└──────────────────────┘
│
▼
┌──────────────────────┐
│ LLM Response │ Answer with citations
└──────────────────────┘
Step 1: Define GraphRAG Requirements
Document the following before implementation:
- Use cases: Q&A, research, report generation, troubleshooting
- Source types: PDFs, HTML, Markdown, APIs, databases
- Entity types: People, systems, components, products, errors
- Relationship types: MENTIONS, CONNECTS_TO, DEPENDS_ON, NEXT
- Latency targets: P95 retrieval time, max hops for expansion
Step 2: Choose Ingestion Strategy
Pick one of these:
- Toolkit-based:
unstructured2graph + lightrag-memgraph
- Custom ETL: your parser + entity extractor + Cypher loader
- Batch migration: sql2graph for relational sources
Ingestion must always produce:
- Chunk nodes with text + source metadata
- Entity nodes with normalized names
- Relationships that connect entities to chunks and each other
Step 3: Standard Graph Schema (Recommended)
Use a stable schema so any client can query consistently:
Nodes
Document {id, title, source, created_at}
Chunk {id, text, source, embedding}
Entity {id, name, type, description}
Concept {id, name}
Relationships
(Document)-[:HAS_CHUNK]->(Chunk)
(Entity)-[:MENTIONED_IN]->(Chunk)
(Entity)-[:RELATES_TO]->(Entity)
(Chunk)-[:NEXT]->(Chunk)
Step 4: Embeddings + Vector Index
- Store embeddings on
Chunk.embedding
- Create a vector index for
Chunk(embedding)
- Use Memgraph’s vector search in retrieval
Keep embeddings consistent across ingestion and queries.
Step 5: Hybrid Retrieval Strategy
Default retrieval flow:
- Vector search to get top-$k$ chunks
- Graph expansion to include related chunks/entities
- Ranking by degree, recency, or path length
- Dedup and trim to the model context budget
Recommended query pattern (pseudo-Cypher):
- Vector search on
Chunk
- BFS traversal limited to $1–3$ hops
- Return chunk text + related entities
Step 6: Agent Tool Contracts
Expose retrieval and diagnostics as tools. Minimal contract:
Tool: run_query
- Input:
{ cypher: string, params?: object }
- Output:
{ rows: array }
Tool: retrieve_context
- Input:
{ question: string, vector_k?: number, hop_limit?: number }
- Output:
{ chunks: [{text, source, entities[]}], graph_stats }
Tool: ingest_sources
- Input:
{ sources: string[], mode?: "append" | "replace" }
- Output:
{ documents, chunks, entities, duration_ms }
Agents should:
- Call
get_schema once per session
- Use parameterized queries
- Log retrieval traces for debugging
Step 7: Language-Agnostic Integration
Memgraph supports the Bolt protocol. Use a Bolt-compatible driver in your language of choice.
Integration responsibilities in each language:
- Create a connection pool
- Execute parameterized Cypher
- Map results to your tool contract
- Handle retries and timeouts
Step 8: Evaluation & Observability
Minimum evaluation suite:
- Recall@k: relevant chunks retrieved
- Groundedness: answer supported by chunks
- Latency: P95 retrieval under target
- Coverage: percent of sources indexed
Log for each request:
- Query text
- Top vector hits
- Expansion hops used
- Final context length
Guardrails
- Always answer from retrieved context
- If context is insufficient, say so
- Avoid unbounded graph traversal
- Enforce per-request timeouts
Optional: Use Memgraph AI Toolkit
Use the Memgraph AI Toolkit for faster setup:
memgraph-toolbox for core utilities
unstructured2graph for parsing and ingestion
lightrag-memgraph for entity extraction
langchain-memgraph for agent tooling
Treat these as implementation options, not requirements.
1---2name: memgraph-graph-rag3description: Language-agnostic blueprint for building GraphRAG systems with Memgraph and agent tooling. Covers end-to-end architecture, schema design, ingestion, hybrid retrieval, tool contracts, and evaluation. Use when designing GraphRAG platforms that must work across multiple programming languages.4---56# Memgraph GraphRAG for Agent Systems (Language-Agnostic)78Build Graph Retrieval-Augmented Generation systems that combine vector similarity search with graph traversal, and expose retrieval as tools for agents across any programming language.910## When to Use1112Use this skill when:1314- Designing a GraphRAG platform (not a single app)15- Supporting multiple client languages (Python, JS, Java, Go, etc.)16- Building agent tools for ingestion, retrieval, and diagnostics17- Combining document chunk retrieval with entity/relationship context1819Do NOT use this skill for:2021- Simple vector-only RAG or standalone chatbots22- Pure ETL without retrieval or agent workflows23- Use cases that require strict SQL semantics2425## Outcomes2627By following this skill, you will deliver:2829- A graph schema that supports hybrid retrieval30- A repeatable ingestion pipeline31- A retrieval tool contract usable by agents32- An evaluation plan for recall, latency, and groundedness3334## Architecture Overview3536```37Sources (files, URLs, APIs)38 │39 ▼40┌──────────────────────┐41│ Ingestion Pipeline │ Parse → chunk → entity extract42└──────────────────────┘43 │44 ▼45┌──────────────────────┐46│ Memgraph │ Graph + embeddings + indexes47└──────────────────────┘48 │49 ▼50┌──────────────────────┐51│ Hybrid Retriever │ Vector search + graph expansion52└──────────────────────┘53 │54 ▼55┌──────────────────────┐56│ Agent Tools │ run_query / retrieve_context57└──────────────────────┘58 │59 ▼60┌──────────────────────┐61│ LLM Response │ Answer with citations62└──────────────────────┘63```6465## Step 1: Define GraphRAG Requirements6667Document the following before implementation:6869- **Use cases**: Q&A, research, report generation, troubleshooting70- **Source types**: PDFs, HTML, Markdown, APIs, databases71- **Entity types**: People, systems, components, products, errors72- **Relationship types**: MENTIONS, CONNECTS_TO, DEPENDS_ON, NEXT73- **Latency targets**: P95 retrieval time, max hops for expansion7475## Step 2: Choose Ingestion Strategy7677Pick one of these:7879- **Toolkit-based**: `unstructured2graph` + `lightrag-memgraph`80- **Custom ETL**: your parser + entity extractor + Cypher loader81- **Batch migration**: sql2graph for relational sources8283Ingestion must always produce:8485- Chunk nodes with text + source metadata86- Entity nodes with normalized names87- Relationships that connect entities to chunks and each other8889## Step 3: Standard Graph Schema (Recommended)9091Use a stable schema so any client can query consistently:9293**Nodes**94- `Document` {id, title, source, created_at}95- `Chunk` {id, text, source, embedding}96- `Entity` {id, name, type, description}97- `Concept` {id, name}9899**Relationships**100- `(Document)-[:HAS_CHUNK]->(Chunk)`101- `(Entity)-[:MENTIONED_IN]->(Chunk)`102- `(Entity)-[:RELATES_TO]->(Entity)`103- `(Chunk)-[:NEXT]->(Chunk)`104105## Step 4: Embeddings + Vector Index106107- Store embeddings on `Chunk.embedding`108- Create a vector index for `Chunk(embedding)`109- Use Memgraph’s vector search in retrieval110111Keep embeddings consistent across ingestion and queries.112113## Step 5: Hybrid Retrieval Strategy114115Default retrieval flow:1161171. **Vector search** to get top-$k$ chunks1182. **Graph expansion** to include related chunks/entities1193. **Ranking** by degree, recency, or path length1204. **Dedup** and trim to the model context budget121122Recommended query pattern (pseudo-Cypher):123124- Vector search on `Chunk`125- BFS traversal limited to $1–3$ hops126- Return chunk text + related entities127128## Step 6: Agent Tool Contracts129130Expose retrieval and diagnostics as tools. Minimal contract:131132**Tool: `run_query`**133- Input: `{ cypher: string, params?: object }`134- Output: `{ rows: array }`135136**Tool: `retrieve_context`**137- Input: `{ question: string, vector_k?: number, hop_limit?: number }`138- Output: `{ chunks: [{text, source, entities[]}], graph_stats }`139140**Tool: `ingest_sources`**141- Input: `{ sources: string[], mode?: "append" | "replace" }`142- Output: `{ documents, chunks, entities, duration_ms }`143144Agents should:145146- Call `get_schema` once per session147- Use parameterized queries148- Log retrieval traces for debugging149150## Step 7: Language-Agnostic Integration151152Memgraph supports the Bolt protocol. Use a Bolt-compatible driver in your language of choice.153154Integration responsibilities in each language:155156- Create a connection pool157- Execute parameterized Cypher158- Map results to your tool contract159- Handle retries and timeouts160161## Step 8: Evaluation & Observability162163Minimum evaluation suite:164165- **Recall@k**: relevant chunks retrieved166- **Groundedness**: answer supported by chunks167- **Latency**: P95 retrieval under target168- **Coverage**: percent of sources indexed169170Log for each request:171172- Query text173- Top vector hits174- Expansion hops used175- Final context length176177## Guardrails178179- Always answer from retrieved context180- If context is insufficient, say so181- Avoid unbounded graph traversal182- Enforce per-request timeouts183184## Optional: Use Memgraph AI Toolkit185186Use the Memgraph AI Toolkit for faster setup:187188- `memgraph-toolbox` for core utilities189- `unstructured2graph` for parsing and ingestion190- `lightrag-memgraph` for entity extraction191- `langchain-memgraph` for agent tooling192193Treat these as implementation options, not requirements.