neo4j/neo4j-graphrag-python
Neo4j GraphRAG for Python
Neo4j GraphRAG Python package
What it is – A first‑party Python library that lets you build graph retrieval‑augmented generation (GraphRAG) applications on top of a Neo4j database. It provides pipelines for turning raw text or PDFs into a knowledge graph, utilities for creating and populating vector indexes, and a set of retrievers that combine vector similarity with graph traversal. The library ships with adapters for many LLM providers (OpenAI, Anthropic, Ollama, etc.) and optional integrations with external vector stores such as Weaviate, Pinecone, and Qdrant.
Key capabilities
- Knowledge‑graph construction –
Pipeline(full‑featured) andSimpleKGPipeline(easy‑start) classes that extract entities/relationships using an LLM, embed them, and write them into Neo4j. Supports text and PDF sources. - Vector indexing – Helper functions to create Neo4j vector indexes and up‑sert embeddings.
- Hybrid retrieval – Built‑in
VectorRetrieverand other retrievers that blend approximate nearest‑neighbor search with graph traversal for richer context. - RAG execution –
GraphRAGclass that ties a retriever to an LLM, exposing a simplesearch(query_text, ...)API that returns a generated answer. - Pluggable LLM/embedding back‑ends – Optional extras (
openai,anthropic,google-genai,mistralai, …) let you pick the model provider you prefer. - Experimental KG builder tools – Additional pipelines and resolvers (e.g., spaCy‑based semantic matching, fuzzy matching) under an
experimentalnamespace.
Installation
# From PyPI
pip install neo4j-graphrag
# Or via conda‑forge
conda install -c conda-forge neo4j-graphrag
Add optional extras for the LLM you need, e.g. pip install "neo4j-graphrag[openai]".
Typical workflow
- Run Neo4j (with the APOC library installed).
- Create a knowledge graph – use
SimpleKGPipeline(or the more configurablePipeline) to feed raw text/PDFs, specify the node/relationship schema, and let the LLM extract and embed entities. - Create a vector index on the
Chunklabel (or any label you store embeddings on) usingcreate_vector_index. - Populate the index with embeddings via
upsert_vectors. - Query – instantiate a
VectorRetriever, an LLM wrapper (e.g.,OpenAILLM), and aGraphRAGobject, then callsearch()with a natural‑language question.
Documentation & examples
- Full docs: https://neo4j.com/docs/neo4j-graphrag-python/
- Blog tutorials walk through KG building, hybrid retrieval, and Text2Cypher retrievers.
- A rich
examples/folder contains ready‑to‑run scripts for each step.
Development & contribution
- Uses the
uvtool for dependency management; runuv sync --group devto set up a dev environment. - Code quality enforced with Ruff (lint) and MyPy (type checking).
- Contributions require signing Neo4j’s CLA.
Who it’s for
- Data engineers or ML engineers who want to augment LLM responses with structured graph context.
- Teams already using Neo4j who need a seamless bridge to generative AI.
- Researchers exploring hybrid retrieval strategies that combine vector similarity with graph semantics.
All details are taken directly from the repository’s README; no additional features are inferred.
Related
- Project
- Project
- Project
- Project
- Project