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) and SimpleKGPipeline (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 VectorRetriever and other retrievers that blend approximate nearest‑neighbor search with graph traversal for richer context.
  • RAG execution – GraphRAG class that ties a retriever to an LLM, exposing a simple search(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 experimental namespace.

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

  1. Run Neo4j (with the APOC library installed).
  2. Create a knowledge graph – use SimpleKGPipeline (or the more configurable Pipeline) to feed raw text/PDFs, specify the node/relationship schema, and let the LLM extract and embed entities.
  3. Create a vector index on the Chunk label (or any label you store embeddings on) using create_vector_index.
  4. Populate the index with embeddings via upsert_vectors.
  5. Query – instantiate a VectorRetriever, an LLM wrapper (e.g., OpenAILLM), and a GraphRAG object, then call search() with a natural‑language question.

Documentation & examples

Development & contribution

  • Uses the uv tool for dependency management; run uv sync --group dev to 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