█

AI/TLDR

Buy me a coffee
Buy me a coffee

nano-graphrag

A simple, easy-to-hack GraphRAG implementation in about 1100 lines

RAG Frameworks & PlatformsOpen source
Language
Python
$pip install nano-graphrag
IN SHORT

What is nano-graphrag?

nano-graphrag is a compact Python reimplementation of GraphRAG, the graph-based retrieval-augmented generation approach. It keeps the core functionality of the original Microsoft GraphRAG while shrinking the codebase to about 1100 lines (excluding tests and prompts), so you can actually read and change it. It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python.

Overview

nano-graphrag is a compact Python reimplementation of GraphRAG, the graph-based retrieval-augmented generation approach. It keeps the core functionality of the original Microsoft GraphRAG while shrinking the codebase to about 1100 lines (excluding tests and prompts), so you can actually read and change it.

It is aimed at developers who want a graph-based retrieval codebase they can study and modify, rather than a large framework that is hard to follow. The project is asynchronous and fully typed, and it supports both global and local query modes plus a naive RAG fallback.

As a RAG framework, it fits the case where plain vector retrieval is not enough and you want entities and communities extracted into a graph. It is portable: you can swap in different LLMs, embedding models, vector databases, and graph storage backends.

What it does

  • Around 1100 lines of code (excluding tests and prompts), built to be read and hacked
  • Global and local GraphRAG search modes, plus an optional naive RAG mode
  • Incremental and batch insert with md5-hash de-duplication so repeated content is not recomputed
  • Async API: every NAME(...) method has a matching aNAME(...) async version
  • Pluggable components — OpenAI, Amazon Bedrock, DeepSeek and ollama LLMs; OpenAI, Bedrock and sentence-transformers embeddings; nano-vectordb, hnswlib, milvus-lite and faiss vector stores; networkx graph storage
  • Reloads all context automatically when you re-initialize GraphRAG from the same working_dir

Getting started

Install the package, set your OpenAI API key, then insert some text and query it.

Install

Install from PyPI, or from source by cloning the repo and running an editable install.

bashbash
pip install nano-graphrag

Set your OpenAI API key

nano-graphrag reads the OpenAI key from the environment.

bashbash
export OPENAI_API_KEY="sk-..."

Insert text and query

Create a GraphRAG with a working directory, insert a document, then run a global or local search. The same working_dir reloads context automatically next time.

pythonpython
from nano_graphrag import GraphRAG, QueryParam

graph_func = GraphRAG(working_dir="./dickens")

with open("./book.txt") as f:
    graph_func.insert(f.read())

# Global graphrag search
print(graph_func.query("What are the top themes in this story?"))

# Local graphrag search
print(graph_func.query("What are the top themes in this story?", param=QueryParam(mode="local")))

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Studying or experimenting with how GraphRAG works without wading through a large official codebase
  • Building a graph-based RAG pipeline over a document collection where entity and community structure matters
  • Prototyping with alternative backends — swapping in ollama, faiss, milvus-lite, or sentence-transformers in place of OpenAI defaults
  • Incrementally ingesting a growing corpus and re-querying it with global or local search modes

How nano-graphrag compares

nano-graphrag alongside other open-source rag frameworks & platforms tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Dify★ 162kAn open-source platform with a visual workflow builder for creating LLM and RAG applications without writing much code.
graphify★ 155kTurns a folder of code, docs, PDFs and images into a local knowledge graph with tree-sitter AST parsing and Leiden communities — queryable by agents over MCP, no vector store.
RAGFlow★ 95kA RAG engine built around deep document understanding that turns complex files into a grounded, citation-backed question-answering layer.
Context7★ 65.7kContext7 pulls current, version-specific documentation and code examples for any library and feeds them into your LLM, available as a CLI skill or an MCP server.
Pathway★ 61.9kA Python framework with a Rust streaming engine that keeps ETL, real-time analytics and RAG pipelines continuously up to date as source data changes.
LightRAG★ 41kA graph-based RAG system that builds an entity-and-relationship knowledge graph for fast retrieval and easy incremental updates.
PageIndex★ 40.8kPageIndex turns long PDFs into a table-of-contents tree and uses LLM reasoning to retrieve relevant sections, with no vector database and no chunking.
nano-graphrag★ 4kA simple, easy-to-hack GraphRAG implementation in about 1100 lines