LEANN
CLAUDE.md14k starsChanged 14 months agoMITView on GitHub
LEANN is a lightweight vector database and RAG (Retrieval-Augmented Generation) system that achieves 97% storage reduction compared to traditional vector databases through graph-based selective recomputation. It enables semantic search across various data sources (emails, browser history, chat history, code, documents) on a single laptop without cloud dependencies. Backends are auto-discovered via leann-backend-* naming convention and registered in registry.py. Example applications demonstrating RAG on various data sources: - document_rag.py: PDF/TXT/MD documents - email_rag.py: Apple Mail - browser_rag.py: Chrome browser history -…
- Pipes a download into a shell
- Installs packages
1 other project uses a version of this.
Trending
More talk lately.thin dataabout the whole repository
Most recently taken up by
- yichuan-w/LEANNword for word, first seen Oct 8, 2026
Who's talking about StarTrail-org/LEANN
- Tech Lead Corner“LEANN: Local Search With 97% Less Storage”YouTube · Oct 6, 2026 · 935 views
- whatvanefinds“This database stores 60M docs in 6 GB #aiagents #ai #opensource #vectordatabase #leann #claude”YouTube · Oct 29, 2026 · 464 views
- Prompt Engineer 48“LEANN: 201 GB vs 6 GB?! I Installed This INSANE Vector DB”YouTube · Oct 28, 2026 · 327 views
- RepoBytes | Find It. Understand It. Build With It.“Introducing LEANN - The World's Smallest Vector Index | 97% Storage Savings”YouTube · Oct 14, 2026 · 204 views
- Github God“13K ⭐ Semua Dokumen di Laptop Jadi Memory AI”YouTube · Nov 4, 2026 · 88 views
The biggest 5 of 13 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 13
Talked about on YouTube, GitHub and Hacker News (13 times).
On YouTube · 9
- Oct 6, 2026LEANN: Local Search With 97% Less Storage — Tech Lead Cornersays it tested it935 views
- Oct 29, 2026This database stores 60M docs in 6 GB #aiagents #ai #opensource #vectordatabase #leann #claude — whatvanefinds464 views
- Oct 28, 2026LEANN: 201 GB vs 6 GB?! I Installed This INSANE Vector DB — Prompt Engineer 48327 views
- Oct 14, 2026Introducing LEANN - The World's Smallest Vector Index | 97% Storage Savings — RepoBytes | Find It. Understand It. Build With It.says it tested it204 views
- Nov 4, 202613K ⭐ Semua Dokumen di Laptop Jadi Memory AI — Github God88 views
4 more on YouTube
- Oct 28, 2026LEANN省下磁盘,查询要等多久? — 智用AI8 views
- Oct 27, 2026We tested LEANN, the viral "vector databases are cooked" claim | We tested it on AgentX — AgentX AIsays it tested it6 views · 1 comment
- Oct 28, 2026LEANN省下磁盘,查询要等多久? #Shorts — 智用AI5 views
- Nov 4, 202613K ⭐ Turn Every Document on Your Laptop Into AI Memory — Github God Eng2 views
On GitHub · 3
- Nov 3, 2026Add pluggable LEANN scoring: Matryoshka, smaller embedders, and rerankers — antflydb/antfly0 reactions
- Nov 3, 2026Support LEANN retrieval over serverless immutable artifacts — antflydb/antfly0 reactions
- Sep 6, 2026[Feature]: recompute-at-query-time vector index (LEANN): record the technique and the threshold for revisiting it — pvliesdonk/markdown-vault-mcp0 reactions · 3 comments
On Hacker News · 1
- Oct 26, 2026Leann1 point
Other versions1 project uses a version of this.
Word for word · 1
- yichuan-w/LEANN★ 14k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repositoryOne other file it gives its agents.
- llms.txtllms.txt
The file
We split this CLAUDE.md into the rules it gives an agent
12 rules. About 0 are common, 9 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 105
Use --force / -f to force a full rebuild regardless.
- Distinctive: line 160
When you encounter a problem, fix it immediately and keep going until there are no more problems.
- Distinctive: line 161
Do not ask about ordering or sequencing — figure it out.
- Distinctive: line 163
No fallbacks or compatibility shims.
- Distinctive: line 168
Keep in sync with GitHub issue #237.
- Distinctive: line 174
Update the changelog when merging significant PRs or completing notable work.
- Very specific: line 179
Use docs/dev/TODO.md for in-progress tasks, docs/dev/PROGRESS.md for completed work.
- Very specific: line 184
All dev docs (PROGRESS.md, STATES.md, EXPERIMENTS.md, TODO.md) must be fully understandable from the document alone, with no reliance on …
- Distinctive: line 203
Keep TODO clean — either do items or remove them.
- Distinctive: line 208
Commit when: (1) a complete feature is finished and tested, or (2) a destructive change is unavoidable.
- Distinctive: line 213
When correcting errors: fix directly with no trace of the error.
- Distinctive: line 214
If you write a correct new version of a file, delete the wrong version.
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
LEANN is a lightweight vector database and RAG (Retrieval-Augmented Generation) system that achieves 97% storage reduction compared to traditional vector databases through graph-based selective recomputation. It enables semantic search across various data sources (emails, browser history, chat history, code, documents) on a single laptop without cloud dependencies.
Build & Development Commands
Quick install (pip)
pip install leannDevelopment setup (from source)
# Install uv first (required package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh
git submodule update --init --recursive
# macOS
brew install libomp boost protobuf zeromq pkgconf
uv sync
# Ubuntu/Debian
sudo apt-get install libomp-dev libboost-all-dev protobuf-compiler \
libabsl-dev libmkl-full-dev libaio-dev libzmq3-dev
uv sync
# Windows (requires VS 2022 Build Tools with C++ workload, vcpkg, chocolatey)
choco install cmake swig pkgconfiglite nuget.commandline -y
vcpkg install zeromq:x64-windows openblas:x64-windows lapack:x64-windows boost-program-options:x64-windows protobuf:x64-windows
# Set CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, OPENBLAS_LIB to vcpkg paths (see README)
uv sync --extra diskann
# Install lint tools
uv sync --group lint
# Install test tools
uv sync --group testCode Quality
# Format code
ruff format
# Lint with auto-fix
ruff check --fix
# Pre-commit hooks (install once)
pre-commit install
# Run pre-commit manually
uv run pre-commit run --all-filesArchitecture
Core API Layer (packages/leann-core/src/leann/)
api.py: Main APIs -LeannBuilder,LeannSearcher,LeannChatreact_agent.py:ReActAgentfor multi-turn reasoningcli.py: CLI implementation (leann build,leann search,leann ask)chat.py: LLM provider integrations (OpenAI, Ollama, HuggingFace, Anthropic)embedding_compute.py: Embedding computation (sentence-transformers, MLX, OpenAI)metadata_filter.py: Search result filtering by metadata
Backend Layer (packages/)
leann-backend-hnsw/: Default backend using FAISS HNSW for fast in-memory searchleann-backend-ivf/: IVF backend (FAISS IndexIVFFlat + DirectMap.Hashtable) supporting in-place add/remove without rebuildleann-backend-diskann/: DiskANN backend for larger-than-memory datasetsleann-mcp/: MCP server for Claude Code integration
Backends are auto-discovered via leann-backend-* naming convention and registered in registry.py.
RAG Applications (apps/)
Example applications demonstrating RAG on various data sources:
document_rag.py: PDF/TXT/MD documentsemail_rag.py: Apple Mailbrowser_rag.py: Chrome browser historywechat_rag.py,imessage_rag.py: Chat historycode_rag.py: Codebase search with AST-aware chunkingslack_rag.py,twitter_rag.py: MCP-based live data
Key Design Patterns
Incremental Update (IVF backend)
The IVF backend supports in-place updates and deletes without rebuilding the entire index:
add_vectors(index_path, embeddings, passage_ids): Append new vectors to an existing index.remove_ids(index_path, passage_ids): Remove vectors by passage ID using FAISS DirectMap.Hashtable.LeannBuilder.update_index(): High-level API that orchestrates remove-then-add for changed files, compactspassages.jsonl, and updates the offset map.
leann build is idempotent — re-running it on an existing index automatically performs an incremental update instead of a full rebuild. It detects new, modified, and removed files and applies the minimal set of changes:
- IVF: Supports add, remove, and modify incrementally (remove old chunks then re-insert).
- HNSW (non-compact): Supports add-only incremental updates; modified/removed files trigger a full rebuild.
- Use
--force/-fto force a full rebuild regardless.
Index Structure
A LEANN index consists of:
<name>.meta.json: Metadata (backend, embedding model, dimensions)<name>.passages.jsonl: Raw text chunks with metadata<name>.passages.idx: Offset map for fast passage lookup<name>.index: Backend-specific vector index
Embedding Recomputation
The core storage optimization: instead of storing embeddings, LEANN stores a pruned graph and recomputes embeddings on-demand during search via ZMQ server communication.
CLI Usage
# Build index
leann build my-docs --docs ./documents/
# Search
leann search my-docs "query"
# Interactive chat
leann ask my-docs --interactive
# List indexes
leann list
# Remove index
leann remove my-docsCommon Development Tasks
Running example RAG applications:
# Document RAG (easiest to test)
python -m apps.document_rag --query "What is LEANN?"
# Code RAG
python -m apps.code_rag --repo-dir ./src --query "How does search work?"Python Version
Requires Python 3.10+ (uses PEP 604 union syntax X | Y).
Agent Coding Guidelines
General
- Voice input may contain typos — interpret intent, not literal text.
- When you encounter a problem, fix it immediately and keep going until there are no more problems.
- Do not ask about ordering or sequencing — figure it out. If something is unclear, note it and skip it; only escalate when all paths are blocked.
- Obvious bugs: fix silently without reporting.
- No fallbacks or compatibility shims. One correct implementation per feature — no redundancy.
Roadmap
- Public roadmap:
docs/roadmap.md— tracks P0/P1 priorities, completed milestones, and timeline. - Long-term vision:
docs/ultimate_goal.md— the north star for where LEANN is headed. - Keep in sync with GitHub issue #237.
- Welcome everyone to add more, and the craziest feature you want to put here! If people want some feature, all put there.
Changelog (for contributors)
- Maintain
docs/CHANGELOG.md— append-only log of major changes (new features, breaking changes, important fixes). - Format:
## YYYY-MM-DD: <short summary>followed by bullet points. - Update the changelog when merging significant PRs or completing notable work.
- See
docs/CONTRIBUTING.mdfor full contributor workflow (conventional commits, PR process, CI).
Personal Dev Notes (gitignored)
docs/dev/is gitignored for personal development notes (TODO, progress, experiments).- Use
docs/dev/TODO.mdfor in-progress tasks,docs/dev/PROGRESS.mdfor completed work. - These are private scratch space — but must follow the Self-Contained Principle below.
Documentation — Self-Contained Principle
All dev docs (PROGRESS.md, STATES.md, EXPERIMENTS.md, TODO.md) must be fully understandable from the document alone, with no reliance on conversation context or implied knowledge.
Requirements:
- Every technique/approach must be explained on first use. Not "switched to IVF backend" — write "switched to IVF backend (FAISS IndexIVFFlat + DirectMap.Hashtable, supports in-place add/remove without full index rebuild)."
- Never assume the reader knows any abbreviation. On first use: full name + one-sentence explanation. E.g., "HNSW (Hierarchical Navigable Small World — a graph-based ANN index used as LEANN's default backend)."
- Benchmark results must include full context. Not "recall improved to 0.95" — write "recall@10 improved from 0.91 to 0.95 after switching from flat chunking (512 tokens, no overlap) to AST-aware chunking (function-level splits with 64-token overlap)."
- Numbers must have reference points. Not "build time: 12s" — write "build time: 12s (vs. 45s before incremental update support, on 10k-document corpus)."
- Include the causal chain — not just conclusions. Not "duplicate chunks appeared after incremental build" — write "Duplicate chunks appeared after incremental build because
passages.jsonlwas appended without first removing stale entries for modified files. The IVF index had correct vectors (remove-then-add), but the passage store was append-only, causing the same text to appear at multiple offsets." docs/dev/STATES.mdtop section maintains a glossary of all key terms (backends, index files, chunking strategies, embedding models). Other docs reference it at the top.
Bad examples (forbidden):
- "Fixed the chunking bug" → Which bug? What was the symptom? What was the root cause?
- "Improved search quality" → By what metric? From what baseline? What change caused it?
- "Used nprobe=32" → What is nprobe? Why 32? What was it before and what effect did the change have?
Doc Maintenance
- Maintain
docs/dev/PROGRESS.md— completed work only (with key script/log/config paths). No plans. - Maintain
docs/dev/TODO.md— incomplete/in-progress/next-steps only (aim for one-command reproducibility). When done: remove from TODO, write result to PROGRESS, update STATES/EXPERIMENTS if needed. - Both files: append-only, chronological order (oldest first). Use
tail -n 80 docs/dev/PROGRESS.mdto read recent entries; increase range or grep by date/keyword if needed. - Keep TODO clean — either do items or remove them. Ask the user when unsure how to handle a TODO item.
- Maintain
docs/dev/STATES.md— tracks all currently useful state (index configs, backend choices, known limitations); does NOT grow indefinitely (delete stale entries). - Maintain
docs/dev/EXPERIMENTS.md— benchmarks, A/B comparisons, parameter sweeps (recall@k, latency, storage size). Experimental content goes here, not in STATES.md.
Commits
Commit when: (1) a complete feature is finished and tested, or (2) a destructive change is unavoidable.
git add <specific files>
git commit -m “feat: ...” # follow conventional commits- When correcting errors: fix directly with no trace of the error.
- If you write a correct new version of a file, delete the wrong version. No duplicate implementations.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

