Agentic Graph RAG
Documents in, knowledge graph out, with an agent choosing how to retrieve
- Backend services
- 5
- Document formats
- 5
- Chunking strategies
- 3
- Retrieval tools
- 6
- Entity resolution stages
- 2
- License
- Apache 2.0
Agentic Graph RAG turns unstructured documents into a knowledge graph and answers natural-language questions over it. Documents are parsed, chunked, embedded, and stored; an ontology service extracts a schema; a graph service extracts and deduplicates entities into Neo4j. At query time a LangGraph agent analyzes the question, picks vector search, graph traversal, or a hybrid, and returns an answer with confidence, evidence, and its reasoning steps.
The problem
Plain vector RAG answers questions about passages but loses the relationships between things: who founded what, which organizations collaborate, how two entities connect. Graph-only retrieval needs a schema and clean entities, and the same real-world entity arrives under many spellings across documents. Deciding which retrieval strategy fits a given question is itself a judgement, and users need to see why an answer was produced, not just the answer.
How it is built
The platform is an API gateway in front of four domain services (ingestion, ontology, graph construction, retrieval), all FastAPI, with a shared Python library of models, adapters, and utilities volume-mounted into each container. Services are stateless; documents, schemas, and job state live in Redis-backed stores.
Ingestion parses five document formats, chunks with a choice of three strategies, embeds chunks, and stores vectors in Qdrant. It can optionally chain into ontology extraction and graph construction as a background pipeline. Graph construction runs as an async job: entities and relationships are extracted by a model, resolved in two stages (fuzzy name match, then embedding similarity) against both the current batch and what is already in the graph, and merged into Neo4j with constraints that prevent duplicate nodes.
Retrieval is a LangGraph state machine: understand the query, route to a strategy, run vector, graph, or hybrid search, then synthesize. Every step appends to a reasoning trail returned with the answer. Tools include vector search, graph traversal, entity search, hybrid search, shortest path, and natural-language to Cypher or Gremlin generation.
Graph access goes through an abstract adapter so the backend can be swapped by configuration; Neo4j is fully implemented and an AWS Neptune adapter is interface-ready. Prometheus metrics are exposed from the gateway, and a D3-based frontend provides upload, ontology management, graph visualization, and a query interface.
What it taught me
- An abstract graph adapter kept every service free of vendor-specific calls, so switching the graph backend is a configuration change rather than a rewrite.
- A typed state machine with a recorded reasoning trail made the agent inspectable: every answer shows which strategy was chosen and why.
- Entity resolution has to be database-aware; checking only the current batch re-inserts entities that earlier documents already created.
Architecture
A Next.js frontend calls a FastAPI gateway that proxies to four domain services. Ingestion writes chunk vectors to Qdrant and can trigger ontology extraction and graph construction, which writes resolved entities to Neo4j. The retrieval agent reads both stores to answer queries. Redis holds documents, schemas, job status, and cache for all services.
Layer 1
FrontendClient
upload, ontology, graph viz, query
→ API gateway (HTTP)
Layer 2
API gatewayEdge
proxies, health, metrics
→ Ingestion (documents) → Ontology (schemas) → Graph construction (construct jobs) → Retrieval agent (query)
Layer 3
IngestionService
parse, chunk, embed
→ Qdrant (embeddings) → Ontology (auto schema) → Redis (state)
Retrieval agentModel
LangGraph: route, search, synthesize
→ Qdrant (vector search) → Neo4j (traverse)
Layer 4
RedisStore
documents, schemas, jobs
OntologyService
schema extraction, merge
→ Graph construction (schema)
QdrantStore
chunk vectors
Layer 5
Graph constructionService
extract, resolve, merge
→ Neo4j (merge)
Layer 6
Neo4jStore
entities, relationships
Stack
Backend
- Python 3.11
- FastAPI
- httpx
- LangGraph
- LangChain
- Pydantic v2
Data
- Neo4j 5 (APOC, GDS)
- Qdrant
- Redis 7
Frontend
- Next.js 14
- React 18
- D3.js
- React Query
- Tailwind CSS
AI
- OpenAI chat and embedding models
- rapidfuzz for name matching
Infrastructure
- Docker Compose
- Prometheus