Neo4j for RAG means using Neo4j, a graph database, as the retrieval layer of a retrieval-augmented generation system, combining graph traversal with vector search so answers are grounded in the actual relationships between entities. The short answer to whether it is worth it: use Neo4j when your data is genuinely connected, when questions hop between entities, or when you need to explain where an answer came from. If your documents are mostly flat text with few meaningful links between items, a plain vector database will do the same job for less effort.
Most RAG systems start as vector search plus a prompt. That works until the questions get relational: which products share a supplier, what connects two companies, or which documents cite the same regulation. Similarity search finds things that look alike; it cannot tell you how things relate. Neo4j stores those relationships as first-class data, and its query language, Cypher, lets the system walk them at query time.
Key takeaways
- Neo4j is a property graph database: nodes are entities, relationships connect them, and both can carry properties.
- For RAG it adds graph traversal to vector search, so retrieval can follow relationships instead of relying on similarity alone.
- Vector indexes in Neo4j support similarity search over embeddings, and hybrid retrieval combines both signals.
- The official neo4j-graphrag Python package provides retrievers and generators that wire Neo4j into a RAG pipeline.
- Graph modelling is a skill in its own right: a bad model produces slow queries and confusing answers.
What Neo4j is, in one paragraph
Neo4j is a graph database built around the property graph model. Data is stored as nodes, which represent entities such as people, products or documents, and relationships, which connect nodes and carry a type and direction, for example a person WORKS_FOR a company or a document CITES a regulation. Both nodes and relationships can hold properties, such as a name, a date or a chunk of text. Queries are written in Cypher, a declarative language built around pattern matching: you describe the shape of the subgraph you want, and the database finds it.
That model fits domains where the connections are the point: fraud rings, supply chains, recommendation engines, knowledge graphs and enterprise search. If your domain looks like a whiteboard full of circles and arrows, forcing it into tables means rebuilding those connections with joins every time you ask a question. Neo4j keeps them stored and indexed instead.
Why a graph database helps RAG
Vector search answers one question well: what is similar to this query. It cannot answer what is connected to this entity, what lies two hops away, or which items share a common neighbour. Those are graph questions, and they come up constantly in real RAG workloads. A customer asks about a product recall, and the useful answer depends on which batches, suppliers and regions are linked to the affected product. A researcher asks which papers build on a given study, and the answer is a citation graph.
A graph also gives answers provenance. When a response is generated from a traversed path, the system can show the exact chain of entities and relationships behind it, which is far more persuasive than a list of chunk scores. That matters in regulated settings, where “the model said so” is not an acceptable citation. For the broader context, our guide to knowledge graph RAG and when graph structure beats plain vector search explains where this advantage pays off.
How Neo4j for RAG works in practice
A typical Neo4j-backed RAG pipeline has four parts: ingestion, indexing, retrieval and generation. Documents are parsed, entities and relationships are extracted, and the results are loaded into the graph. Text chunks are embedded and stored alongside their source nodes, with a vector index created over the embeddings so similarity search runs inside the same database as the graph.
Ingestion and modelling
Modelling is the step teams underestimate. You decide which things become nodes, which become relationships and which stay as properties, and those choices shape every query that follows. A common pattern is to keep documents and chunks as nodes, link chunks to the entities they mention, and link entities to each other. Keep the model as small as the questions require: every node type you add is a type your queries must handle.
Vector indexes and hybrid retrieval
Neo4j supports vector indexes for similarity search over embeddings, using approximate nearest neighbour search. The practical pattern is hybrid: run vector search to find candidate entities or chunks, then expand from those candidates by traversing the graph to gather context, apply filters and collect explanations. Neo4j also provides a SEARCH subclause that lets a Cypher pattern be constrained by vector index hits, which is the ergonomic bridge between the two retrieval styles.
The neo4j-graphrag package
Neo4j publishes an official Python package, neo4j-graphrag, that wires the database into a RAG pipeline without requiring deep Cypher knowledge. It provides retrievers for different strategies, including a VectorRetriever for similarity search, and generators that pass retrieved context to a language model. Neo4j’s getting-started guide walks through the setup with a demo movie database. You connect with the Neo4j Python driver, pick a retriever, and call its search method with the query text and a top-k value. The package also supports building full GraphRAG flows, where the graph itself is the retrieval source.

