# Repository Briefing: gusye1234/nano-graphrag
> Source: https://repoforai.com/repo/gusye1234/nano-graphrag (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/gusye1234/nano-graphrag
- **Category**: RAG, Data & Memory (知识库 / 爬虫 / 记忆层)
- **Primary Language**: Python
- **License**: MIT
- **Engineering Health**: B (56/100 · Maintenance 6/35 · Adoption 19/25 · Releases 11/20 · License 20/20)
- **Latest Release**: v0.0.8 (2024-10-01) — https://github.com/gusye1234/nano-graphrag/releases
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: API, Local AI
- **Momentum**: 4,017 ★ total (+1 24h / +2 7d) · 427 forks
- **Topics**: `gpt-4o`, `graphrag`, `learning-by-doing`, `gpt`, `llm`, `rag`
- **When to Use**: Best for: Python teams prototyping or embedding entity-centric retrieval and corpus-wide synthesis, with room to swap models and storage or compare against chunk retrieval. Skip if: You need parity with Microsoft's GraphRAG, a packaged streaming API, or frequent ingestion without community and report rebuilds.

## Overview
```text
### Architecture & Core Mechanics
nano-graphrag is an embeddable Python SDK built around the `GraphRAG` and `QueryParam` dataclasses. `insert` and `ainsert` chunk documents, use model calls to extract entities and relationships, and build a graph whose communities are summarized into reports. Local search starts from relevant entities and assembles graph context; global search synthesizes across community reports. The optional naive path retrieves text chunks by embedding similarity instead of using graph context at query time.

The SDK separates key-value, vector and graph storage. Its default setup combines file-backed KV storage, nano-vectordb and NetworkX; hnswlib and Neo4j are built-in options for the vector and graph layers respectively. Model completion and embedding functions are injectable. Completion is split into a stronger model for planning and responses and a cheaper one for summarization, defaulting to `gpt-4o` and `gpt-4o-mini`. The Python dependencies include OpenAI, tiktoken, NetworkX, graspologic and tenacity alongside the storage and provider packages.

### Key Capabilities & Differentiators
A caller can insert a document or a batch of strings, reopen the same `working_dir` to load persisted state, and choose local, global or naive retrieval per query. Both ingestion and querying have async entry points. Queries normally return a completed answer without streaming; `only_need_context=True` returns the assembled context so the application can supply its own prompt or generation layer. Global search considers at most 512 communities by default, adjustable via `QueryParam.global_max_consider_community`.

OpenAI, Azure OpenAI and Amazon Bedrock have built-in integrations. Examples show DeepSeek and Ollama generation, local sentence-transformers embeddings, and FAISS and Milvus Lite vector adapters. Chunking functions and prompts are replaceable, and a custom response-to-JSON converter can handle backends whose structured output needs post-processing. GraphML provides a visualization path. English and Chinese benchmark materials and a multi-hop evaluation notebook offer starting points for comparing retrieval modes on a representative corpus.

### Trade-offs & Limitations
Compared with Microsoft's GraphRAG, this implementation gives developers a smaller Python surface to modify, but it is not a drop-in replacement. It omits covariates and uses a capped set of important or central communities for global search rather than processing the full community set in the original map-reduce-like approach. That cap bounds how many reports enter consideration, but themes concentrated in lower-ranked communities can be missed. Test global coverage on the target corpus rather than treating the default as a quality guarantee.

MD5-based content keys prevent duplicate chunks, but inserts that add new content still recompute graph communities and regenerate their reports. On a frequently updated corpus, that turns ingestion cadence into a cost and latency decision; measure the effect of batching before committing to continuous ingestion. Use naive chunk retrieval as a baseline when plain passage lookup may suffice. Cloud APIs reduce local model operations but introduce provider costs and data-handling considerations; local models shift capacity planning and structured-output reliability back to the operator.

### Hardware & Deployment Guide
Install the Python package from PyPI with `pip install nano-graphrag` or from a source checkout with `pip install -e .`. The integration point is an in-process Python API, not a packaged HTTP service. For the file-backed path, give the application a writable, durable `working_dir`. OpenAI requires an API key; Azure OpenAI needs its environment settings and `using_azure_openai=True`; Bedrock needs AWS credentials, `using_amazon_bedrock=True`, and model IDs. Neo4j is an optional graph backend, not a prerequisite.

The hosted path shifts model compute to the provider, but the application still budgets for graph processing, vector indexing, storage and API concurrency. The no-key example combines Ollama and transformers; local RAM and VRAM requirements depend on the selected models, context lengths, embedding batches and concurrency. In the release history, v0.0.6 fixed HNSW local-query bugs, v0.0.7 added naive chunk RAG, and v0.0.8, dated October 1, 2024, added Azure OpenAI and DSPy-based entity extraction.
```

## Key Capabilities
```text
- Python API: `GraphRAG` and `QueryParam` are dataclasses; `ainsert` and `aquery` expose the async path.
- Retrieval modes: Local search starts from entities, global search uses community reports, and optional naive search retrieves text chunks.
- Incremental ingestion: MD5-based content keys deduplicate repeated text, but new inserts still trigger community recomputation and report regeneration.
- Storage adapters: File-backed KV, nano-vectordb and NetworkX form the default stack; hnswlib and Neo4j are built-in alternatives.
- Model adapters: Built-in OpenAI, Azure OpenAI and Amazon Bedrock support; examples cover DeepSeek, Ollama and local sentence-transformers embeddings.
- Application control: Context-only retrieval, configurable chunking, editable prompts and a custom JSON conversion hook.
```

## Quick Start / Clone
```bash
# clone this repo first
cd nano-graphrag
pip install -e .
```
