# graphrag
<div align="center">
**Hybrid search engine: vector embeddings + knowledge graph over Markdown notes.**
[](https://crates.io/crates/graphrag)
[](https://crates.io/crates/graphrag)
[](LICENSE)
[](https://www.rust-lang.org)
[](https://www.rust-lang.org)
**A single Rust binary โ no Python, no npm, no servers. 100% local and private.**
</div>
---
## ๐งญ GraphRAG for absolute beginners
*(If you already know what RAG, vectors, and knowledge graphs are, skip ahead to [What is Graph RAG?](#-what-is-graph-rag))*
### The problem: hundreds of notes, can't find anything
Imagine you've been taking notes about Linux for years. You have a `~/linux-notes/`
folder with **500 Markdown files** on topics like:
```
linux-notes/
โโโ apt-comandos-basicos.md
โโโ systemd-crear-servicio.md
โโโ docker-compose-nginx.md
โโโ particionar-disco-gpt.md
โโโ script-bash-backup.md
โโโ firewall-ufw-reglas.md
โโโ kernel-compilar-modulo.md
โโโ ssh-tunel-inverso.md
โโโ lvm-redimensionar.md
โโโ nginx-proxy-inverso.md
โโโ rsync-incremental-backup.md
โโโ ... (500 files)
```
When you need to find something, you do the usual:
```bash
grep -ri "partitions" ~/linux-notes/
```
And it works... until it doesn't. Because:
- You search **"partitions"** but the note is titled **"resizing LVM"** and never uses that word
- You search **"network monitoring"** but your note talks about **"ntopng"** and **"iftop"** without saying "monitoring"
- You search **"high availability"** and get one note, but you miss the **"keepalived"** and **"nginx load balancing"** notes that are closely related
**Your knowledge is there. The problem is you don't know it's there.**
---
### The solution: a search engine that understands *relationships*, not just words
GraphRAG scans your 500 Linux notes, automatically extracts key concepts
(apt, systemd, LVM, Nginx, Docker, firewalld...) and builds a **knowledge map**
that knows how they relate to each other.
Now, when you search:
```bash
graphrag search "hard disk partitions" linux.db
```
GraphRAG doesn't just find the note mentioning "partitions". It also shows you:
- The note about **LVM** (because LVM and partitions are neighboring concepts in the graph)
- The note about **GPT vs MBR** (connected through `partitioning`)
- The note about **mounting filesystems** (connected by `disk` โ `storage`)
**This is Graph RAG**: a search engine that uncovers connections you didn't even know existed.
---
### Real-world example: how it works with your Linux notes
#### 1. Build the knowledge map
```bash
# One command scans all your notes and builds the graph
graphrag build ~/linux-notes linux.db
```
Under the hood, GraphRAG:
1. Reads each note and splits it into sections
2. Sends sections to a local AI (Ollama) that extracts entities like `systemd`,
`docker`, `nginx`, `partitioning`, `firewall`
3. Detects which entities appear together in the same notes (co-occurrence)
4. Builds a graph where each entity is a node and each co-occurrence is a connection
5. Computes embeddings (vectors) for each note and entity
The result is a SQLite database that knows:
```
[Docker] โโco-occursโโ [Nginx] โโco-occursโโ [reverse-proxy]
โโco-occursโโ [certbot-ssl]
โโco-occursโโ [load-balancing]
```
#### 2. Search for something specific
```bash
graphrag search "secure web server" linux.db -k 5
```
Results:
```
1. Nginx as reverse proxy Score: 0.92
Connections: nginx, reverse-proxy, http
2. Certbot: SSL certificates with Let's Encrypt Score: 0.67
Connections: ssl, certbot, nginx
โ Appears because it shares "nginx" with the previous note
3. Fail2ban: protecting SSH and services Score: 0.45
Connections: fail2ban, firewall, security
โ Appears because "security" is connected to "nginx" in the graph
```
Note 3 never mentions "secure web server" โ but GraphRAG knows that
fail2ban is used to protect web servers, because both notes share
entities in the graph. **grep would never have shown you that note.**
#### 3. Explore connections
```bash
# What does Docker have to do with systemd?
graphrag path "Docker" "systemd" linux.db
# โ Docker โ containers โ systemd โ services
# What entities surround "firewall"?
graphrag graph "firewall" linux.db -d 1
# Neighbors: ufw, iptables, nftables, fail2ban, security, ports
# General statistics
graphrag stats linux.db
# โ 500 notes, 1200 entities, 3400 connections
```
---
### And all this without internet?
Yes. GraphRAG is a **single Rust binary** that:
- Doesn't need Python, Node.js, or Docker
- Runs entirely on your machine, 100% local
- Never sends your data to any server
- If you don't have Ollama, uses synthetic embeddings (no external AI needed)
- The SQLite database is smaller than an MP3 and fully portable
**In summary:** If you have hundreds of Markdown notes and you're tired of searching
with grep or missing notes you know exist but can't find,
GraphRAG is the search engine that turns your file chaos into an
explorable knowledge map.
---
## ๐ What is Graph RAG?
**Graph RAG** (Retrieval-Augmented Generation with Graphs) is a retrieval technique that improves on plain vector search by incorporating **graph structure** into relevance ranking.
Instead of just finding notes that *mention* your query, it discovers notes connected through **shared concepts and entities** โ even if those notes never use the same words.
### Why it matters
| **FTS** (full-text) | Exact keyword matches | Synonyms, typos, related concepts |
| **Vector search** | Semantically similar content | Indirect relationships |
| **Graph RAG** | Semantic matches **+** graph-connected content | Nothing โ it's strictly better |
**Concrete example:** You have notes about "Docker Compose", "PostgreSQL", and "Patroni HA clusters". Vector search for "PostgreSQL replication" finds the PostgreSQL note. Graph RAG also surfaces the Patroni note โ not because it mentions PostgreSQL, but because both connect through the entity `high-availability` in the knowledge graph.
### The three-phase pipeline
```
Query "Python databases"
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PHASE 1 โ Vector Search โ
โ Cosine similarity: query vs every note/entity embedding โ
โ โ Top-K candidates ranked by semantic proximity โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ PHASE 2 โ Reranking โ
โ Boost: title match (+0.1) โข note type (+0.2) โ
โ Combine vector score + graph score via ฮฑ (default 0.7) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ PHASE 3 โ Graph Expansion โ
โ From top candidates, traverse the knowledge graph โ
โ via recursive CTE (SQLite). Neighbors get decaying score โ
โ โ Discovers notes connected through shared entities โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Results: hybrid score โข note content โข neighbors โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
> **TL;DR:** Vector search tells you what's similar. Graph expansion tells you what's *connected*. Together they find what you didn't know to look for.
### When to use it
- ๐ง **Personal knowledge bases** โ connect ideas across hundreds of notes
- ๐ **Technical documentation** โ find related tools, libraries, and concepts
- ๐ฌ **Research workflows** โ discover papers and notes linked by shared entities
- ๐ฑ **Zettelkasten / digital gardens** โ surface implicit links between atomic notes
- ๐ฅ **Team wikis** โ find documents connected through shared terminology
---
## โจ Features
| ๐ | **Hybrid search** (vectors + graph) | Finds relevant notes *and* connected content you didn't explicitly search for |
| ๐งฉ | **Entity extraction** via Ollama LLM | Automatically builds the knowledge graph from your notes โ no manual tagging |
| ๐๏ธ | **Community detection** (Leiden algorithm) | Groups related entities into clusters for higher-level understanding |
| ๐ | **Narrative answers** (`--answer`) | Get LLM-generated summaries grounded in community context, not just result lists |
| ๐ | **FTS5 full-text search** | Classic keyword search when you know exactly what you're looking for |
| ๐ | **Path finding** | Shortest path between any two nodes โ discover surprising connections |
| ๐ | **Graph statistics** | Understand your knowledge base structure at a glance |
| ๐ฅ๏ธ | **Concept map TUI** (`map`) | Interactive terminal UI to visually explore the knowledge graph โ navigate nodes, inspect details, filter by type |
| โก | **Incremental builds** | Only processes new/modified files (SHA256). Second build is instant |
| ๐ | **Parallel NER** | N worker threads for entity extraction, 1 serial writer โ no SQLite lock contention |
| ๐ค | **MCP server** | Claude Desktop, Cline, and other AI assistants can query your graph in real-time |
| ๐ | **Neovim plugin** | Search and insert related notes without leaving your editor |
| ๐ซ | **Zero external deps** | SQLite compiled statically. No Python, Node, Docker, or servers needed |
| ๐ | **100% local & private** | Everything runs on your machine. No data ever leaves your computer |
---
## ๐ Quick start (under 2 minutes)
```bash
# 1. Install
cargo install graphrag-search
# 2. Populate demo data (44 nodes, ~113 edges)
graphrag seed demo.db
# 3. Search โ finds notes semantically related to "Python"
graphrag search "Python" demo.db -k 5
# 4. Path โ discovers how two technologies connect
graphrag path "Docker" "SQLite" demo.db
# โ Docker โ virtualization โ embedded-database โ SQLite
# 5. Graph โ see what's connected to a concept
graphrag graph "machine-learning" demo.db -d 2
# 6. Stats โ understand your graph
graphrag stats demo.db
```
### Sample output
```
$ graphrag search "Python" demo.db -k 3
Results for "Python" (ฮฑ=0.70, depth=2):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. Python: A versatile language
Score: 0.982 | Type: note
Python is widely used in data science, web development, and automation.
Neighbors: pandas, flask, machine-learning, data-science
2. pandas: Data analysis library
Score: 0.623 | Type: note
pandas provides high-performance, easy-to-use data structures.
Neighbors: Python, numpy, data-science, jupyter
3. Data Science overview
Score: 0.412 | Type: note
An introduction to data science concepts and tooling.
Neighbors: Python, R, machine-learning, statistics
```
### Full demo walkthrough
```bash
# Create a database with demo data
graphrag seed graph.db
# Hybrid search with graph expansion (depth 2)
graphrag search "Docker security" graph.db -k 5
# Search with narrative answer (requires community detect + summarize)
graphrag community detect graph.db
graphrag community summarize graph.db
graphrag search "Docker security" graph.db --answer
# Exact text search
graphrag fts "Python" graph.db -l 10
# Explore the graph
graphrag graph "Docker" graph.db -d 1
graphrag path "Python" "Docker" graph.db
graphrag stats graph.db
# Interactive concept map
graphrag map graph.db
# Clean up when done
graphrag reset graph.db
```
---
## ๐ฆ Installation
### From crates.io (recommended)
```bash
cargo install graphrag-search
```
### From source
```bash
git clone https://github.com/atareao/graphrag
cd graphrag
cargo build --release
# Binary at:
# target/release/graphrag (~6.5 MB)
```
**Requirements:** Rust โฅ 1.75 only. SQLite is compiled statically via `rusqlite` bundled feature โ no system libraries needed.
### Optional: Ollama setup
GraphRAG works **without Ollama** using synthetic (deterministic hash-based) embeddings.
For better results, install [Ollama](https://ollama.ai/) and pull the models you need:
```bash
# Minimal setup (fast, works on any hardware)
ollama pull llama3.2:3b # NER โ 3.2B params, ~2GB VRAM
ollama pull nomic-embed-text # Embeddings โ 137M params, ~0.5GB VRAM
# Recommended setup (best quality)
ollama pull gemma4:e2b # NER โ 5.1B params, ~5GB VRAM
ollama pull bge-m3 # Embeddings โ 566M params, ~1GB VRAM
```
---
## โ๏ธ Configuration
GraphRAG auto-creates a config file at `~/.config/graphrag/config.toml` on first run.
**All fields are optional** โ CLI flags always override config values.
```toml
# =============================================
# GraphRAG configuration
# =============================================
# --- Database ---
db = "graph.db" # Default DB path
# --- Ollama connection ---
ollama_url = "http://localhost:11434"
embed_model = "bge-m3:latest" # Embedding model
ner_model = "gemma4:e2b" # Entity extraction model
# --- Search defaults ---
k = 5 # Results count
depth = 2 # Graph expansion hops
alpha = 0.7 # Vector weight (0=graph only, 1=vector only)
# --- Notes directory ---
notes_dir = "~/notes" # Used by `graphrag build` when no dir is given
# --- Build ---
num_threads = 4 # Parallel NER workers
```
### Practical config examples
<details>
<summary><b>๐ Minimal config (no Ollama, synthetic embeddings only)</b></summary>
```toml
db = "search.db"
notes_dir = "~/notes"
k = 10
depth = 2
# No Ollama fields โ uses deterministic synthetic embeddings automatically
```
</details>
<details>
<summary><b>๐ Knowledge base with 1000+ notes</b></summary>
```toml
db = "~/kb/search.db"
notes_dir = "~/kb/notes"
ner_model = "gemma4:e2b"
embed_model = "bge-m3:latest"
k = 10
depth = 2
alpha = 0.7
num_threads = 6
```
</details>
---
## ๐ ๏ธ CLI commands
```
graphrag <COMMAND> [ARGS] [OPTIONS]
```
### Core commands
| [`build`](#graphrag-build-repo-db) | ๐ฅ Scan `.md` files โ extract entities โ build knowledge graph |
| [`search`](#graphrag-search-query-db) | ๐ Hybrid vector + graph search |
| [`ask`](#graphrag-ask-query-db) | ๐ก RAG: answer questions with sources (retrieval + LLM) |
| [`fts`](#graphrag-fts-query-db) | ๐ Exact full-text search (FTS5) |
| [`graph`](#graphrag-graph-label-db) | ๐ธ๏ธ Show neighbors of a node |
| [`map`](#graphrag-map-db) | ๐ฅ๏ธ Interactive concept map TUI |
| [`path`](#graphrag-path-from-to-db) | ๐ Shortest path between two nodes |
| [`seed`](#graphrag-seed-db) | ๐ฑ Populate demo data |
| [`stats`](#graphrag-stats-db) | ๐ Graph statistics |
| [`reset`](#graphrag-reset-db) | ๐๏ธ Delete DB and recreate empty |
### Advanced commands
| [`community detect`](#graphrag-community-detect-db) | ๐๏ธ Leiden community detection |
| [`community summarize`](#graphrag-community-summarize-db) | ๐ LLM summaries per community |
| [`mcp`](#graphrag-mcp) | ๐ค MCP server for AI assistants |
| [`init db`](#graphrag-init-db-db) | ๐ Create empty database |
| [`init neovim`](#graphrag-init-neovim---output-path) | ๐ Generate Neovim plugin config |
| [`completions`](#graphrag-completions-bashzshfish) | โจ๏ธ Shell completions (bash/zsh/fish) |
---
### `graphrag init db [DB]`
Create an empty SQLite database with the GraphRAG schema.
```bash
graphrag init db graph.db
```
### `graphrag init neovim [--output <path>]`
Generate Neovim plugin Lua config ready for [lazy.nvim](https://github.com/folke/lazy.nvim).
```bash
# Print to stdout
graphrag init neovim
# Save directly
graphrag init neovim --output ~/.config/nvim/lua/plugins/graphrag.lua
```
---
### `graphrag community detect [DB]`
Run **Leiden community detection** on the entity graph โ groups related entities into clusters.
```bash
graphrag community detect graph.db
# Coarser communities (lower resolution = fewer, larger groups)
graphrag community detect graph.db --resolution 0.8
# Finer communities (higher resolution = more, smaller groups)
graphrag community detect graph.db --resolution 1.5
```
| `--resolution` | 1.0 | CPM quality function resolution parameter |
### `graphrag community summarize [DB]`
Generate LLM summaries for all detected communities. Requires `community detect` first.
```bash
graphrag community summarize graph.db --summary-model gemma4:e2b
```
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--summary-model` | `llama3.2:3b` | LLM for generating summaries |
| `--embed-model` | `nomic-embed-text` | Embedding model |
After summarizing, use `graphrag search --answer` to get **narrative answers** grounded in community context.
---
### `graphrag completions <bash|zsh|fish>`
Generate shell completion scripts.
```bash
graphrag completions bash > ~/.local/share/bash-completion/completions/graphrag
graphrag completions zsh > _graphrag
graphrag completions fish > graphrag.fish
```
---
### `graphrag seed [DB]`
Populate a database with demo data (44 nodes: notes, entities, tags; ~113 edges).
```bash
graphrag seed graph.db
graphrag search "Docker security" graph.db -k 5
```
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--embed-model` | `nomic-embed-text` | Embedding model |
---
### `graphrag build [REPO] [DB]`
The heart of GraphRAG โ scan `.md` files, extract entities via Ollama, and build the graph.
**Optimized for large repos:**
| โก **Incremental** | Skips unchanged files via SHA256 hash. Second builds are near-instant |
| ๐งต **Parallel NER** | N worker threads extract entities in parallel |
| โ๏ธ **Serial writer** | Single thread writes to SQLite โ no lock contention |
| ๐ฆ **Batch NER** | All chunks of a file sent in one Ollama call |
| ๐ **Retry with backoff** | 3 attempts (2s, 4s, 8s) on connection errors |
| ๐งน **Auto-cleanup** | Deleted notes and orphaned entities pruned automatically |
```bash
# Build from configured notes directory
graphrag build
# Build from a specific directory
graphrag build ~/notes graph.db
# Build with specific model
graphrag build ~/notes graph.db --ner-model gemma4:e2b
```
| `--embed-model` | `nomic-embed-text` | Embedding model |
| `--ner-model` | `llama3.2:3b` | Entity extraction model |
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
---
### `graphrag reset [DB]`
Delete the database and recreate it empty (equivalent to `rm + init`).
```bash
graphrag reset
graphrag reset /data/notes/graph.db
```
---
### `graphrag search <QUERY> [DB]`
Hybrid search โ semantic vectors + graph expansion. This is what makes GraphRAG special.
```bash
graphrag search "Python and databases" graph.db -k 10 -d 2
```
| `-k` | 5 | Number of results |
| `-d` | 2 | Graph expansion depth (hops from initial results) |
| `-a` | 0.7 | Vector weight (0.0 = pure graph, 1.0 = pure vector) |
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--embed-model` | `nomic-embed-text` | Embedding model |
| `--notes-only` | โ | Show only notes (hide entities and tags) |
| `--min-weight` | โ | Minimum edge weight for graph expansion |
| `--filter` | โ | Filter by metadata (repeatable). Format: `'field op value'` e.g. `--filter 'date >= 2023'` |
| `--answer` | โ | Narrative answer using community context (requires `community detect + summarize`) |
| `--format` | `table` | Output format: `table`, `list`, or `json` |
---
### `graphrag ask <QUERY> [DB]`
RAG in one command: hybrid retrieval + community summaries + chunk evidence โ a grounded natural-language answer generated with Ollama, with cited sources.
```bash
graphrag ask "how do I configure nginx?" notes.db
graphrag ask "backups" notes.db -k 10 --filter 'date >= 2024'
graphrag ask "nginx" notes.db --format json
graphrag ask "nginx" notes.db --model gpt-oss:latest --communities 5
```
| `-k, --k` | Retrieval results used as evidence (default 5) |
| `-d, --depth` | Graph expansion depth (default 2; 0 = vector-only) |
| `-a, --alpha` | Vector weight, 0.0โ1.0 (default 0.7) |
| `--min-weight` | Minimum edge weight for expansion |
| `--notes-only` | Only notes (hide entities and tags) |
| `--filter` | Metadata filter (repeatable), e.g. `'date >= 2023'` |
| `--communities` | Max community summaries in the context (default 3) |
| `--model` | Ollama model for generation (default: `summary_model` from config) |
| `--format` | Output format: `table` \| `list` \| `json` |
If Ollama is unreachable, `ask` degrades to plain retrieval and exits 0. Community context requires `graphrag community detect` followed by `graphrag community summarize`. With `--format json` the output is `{ "answer", "sources", "results" }`.
---
### `graphrag similar --label <LABEL> --file <PATH> [DB]`
Find semantically similar notes. Two modes:
- `--label`: find notes similar to an **existing** indexed note (no Ollama needed โ uses stored embeddings)
- `--file`: find notes similar to an **external** `.md` file (chunks and embeds via Ollama)
Both modes use **match individual**: each chunk of the source is compared independently, and each target note is scored by its best-matching chunk pair.
```bash
# Find notes similar to an existing note
$ graphrag similar --label "Python frameworks" graph.db -k 5
# Find notes similar to an external file
$ graphrag similar --file ~/drafts/new-idea.md graph.db -k 10 -d 2
```
| `--label` | โ | Label of an existing note in the database |
| `--file` | โ | Path to an external `.md` file |
| `-k` | 5 | Number of results |
| `-d` | 2 | Graph expansion depth |
| `--notes-only` | โ | Show only notes (no entities/tags) |
| `--min-weight` | โ | Minimum edge weight for expansion |
| `--filter` | โ | Filter by metadata field (`--filter "category = tutorial"`) |
| `--format` | `table` | Output format: `table`, `list`, or `json` |
Note: `--label` and `--file` are mutually exclusive. Use exactly one.
### `graphrag fts <QUERY> [DB]`
Exact full-text search via SQLite FTS5 โ classic keyword search.
```bash
graphrag fts "Python" graph.db -l 20
```
| `-l` | 10 | Number of results |
| `--notes-only` | โ | Show only notes (no entities/tags) |
| `--format` | `table` | Output format: `table`, `list`, or `json` |
---
### `graphrag graph <LABEL> [DB]`
Show neighbors of a node in the knowledge graph. Great for exploring.
```bash
graphrag graph "Docker" graph.db -d 2
```
---
### `graphrag map [DB]`
Interactive concept map TUI โ visually explore the knowledge graph in the terminal.
```bash
# Full graph
graphrag map graph.db
# Subgraph centered on a node
graphrag map --from Python --depth 3 graph.db
```
| `--from` | โ | Starting node label (omit for full graph) |
| `-d` | 2 | Graph expansion depth from starting node |
**Controls:**
| `โโโโ` / `hjkl` | Navigate between nodes |
| `Enter` | Select node (details in right panel) |
| `t` | Cycle filter: all โ notes โ entities โ tags |
| `/` | Search nodes by name |
| `q` / `Esc` | Quit |
| Mouse click | Select node |
---
### `graphrag path <FROM> <TO> [DB]`
Shortest path between two nodes โ discovers how concepts connect.
```bash
graphrag path "Python" "Docker" graph.db
# โ Python โ web-development โ containerization โ Docker
```
| `-d` | 10 | Maximum traversal depth |
---
### `graphrag stats [DB]`
Graph statistics. Omits the DB path to use the configured default.
```bash
graphrag stats graph.db
graphrag stats # uses config default
```
Output example:
```
Graph Statistics
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Nodes: 156
โข notes: 89
โข entities: 52
โข tags: 15
Edges: 342
Density: 0.028
Communities: 12
```
---
### `graphrag mcp`
Start an MCP server over stdio for AI assistant integration (see [MCP section](#-mcp-server)).
```bash
graphrag mcp --db graph.db
graphrag mcp --db graph.db --ollama-url http://localhost:11434
```
| `--db` | `graphrag.db` | Path to SQLite database |
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--embed-model` | `nomic-embed-text` | Embedding model |
---
## ๐ฏ Use cases & examples
### ๐ Personal knowledge base
You have 300 notes about programming, DevOps, and system design. You search for
"async Rust" and get back notes about tokio and async/await โ *plus* a note
about the "actor model" that never mentions those words.
```bash
# Build the graph
graphrag build ~/zettelkasten kb.db
# Hybrid search โ finds connected content you didn't explicitly search for
graphrag search "async Rust" kb.db -k 10 -d 2
# Example result you wouldn't get with vector-only search:
# "Actor Model in Distributed Systems" โ Score: 0.34 (from graph expansion)
# Connected via: concurrency (shared entity with async Rust notes)
```
### ๐ Technical documentation
Search across multiple project docs and discover cross-project connections.
```bash
graphrag build ~/docs --ner-model gemma4:12b
graphrag search "PostgreSQL high availability" -k 10 -d 3
graphrag path "Kubernetes" "SQLite"
# โ Kubernetes โ container-orchestration โ Docker โ embedded-database โ SQLite
```
### ๐งช Research paper collection
200 ML paper summaries. Find cross-disciplinary connections.
```bash
graphrag build ~/papers research.db
# Searching for "transformer attention" also surfaces a paper about
# "sparse mixture of experts" โ both connect through "self-attention"
graphrag search "transformer attention mechanisms" research.db -k 15 -d 2
# Explore concepts
graphrag graph "self-attention" research.db -d 1
```
### ๐ Hidden connections
Discover how seemingly unrelated topics connect through your graph.
```bash
# CSS to PostgreSQL? There's a path through web development
graphrag path "CSS" "PostgreSQL"
# โ CSS โ frontend โ web-development โ backend โ PostgreSQL
# Explore an entity's neighborhood
graphrag graph "machine-learning" -d 2
# Get a narrative answer about a topic
graphrag community detect research.db
graphrag community summarize research.db --summary-model gemma4:e2b
graphrag search "attention mechanisms" research.db --answer
```
### ๐ค AI assistant integration (MCP)
Let Claude, Cline, or any MCP-compatible AI assistant query your knowledge base
in real-time during conversations.
```json
{
"mcpServers": {
"graphrag": {
"command": "/usr/local/bin/graphrag",
"args": ["mcp", "--db", "/home/user/kb.db"]
}
}
}
```
Claude can now use tools to explore your knowledge graph:
- `search` โ hybrid semantic + graph search ๐
- `graph` โ explore neighbors of a node ๐ธ๏ธ
- `path` โ find connections between concepts ๐
- `stats` โ understand graph structure ๐
---
## ๐ Neovim plugin
Search and insert related notes without leaving your editor.
### Installation
```bash
graphrag init neovim --output ~/.config/nvim/lua/plugins/graphrag.lua
```
[lazy.nvim](https://github.com/folke/lazy.nvim) loads it automatically from `lua/plugins/`.
### Commands & keymaps
| `:GraphRAG related` | `,gr` | Find notes related to current buffer (floating window) |
| `:GraphRAG insert` | `,gi` | Find related and insert `## Related` links at end of file |
| `:GraphRAG search <q>` | โ | Hybrid search from command line |
| `:GraphRAG fts <q>` | โ | Full-text search |
| `:GraphRAG path <A> <B>` | โ | Shortest path |
| `:GraphRAG stats` | โ | Graph statistics |
---
## ๐ค MCP server
Expose your knowledge graph to any MCP-compatible AI assistant (Claude Desktop, Cline, etc.).
### Claude Desktop configuration
```json
{
"mcpServers": {
"graphrag": {
"command": "/usr/local/bin/graphrag",
"args": ["mcp", "--db", "/Users/me/knowledge/kb.db"]
}
}
}
```
### Tools exposed
| `build` | Build or update the graph from your notes directory |
| `search` | Hybrid search (vectors + graph) |
| `fts` | Full-text search |
| `graph` | Show neighbors of a node |
| `path` | Shortest path between two nodes |
| `stats` | Graph statistics |
| `seed` | Populate demo data |
### Resources exposed
| `graphrag://stats` | Graph statistics |
| `graphrag://nodes` | All nodes |
| `graphrag://notes` | Notes only |
| `graphrag://entities` | Entities only |
| `graphrag://edges` | All edges |
| `graphrag://nodes/<label>` | Single node details |
---
## ๐๏ธ Architecture
### Module map
```
๐ฆ graphrag (single ~6.5 MB binary)
โโโ src/
โ โโโ main.rs โ CLI entrypoint (clap, 12 subcommands)
โ โโโ config.rs โ TOML config (auto-created, all fields optional)
โ โโโ mcp/mod.rs โ MCP server (stdio, JSON-RPC 2.0)
โ โโโ db/
โ โ โโโ schema.rs โ SQLite schema + FTS5 virtual table
โ โโโ graph/
โ โ โโโ build.rs โ Incremental build (parallel NER, serial writer)
โ โ โโโ expand.rs โ Recursive CTE expansion + shortest path
โ โโโ search/
โ โ โโโ hybrid.rs โ 3-phase hybrid search engine
โ โโโ embed/
โ โ โโโ ollama.rs โ Ollama HTTP client (blocking reqwest)
โ โโโ vector/
โ โ โโโ mod.rs โ f32 โ BLOB, cosine similarity
โ โ โโโ synthetic.rs โ Deterministic hash-based embeddings
โ โโโ chunking/
โ โ โโโ markdown.rs โ Frontmatter parsing + section chunking
โ โโโ ner/
โ โ โโโ ollama_ner.rs โ LLM entity extraction (batch mode)
โ โโโ map/
โ โ โโโ mod.rs โ Data loading (load_graph, cmd_map)
โ โ โโโ layout.rs โ Force-directed layout algorithm
โ โ โโโ tui.rs โ Interactive TUI (ratatui)
โ โโโ seed/
โ โโโ demo_data.rs โ Demo data generator (44 nodes, 113 edges)
```
### How data flows
```
BUILD PIPELINE:
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโ
โ .md filesโ โ โ SHA256 โ โ โ N worker threads: โ โ โ 1 writer โ
โ โ โ pre-scan โ โ frontmatter โ chunk โ โ thread โ
โ โ โ โ โ โ NER batch (Ollama) โ โ โ SQLite โ
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโ
โ โ
Entities + co-occurrence Nodes + Edges
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโ
โ Prune โ โ Repopulate FTS5
โ deleted โ
โโโโโโโโโโโโ
SEARCH PIPELINE:
Query โ Embed โ Cosine similarity โ Rerank โ Graph expansion โ Results
โ โ โ โ โ โ
โ Ollama or Top-K scores +title Recursive Hybrid score
โ synthetic by semantic +type CTE from + content
โ similarity +alpha candidates + neighbors
```
### Database schema
```
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ
โ nodes โ โ edges โ
โโโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโโโค
โ id INT PK โโโโ โ source_id INT FK โ
โ key TEXT UQโ โโโโโโค target_id INT FK โ
โ label TEXT โ โโโโโโค type TEXT โ
โ type TEXT โ โโโโโโค type TEXT โ
โ embedding BLOB โ โ โ weight REAL โ
โ metadata JSON โ โ โ context TEXT โ
โ created_at INT โ โ โโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโ
notes_fts โ โ node_types โ
(FTS5 virtual) โ โโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ note โ
โ โ entity โ
โ โ tag โ
โโโโโโค โ
โโโโโโโโโโโโโโโโโโโโโโโโโ
```
**Node identity:** every node has a unique `key`. Notes use `key = "note:" + <relative path>`; entities, tags and directories use `key = "node:" + <label>`. This means two notes with the same title โ and even a note whose title matches an entity โ are stored as separate nodes instead of overwriting each other, so incremental builds converge.
---
## โก Performance
### Recommended Ollama models
| NER | `gemma4:e2b` | 5.1B | ~5GB | โญโญโญ Very good |
| NER | `gemma4:12b` | 11.9B | ~7GB | โญโญโญ Excellent |
| NER | `llama3.2:3b` | 3.2B | ~2GB | โญโญ Good (fast) |
| Embeddings | `bge-m3` | 566M | ~1GB | โญโญโญ Excellent |
| Embeddings | `nomic-embed-text` | 137M | ~0.5GB | โญโญ Good |
### Build throughput
| First build | 100 | ~20 min | With `gemma4:e2b`, 4 threads |
| First build | 6254 | ~22 h | Large docs repo |
| Incremental | 1 changed | ~2 s | Only re-processes modified files |
| No Ollama | any | ~5 s | Synthetic embeddings, no NER |
> **Tip:** The first build is the slowest (NER is LLM-bound). Subsequent builds are
> near-instant because only new/modified files are processed.
### Memory
| No Ollama (synthetic) | ~15 MB | Minimal |
| With `nomic-embed-text` | ~500 MB | + Ollama process |
| With `bge-m3` | ~1.5 GB | + Ollama process |
| With `gemma4:e2b` (NER) | ~5 GB | + Ollama process |
---
## ๐งช Tests
```bash
# All tests (123 tests, no external services needed)
cargo test
# Ollama-dependent tests (2 tests, requires Ollama running)
cargo test -- --ignored
# Lint
cargo clippy -- -D warnings
# Format check
cargo fmt --check
```
Tests use `tempfile` for temporary databases โ no cleanup needed.
---
## ๐ง Troubleshooting
### "Ollama is not running"
```
Error: connection refused
```
GraphRAG works without Ollama using synthetic embeddings. If you want Ollama
for better results:
```bash
# Start Ollama
ollama serve
# Verify it's running
curl http://localhost:11434/api/tags
```
### "Model not found"
```
WARN: model "gemma4:e2b" not found, skipping...
```
Pull the model:
```bash
ollama pull gemma4:e2b
```
### Build is slow
The first build runs NER (entity extraction) via LLM on every file. This is
expected โ LLMs are slow. After the first build, only changed files are processed.
Tips:
- Increase `num_threads` in config (watch your VRAM)
- Use a smaller NER model: `llama3.2:3b` is 2ร faster than `gemma4:e2b`
- Use `--ollama-url` to point to a remote Ollama server on a GPU machine
### "No entities found for any chunks"
Some models don't support Ollama's `format: json` mode. Try:
```bash
# Switch to a model that handles JSON output well
graphrag build --ner-model llama3.2:3b
# Or use gemma4 which has excellent JSON support
graphrag build --ner-model gemma4:e2b
```
### "graphrag.db" uses config but I wanted a literal file
If you pass `graphrag.db` (the default), GraphRAG substitutes the path from
your config file. To force a literal `graphrag.db` file, use the config path:
```toml
# In config.toml
db = "graphrag.db"
```
---
## โ FAQ
<details>
<summary><b>Does GraphRAG need Ollama?</b></summary>
No. Without Ollama, GraphRAG uses deterministic synthetic embeddings (hash-based).
Search still works โ just without the semantic quality that LLM embeddings provide.
</details>
<details>
<summary><b>Can I use it with non-Markdown files?</b></summary>
Currently only `.md` files are supported. The build pipeline parses Markdown
frontmatter and section headers for chunking.
</details>
<details>
<summary><b>How is this different from Microsoft's GraphRAG?</b></summary>
Microsoft GraphRAG is a Python project that uses global community summarization
for question-answering over large datasets. This project is a lightweight Rust
binary focused on personal knowledge bases โ instant search, no server, single
binary, works entirely offline.
</details>
<details>
<summary><b>Can I share the database between machines?</b></summary>
Yes โ the SQLite database is portable. Copy it between machines and it works.
Synthetic embeddings are deterministic (same text = same vector), so builds
are reproducible across machines.
</details>
<details>
<summary><b>How do I update the graph when I add new notes?</b></summary>
Just run `graphrag build` again. It only processes new and modified files
(checked via SHA256 hash). Deleted files are auto-pruned.
</details>
<details>
<summary><b>Does it work with multiple users?</b></summary>
The SQLite database supports concurrent readers. For write access (build),
only one process at a time.
</details>
---
## ๐ค Contributing
Contributions are welcome! Here's how to get started:
```bash
# Clone and build
git clone https://github.com/atareao/graphrag
cd graphrag
cargo build
# Run tests
cargo test
# Check lint
cargo clippy -- -D warnings
# Format
cargo fmt --check
```
### Development tips
- Use `RUST_LOG=debug graphrag build` to see detailed build logs
- The demo data seed is at `src/seed/demo_data.rs` โ great starting point
- All CLI commands are in `src/main.rs` โ easy to add new ones
- SQLite schema is in `src/db/schema.rs`
---
## ๐ Further reading
- [Microsoft GraphRAG paper](https://arxiv.org/abs/2404.16130) โ the original research
- [SQLite FTS5 documentation](https://www.sqlite.org/fts5.html) โ full-text search engine
- [Leiden algorithm](https://arxiv.org/abs/1810.08473) โ community detection used by GraphRAG
- [Ollama](https://ollama.ai/) โ local LLM server
---
## ๐ License
MIT โ see [LICENSE](LICENSE).
---
<div align="center">
<sub>Built with ๐ฆ Rust โข SQLite โข Ollama</sub>
</div>