# graph-rag-agent

> A Neo4j knowledge-graph Q&A system that fuses GraphRAG, LightRAG-style search and DeepSearch reasoning agents

- Category: Retrieval & Knowledge (RAG) / RAG Frameworks & Platforms
- Language: Python
- Licence: MIT
- Repository: https://github.com/1517005260/graph-rag-agent
- Canonical page: https://ai-tldr.dev/tools/graph-rag-agent/

## In short

graph-rag-agent is an open-source Python project that combines GraphRAG with private-domain DeepSearch to build an explainable question-answering system over your own documents. It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed MIT. To get started: start Neo4j.

## Overview

graph-rag-agent is an open-source Python project that combines GraphRAG with private-domain DeepSearch to build an explainable question-answering system over your own documents. It reimplements GraphRAG's core ideas from scratch and borrows from Microsoft GraphRAG, Neo4j's llm-graph-builder, LightRAG and Zilliz's deep-searcher: an LLM extracts entities and relationships from your files, the result is stored as a knowledge graph in Neo4j, and a set of agents searches that graph to answer questions.

The project ships as a full stack rather than a library alone. A graph-building pipeline ingests TXT, PDF, Markdown, DOCX, DOC, CSV, JSON and YAML files, runs community detection (Leiden or SLLPA) with summaries, and supports incremental updates with entity disambiguation and alignment. A FastAPI backend serves several agents, and a Streamlit frontend shows streamed answers, the reasoning trace, the matched sub-graph and the source text in a debug mode.

It is aimed at developers who want to study or deploy graph-based RAG end to end, including evaluation: a built-in evaluation framework covers answer quality, retrieval performance, graph quality and deep-research results with more than 20 metrics. The README is written in Chinese and its sample knowledge base is a set of university student-management rules, which you replace with your own files and entity/relationship schema.

## What it does

- Knowledge-graph construction in Neo4j with LLM-driven entity and relationship extraction from TXT, PDF, MD, DOCX, DOC, CSV, JSON and YAML files
- Incremental graph updates (one-off or as a background daemon) with entity disambiguation, entity alignment and built-in consistency checks
- Community detection with the Leiden or SLLPA algorithm plus generated community summaries for global search
- Several agents: NaiveRagAgent (vector retrieval), GraphAgent, HybridAgent, DeepResearchAgent and FusionGraphRAGAgent, the last built on a Plan-Execute-Report multi-agent architecture that plans tasks, runs retrieval, research and reflection workers, and writes long-form reports
- Local, global and hybrid graph search, Chain of Exploration over the graph, evidence-chain tracking and a visible thinking process
- FastAPI backend with streamed responses and a Streamlit frontend with a debug mode, an interactive Neo4j-style graph view and entity-path reasoning, plus an evaluation system with 20+ metrics

## Getting started

These steps follow the project's quick-start guide (assets/start.md). You need Docker for Neo4j, Python 3.10, and an OpenAI-compatible API endpoint; the guide suggests routing requests through a One-API or New-API gateway.

1. Start Neo4j

   The repository includes a Docker Compose file for Neo4j. The default credentials are neo4j / 12345678.

```bash
cd graph-rag-agent/
docker compose up -d
```

2. Create the Python environment

   Install the dependencies into a Python 3.10 environment, then install the package itself in editable mode.

```bash
conda create -n graphrag python==3.10
conda activate graphrag
cd graph-rag-agent/
pip install -r requirements.txt
pip install -e .
```

3. Configure .env

   Copy .env.example to .env in the project root and fill in at least the model and Neo4j settings. The base URL points at your OpenAI-compatible gateway. Entity types, relationship types and the graph theme are set separately in graphrag_agent/config/settings.py.

```text
OPENAI_API_KEY = 'sk-xxx'
OPENAI_BASE_URL = 'http://localhost:13000/v1'
OPENAI_EMBEDDINGS_MODEL = 'text-embedding-3-large'
OPENAI_LLM_MODEL = 'gpt-4o'

NEO4J_URI = 'neo4j://localhost:7687'
NEO4J_USERNAME = 'neo4j'
NEO4J_PASSWORD = '12345678'
```

4. Build the knowledge graph

   Put your source documents in the files/ folder, then run the full build. The incremental script applies later additions and removals, once or as a daemon.

```bash
cd graph-rag-agent/
python graphrag_agent/integrations/build/main.py

# incremental update, once
python graphrag_agent/integrations/build/incremental_update.py --once
# or as a background daemon
python graphrag_agent/integrations/build/incremental_update.py --daemon
```

5. Test the agents from the terminal

   The test scripts query the agents with and without streaming; comment out agents you do not want to run to keep it fast.

```bash
cd graph-rag-agent/test
python search_without_stream.py
python search_with_stream.py
```

6. Run the backend and frontend

   Start the FastAPI server, then the Streamlit app, and pick an agent in the sidebar.

```bash
cd graph-rag-agent/
python server/main.py

# in another terminal
cd graph-rag-agent/
streamlit run frontend/app.py
```

## When to use it

- Build a question-answering assistant over an internal rulebook or document set where answers depend on relationships between entities, not just similar text chunks
- Compare naive vector RAG, graph search, hybrid search and DeepSearch-style multi-step agents side by side on the same knowledge base
- Inspect how a graph-RAG answer was produced, with the execution trace, matched sub-graph and source passages visible in debug mode
- Evaluate a GraphRAG pipeline with ready-made metrics for answer quality, retrieval, graph quality and deep research