Neo4j for RAG vs a plain vector database
| Aspect | Plain vector database | Neo4j for RAG |
|---|---|---|
| Retrieval signal | Embedding similarity only | Similarity plus graph traversal |
| Multi-hop questions | Needs extra retrieval rounds | Native, via Cypher patterns |
| Answer provenance | Chunk scores | Explicit graph paths |
| Filtering | Metadata filters | Graph structure, metadata and similarity together |
| Setup effort | Low | Higher, needs a graph model |
| Best for | Flat document collections | Connected, entity-rich data |
The comparison is not about which is better in general. A vector database is the right default for a pile of documents with weak structure. Neo4j earns its place when relationships carry meaning your users ask about. Our guide to choosing a vector database for RAG covers the vector-only side of this decision, and our vector database comparison explains how to judge the options without being misled by benchmarks.
Common retrieval patterns
Three patterns cover most Neo4j RAG designs. The first is vector search plus graph expansion: retrieve the top chunks by similarity, then walk from their entities to neighbouring nodes to add context the chunks alone missed. The second is text-to-Cypher, where the language model writes a Cypher query from the question and the database answers it directly; this is powerful but needs guardrails, because a wrong query returns a confident-looking wrong answer, so many teams use query templates rather than free-form generation. The third is GraphRAG, where the graph is built from the corpus by entity extraction and community summaries answer broad questions, as in Microsoft’s GraphRAG approach.
Best for: vector plus graph expansion suits most teams starting out, because it keeps vector search as the safety net and adds graph context only where it helps.
When Neo4j is the wrong choice
Neo4j is the wrong choice when the data has no meaningful relationships, when the team has no one willing to learn graph modelling, or when the corpus is small enough that a vector database and a few metadata filters answer every question. It is also worth pausing if the data changes constantly in ways that would force the graph to be rebuilt, or if the only reason for choosing it is fashion. A graph database is infrastructure you maintain, not a feature you switch on.
Cost is a second consideration. Running and operating a graph database, keeping its indexes healthy and its model clean, is real work. For a small internal tool, that work may exceed the value of the better answers. Start with the smallest graph that answers a real user question, and expand the model only when new questions demand it.
Getting started checklist
- List the five hardest real questions your users ask, and check which ones need relationships to answer.
- Sketch the graph model on paper before writing any ingestion code.
- Load a small sample, a few hundred entities, and test queries against it by hand.
- Create a vector index over chunk embeddings so similarity search runs in the same database.
- Start with vector search plus graph expansion, not text-to-Cypher.
- Use query templates for generated Cypher, and validate every query before it runs.
- Keep chunk text attached to its source nodes so answers stay traceable.
- Measure retrieval quality on real questions before scaling the graph.
Frequently asked questions
Can Neo4j do vector search for RAG?
Yes. Neo4j supports vector indexes for similarity search over embeddings, so the same database can run both vector retrieval and graph traversal. That combination is the core of hybrid retrieval in a Neo4j-backed RAG system.
What is the neo4j-graphrag package?
It is Neo4j’s official Python package for building GraphRAG applications. It provides retrievers, such as VectorRetriever, and generators that connect the database to a language model, so developers can build a RAG pipeline without writing Cypher for every step.
Do I need to know Cypher to use Neo4j for RAG?
Not for a basic setup, since the neo4j-graphrag package and framework integrations handle retrieval for you. For serious work, though, some Cypher is unavoidable: modelling, debugging and custom retrieval patterns all need it, and it is a small language to learn.
Is Neo4j better than a vector database for RAG?
Neither is better in general. A vector database wins for flat document collections and simple similarity questions. Neo4j wins when questions follow relationships, when provenance matters, or when the data is naturally a graph.
How do I keep the graph up to date?
Ingestion should be a pipeline, not a one-off script: new documents are parsed, entities extracted and merged into the existing graph, and stale nodes updated or removed. Plan this before the first load, because a graph that drifts from its source documents produces answers you cannot trust.
What does hybrid retrieval mean in Neo4j?
It means combining vector similarity with graph traversal in a single query path, for example finding candidates by embedding similarity and then expanding through relationships to gather context. Neo4j’s SEARCH subclause lets a Cypher pattern be constrained by vector index results, which makes this pattern straightforward to express.







