LEANN

StarTrail-orgMIT活跃维护

在个人设备上本地跑 RAG 的向量索引库,用图结构剪枝把索引体积压掉 97%,兼顾检索速度和准确率,数据不出本机。

[MLsys2026 Best Paper]: https://arxiv.org/abs/2506.08276. RAG on Everything with LEANN. Enjoy 97% storage savings while running a fast, accurate, and 100% private RAG application on your personal device.

v0.3.9发布于 2026-11-02 03:32 UTC13,787star +9 / 7 天1,283fork同步于 2026-11-10 11:27 UTC

怎么上手

由 README 提炼,执行前请确认
curl -LsSf https://astral.sh/uv/install.sh | sh
git clone https://github.com/StarTrail-org/LEANN.git leann
cd leann
uv venv
source .venv/bin/activate
uv pip install leann
硬件要求按 README 说明

README 未说明具体显存或 GPU 型号要求;提供 CPU-only 安装方式(Linux 用 leann[cpu] extra),支持 Ubuntu、Arch、WSL、macOS(ARM64/Intel)与 Windows。

纯 CPU 可运行支持 Apple Silicon多卡 / 张量并行
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把笔记本变成本地 RAG 系统,用图选择性重算省下 97% 向量索引存储

在个人设备上本地跑 RAG 的向量索引库,用图结构剪枝把索引体积压掉 97%,兼顾检索速度和准确率,数据不出本机。

核心能力

  • 用图选择性重算与高度保留剪枝,按需计算 embedding 而非全量存储
  • 索引 6000 万文本块仅占 6GB,对比传统方案 201GB
  • 支持 PDF/TXT/MD、邮件、浏览器历史、聊天记录等个人数据源
  • 提供 LeannBuilder/LeannSearcher/LeannChat 声明式 Python API
  • 原生 MCP 集成,可作为 Claude Code 的语义搜索服务

容易踩的坑

需先单独安装 uv 包管理器;Linux 上 leann build 可能因 Security Violation [pathsec.open] 报错,需按 README 处理;使用 OpenAI 等云端 LLM 需自行设置 OPENAI_API_KEY,默认走 OpenAI 接口。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.3.9
  1. v0.3.9Release v0.3.9最新正式版2026-11-02 · 2026-11-02 03:32 UTC
  2. v0.3.8Release v0.3.82026-09-28 · 2026-09-28 15:35 UTC
    查看更新说明
  3. v0.3.7Release v0.3.72026-03-08 · 2026-03-08 21:37 UTC
    查看更新说明
  4. v0.3.6Release v0.3.62026-01-11 · 2026-01-11 10:38 UTC
    查看更新说明
  5. v0.3.5Release v0.3.52025-11-12 · 2025-11-12 06:49 UTC
    查看更新说明

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    LEANN is an innovative vector database that democratizes personal AI. Transform your laptop into a powerful RAG system that can index and search through millions of documents while using 97% less storage than traditional solutions without accuracy loss.

    LEANN achieves this through graph-based selective recomputation with high-degree preserving pruning, computing embeddings on-demand instead of storing them all. Illustration Fig → | Paper →

    Ready to RAG Everything? Transform your laptop into a personal AI assistant that can semantic search your file system, emails, browser history, chat history (WeChat, iMessage), agent memory (ChatGPT, Claude), live data (Slack, Twitter), codebase*, or external knowledge bases (i.e., 60M documents) - all on your laptop, with zero cloud costs and complete privacy.

    * Claude Code only supports basic grep-style keyword search. LEANN is a drop-in semantic search MCP service fully compatible with Claude Code, unlocking intelligent retrieval without changing your workflow. 🔥 Check out the easy setup →

    Why LEANN?

    The numbers speak for themselves: Index 60 million text chunks in just 6GB instead of 201GB. From emails to browser history, everything fits on your laptop. See detailed benchmarks for different applications below ↓

    🔒 Privacy: Your data never leaves your laptop. No OpenAI, no cloud, no "terms of service".

    🪶 Lightweight: Graph-based recomputation eliminates heavy embedding storage, while smart graph pruning and CSR format minimize graph storage overhead. Always less storage, less memory usage!

    📦 Portable: Transfer your entire knowledge base between devices (even with others) with minimal cost - your personal AI memory travels with you.

    📈 Scalability: Handle messy personal data that would crash traditional vector DBs, easily managing your growing personalized data and agent generated memory!

    ✨ No Accuracy Loss: Maintain the same search quality as heavyweight solutions while using 97% less storage.

    Making Your Coding Agent Smarter

    We plugged LEANN into Claude Code and compared it with BM25 on 30 SWE-Bench Pro tasks from ContextBench, keeping the model, agent, tools, and 8,192-token retrieval budget fixed.

    With LEANN, the agent achieved 2.1× the initial relevant-code recall (24.2% vs. 11.4%), reached 12.6 percentage points higher relevant-code coverage after exploration (38.4% vs. 25.8%), and used 8.4% fewer tokens (3.22M vs. 3.51M).

    LEANN surfaces relevant code earlier, so coding agents can spend more of their context window reasoning about the right files instead of repeatedly scanning the repository. Reproduce the benchmark →

    Note: Results are macro-averaged annotated gold-line metrics over 30 SWE-Bench Pro tasks. Better context access does not guarantee issue resolution.

    Installation

    📦 Prerequisites: Install uv

    Install uv first if you don't have it. Typically, you can install it with:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    

    🚀 Quick Install

    Clone the repository to access all examples and try amazing applications,

    git clone https://github.com/StarTrail-org/LEANN.git leann
    cd leann
    

    and install LEANN from PyPI to run them immediately:

    uv venv
    source .venv/bin/activate
    uv pip install leann
    
    # CPU-only (Linux): use the `cpu` extra (e.g. `leann[cpu]`)
    

    Linux note: if a later leann build fails with Security Violation [pathsec.open]: refusing multiply-linked file, reinstall with UV_LINK_MODE=copy uv pip install --reinstall ... (or UV_LINK_MODE=copy uv tool install --reinstall ...) - uv's default hardlink installs trip nltk's hardened file loader bundled with llama-index. Details in the FAQ.

    git clone https://github.com/StarTrail-org/LEANN.git leann
    cd leann
    git submodule update --init --recursive
    

    macOS:

    Note: DiskANN requires MacOS 13.3 or later.

    brew install libomp boost protobuf zeromq pkgconf
    uv sync --extra diskann
    

    Linux (Ubuntu/Debian):

    Note: On Ubuntu 20.04, you may need to build a newer Abseil and pin Protobuf (e.g., v3.20.x) for building DiskANN. See Issue #30 for a step-by-step note.

    You can manually install Intel oneAPI MKL instead of libmkl-full-dev for DiskANN. You can also use libopenblas-dev for building HNSW only, by removing --extra diskann in the command below.

    sudo apt-get update && sudo apt-get install -y \
      libomp-dev libboost-all-dev protobuf-compiler libzmq3-dev \
      pkg-config libabsl-dev libaio-dev libprotobuf-dev \
      libmkl-full-dev
    
    uv sync --extra diskann
    

    Linux (Arch Linux):

    sudo pacman -Syu && sudo pacman -S --needed base-devel cmake pkgconf git gcc \
      boost boost-libs protobuf abseil-cpp libaio zeromq
    
    # For MKL in DiskANN
    sudo pacman -S --needed base-devel git
    git clone https://aur.archlinux.org/paru-bin.git
    cd paru-bin && makepkg -si
    paru -S intel-oneapi-mkl intel-oneapi-compiler
    source /opt/intel/oneapi/setvars.sh
    
    uv sync --extra diskann
    

    Linux (RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux):

    See Issue #50 for more details.

    sudo dnf groupinstall -y "Development Tools"
    sudo dnf install -y libomp-devel boost-devel protobuf-compiler protobuf-devel \
      abseil-cpp-devel libaio-devel zeromq-devel pkgconf-pkg-config
    
    # For MKL in DiskANN
    sudo dnf install -y intel-oneapi-mkl intel-oneapi-mkl-devel \
      intel-oneapi-openmp || sudo dnf install -y intel-oneapi-compiler
    source /opt/intel/oneapi/setvars.sh
    
    uv sync --extra diskann
    

    Windows:

    Requires Visual Studio 2022 Build Tools with the C++ desktop development workload, and vcpkg.

    # Install toolchain (if not already present)
    choco install cmake swig pkgconfiglite nuget.commandline -y
    
    # Install C++ dependencies via vcpkg
    vcpkg install zeromq:x64-windows openblas:x64-windows lapack:x64-windows `
      boost-program-options:x64-windows protobuf:x64-windows
    
    # Set environment variables (adjust VCPKG_ROOT to your vcpkg path)
    $env:CMAKE_PREFIX_PATH = "$env:VCPKG_ROOT\installed\x64-windows"
    $env:PKG_CONFIG_PATH = "$env:VCPKG_ROOT\installed\x64-windows\lib\pkgconfig"
    $env:PKG_CONFIG_EXECUTABLE = "C:\ProgramData\chocolatey\bin\pkg-config.exe"
    $env:OPENBLAS_LIB = "$env:VCPKG_ROOT\installed\x64-windows\lib\openblas.lib"
    $env:PATH += ";$env:VCPKG_ROOT\installed\x64-windows\bin"
    $env:PATH += ";$env:VCPKG_ROOT\installed\x64-windows\tools\protobuf"
    
    uv sync --extra diskann
    

    Quick Start

    Our declarative API makes RAG as easy as writing a config file.

    Check out demo.ipynb or Open In Colab

    from leann import LeannBuilder, LeannSearcher, LeannChat
    from pathlib import Path
    INDEX_PATH = str(Path("./").resolve() / "demo.leann")
    
    # Build an index
    builder = LeannBuilder(backend_name="hnsw")
    builder.add_text("LEANN saves 97% storage compared to traditional vector databases.")
    builder.add_text("Tung Tung Tung Sahur called—they need their banana‑crocodile hybrid back")
    builder.build_index(INDEX_PATH)
    
    # Search
    searcher = LeannSearcher(INDEX_PATH)
    results = searcher.search("fantastical AI-generated creatures", top_k=1)
    
    # Chat with your data
    chat = LeannChat(INDEX_PATH, llm_config={"type": "hf", "model": "Qwen/Qwen3-0.6B"})
    response = chat.ask("How much storage does LEANN save?", top_k=1)
    

    RAG on Everything!

    LEANN supports RAG on various data sources including documents (.pdf, .txt, .md), Apple Mail, Google Search History, WeChat, ChatGPT conversations, Claude conversations, iMessage conversations, and live data from any platform through MCP (Model Context Protocol) servers - including Slack, Twitter, and more.

    Generation Model Setup

    LLM Backend

    LEANN supports many LLM providers for text generation (HuggingFace, Ollama, Anthropic, and Any OpenAI compatible API).

    Set your OpenAI API key as an environment variable:

    export OPENAI_API_KEY="your-api-key-here"
    

    Make sure to use --llm openai flag when using the CLI. You can also specify the model name with --llm-model <model-name> flag.

    Thanks to the widespread adoption of the OpenAI API format, LEANN is compatible out-of-the-box with a vast array of LLM and embedding providers. Simply set the OPENAI_BASE_URL and OPENAI_API_KEY environment variables to connect to your preferred service.

    export OPENAI_API_KEY="xxx"
    export OPENAI_BASE_URL="http://localhost:1234/v1" # base url of the provider
    

    To use OpenAI compatible endpoint with the CLI interface:

    If you are using it for text generation, make sure to use --llm openai flag and specify the model name with --llm-model <model-name> flag.

    If you are using it for embedding, set the --embedding-mode openai flag and specify the model name with --embedding-model <MODEL>.


    Below is a list of base URLs for common providers to get you started.

    🖥️ Local Inference Engines (Recommended for full privacy)

    ProviderSample Base URL
    Ollamahttp://localhost:11434/v1
    LM Studiohttp://localhost:1234/v1
    vLLMhttp://localhost:8000/v1
    llama.cpphttp://localhost:8080/v1
    SGLanghttp://localhost:30000/v1
    LiteLLMhttp://localhost:4000

    ☁️ Cloud Providers

    🚨 A Note on Privacy: Before choosing a cloud provider, carefully review their privacy and data retention policies. Depending on their terms, your data may be used for their own purposes, including but not limited to human reviews and model training, which can lead to serious consequences if not handled properly.

    ProviderBase URL
    OpenAIhttps://api.openai.com/v1
    OpenRouterhttps://openrouter.ai/api/v1
    Geminihttps://generativelanguage.googleapis.com/v1beta/openai/
    x.AI (Grok)https://api.x.ai/v1
    Groq AIhttps://api.groq.com/openai/v1
    DeepSeekhttps://api.deepseek.com/v1
    SiliconFlowhttps://api.siliconflow.cn/v1
    Zhipu (BigModel)https://open.bigmodel.cn/api/paas/v4/
    Mistral AIhttps://api.mistral.ai/v1
    Anthropichttps://api.anthropic.com/v1
    Jina AI (Embeddings)https://api.jina.ai/v1

    💡 Tip: Separate Embedding Provider

    To use a different provider for embeddings (e.g., Jina AI) while using another for LLM, use --embedding-api-base and --embedding-api-key:

    leann build my-index --docs ./docs \
      --embedding-mode openai \
      --embedding-model jina-embeddings-v3 \
      --embedding-api-base https://api.jina.ai/v1 \
      --embedding-api-key $JINA_API_KEY
    

    If your provider isn't on this list, don't worry! Check their documentation for an OpenAI-compatible endpoint—chances are, it's OpenAI Compatible too!

    macOS:

    First, download Ollama for macOS.

    # Pull a lightweight model (recommended for consumer hardware)
    ollama pull llama3.2:1b
    

    Linux:

    # Install Ollama
    curl -fsSL https://ollama.ai/install.sh | sh
    
    # Start Ollama service manually
    ollama serve &
    
    # Pull a lightweight model (recommended for consumer hardware)
    ollama pull llama3.2:1b
    

    ⭐ Flexible Configuration

    LEANN provides flexible parameters for embedding models, search strategies, and data processing to fit your specific needs.

    📚 Need configuration best practices? Check our Configuration Guide for detailed optimization tips, model selection advice, and solutions to common issues like slow embeddings or poor search quality.

    All RAG examples share these common parameters. Interactive mode is available in all examples - simply run without --query to start a continuous Q&A session where you can ask multiple questions. Type 'quit' to exit.

    # Environment Variables (GPU Device Selection)
    LEANN_EMBEDDING_DEVICE       # GPU for embedding model (e.g., cuda:0, cuda:1, cpu)
    LEANN_LLM_DEVICE             # GPU for HFChat LLM (e.g., cuda:1, or "cuda" for multi-GPU auto)
    
    # Core Parameters (General preprocessing for all examples)
    --index-dir DIR              # Directory to store the index (default: current directory)
    --query "YOUR QUESTION"      # Single query mode. Omit for interactive chat (type 'quit' to exit), and now you can play with your index interactively
    --max-items N                # Limit data preprocessing (default: -1, process all data)
    --force-rebuild              # Force rebuild index even if it exists
    
    # Embedding Parameters
    --embedding-model MODEL      # e.g., facebook/contriever, text-embedding-3-small, mlx-community/Qwen3-Embedding-0.6B-8bit or nomic-embed-text
    --embedding-mode MODE        # sentence-transformers, openai, mlx, or ollama
    
    # LLM Parameters (Text generation models)
    --llm TYPE                   # LLM backend: openai, ollama, hf, or anthropic (default: openai)
    --llm-model MODEL            # Model name (default: gpt-4o) e.g., gpt-4o-mini, llama3.2:1b, Qwen/Qwen2.5-1.5B-Instruct
    --thinking-budget LEVEL      # Thinking budget for reasoning models: low/medium/high (supported by o3, o3-mini, GPT-Oss:20b, and other reasoning models)
    
    # Search Parameters
    --top-k N                    # Number of results to retrieve (default: 20)
    --search-complexity N        # Search complexity for graph traversal (default: 32)
    
    # Chunking Parameters
    --chunk-size N               # Size of text chunks (default varies by source: 256 for most, 192 for WeChat)
    --chunk-overlap N            # Overlap between chunks (default varies: 25-128 depending on source)
    
    # Index Building Parameters
    --backend-name NAME          # Backend to use: hnsw or diskann (default: hnsw)
    --graph-degree N             # Graph degree for index construction (default: 32)
    --build-complexity N         # Build complexity for index construction (default: 64)
    --compact / --no-compact     # Use compact storage (default: true). Must be `no-compact` for `no-recompute` build.
    --recompute / --no-recompute # Enable/disable embedding recomputation (default: enabled). Should not do a `no-recompute` search in a `recompute` build.
    

    📄 Personal Data Manager: Process Any Documents (.pdf, .txt, .md)!

    Ask questions directly about your personal PDFs, documents, and any directory containing your files!

    The example below asks a question about summarizing our paper (uses default data in data/, which is a directory with diverse data sources: two papers, Pride and Prejudice, and a Technical report about LLM in Huawei in Chinese), and this is the easiest example to run here:

    source .venv/bin/activate # Don't forget to activate the virtual environment
    python -m apps.document_rag --query "What are the main techniques LEANN explores?"
    
    Parameters
    --data-dir DIR           # Directory containing documents to process (default: data)
    --file-types .ext .ext   # Filter by specific file types (optional - all LlamaIndex supported types if omitted)
    
    Example Commands
    # Process all documents with larger chunks for academic papers
    python -m apps.document_rag --data-dir "~/Documents/Papers" --chunk-size 1024
    
    # Filter only markdown and Python files with smaller chunks
    python -m apps.document_rag --data-dir "./docs" --chunk-size 256 --file-types .md .py
    
    # Enable AST-aware chunking for code files
    python -m apps.document_rag --enable-code-chunking --data-dir "./my_project"
    
    # Or use the specialized code RAG for better code understanding
    python -m apps.code_rag --repo-dir "./my_codebase" --query "How does authentication work?"
    

    🎨 ColQwen: Multimodal PDF Retrieval with Vision-Language Models

    Search through PDFs using both text and visual understanding with ColQwen2/ColPali models. Perfect for research papers, technical documents, and any PDFs with complex layouts, figures, or diagrams.

    🍎 Mac Users: ColQwen is optimized for Apple Silicon with MPS acceleration for faster inference!

    # Build index from PDFs
    python -m apps.colqwen_rag build --pdfs ./my_papers/ --index research_papers
    
    # Search with text queries
    python -m apps.colqwen_rag search research_papers "How does attention mechanism work?"
    
    # Interactive Q&A
    python -m apps.colqwen_rag ask research_papers --interactive
    
    Prerequisites
    # Install dependencies
    uv pip install colpali_engine pdf2image pillow matplotlib qwen_vl_utils einops seaborn
    brew install poppler  # macOS only, for PDF processing
    
    Build Index
    python -m apps.colqwen_rag build \
      --pdfs ./pdf_directory/ \
      --index my_index \
      --model colqwen2  # or colpali
    
    Search
    python -m apps.colqwen_rag search my_index "your question here" --top-k 5
    
    Models
    • ColQwen2 (colqwen2): Latest vision-language model with improved performance
    • ColPali (colpali): Proven multimodal retriever

    For detailed usage, see the ColQwen Guide.

    📧 Your Personal Email Secretary: RAG on Apple Mail!

    Note: The examples below currently support macOS only. Windows support coming soon.

    Before running the example below, you need to grant full disk access to your terminal/VS Code in System Preferences → Privacy & Security → Full Disk Access.

    python -m apps.email_rag --query "What's the food I ordered by DoorDash or Uber Eats mostly?"
    

    780K email chunks → 78MB storage. Finally, search your email like you search Google.

    Parameters
    --mail-path PATH         # Path to specific mail directory (auto-detects if omitted)
    --include-html          # Include HTML content in processing (useful for newsletters)
    
    Example Commands
    # Search work emails from a specific account
    python -m apps.email_rag --mail-path "~/Library/Mail/V10/WORK_ACCOUNT"
    
    # Find all receipts and order confirmations (includes HTML)
    python -m apps.email_rag --query "receipt order confirmation invoice" --include-html
    

    Once the index is built, you can ask questions like:

    • "Find emails from my boss about deadlines"
    • "What did John say about the project timeline?"
    • "Show me emails about travel expenses"

    🔍 Time Machine for the Web: RAG Your Entire Chrome Browser History!

    python -m apps.browser_rag --query "Tell me my browser history about machine learning?"
    

    38K browser entries → 6MB storage. Your browser history becomes your personal search engine.

    Parameters
    --chrome-profile PATH    # Path to Chrome profile directory (auto-detects if omitted)
    
    Example Commands
    # Search academic research from your browsing history
    python -m apps.browser_rag --query "arxiv papers machine learning transformer architecture"
    
    # Track competitor analysis across work profile
    python -m apps.browser_rag --chrome-profile "~/Library/Application Support/Google/Chrome/Work Profile" --max-items 5000
    

    The default Chrome profile path is configured for a typical macOS setup. If you need to find your specific Chrome profile:

    1. Open Terminal
    2. Run: ls ~/Library/Application\ Support/Google/Chrome/
    3. Look for folders like "Default", "Profile 1", "Profile 2", etc.
    4. Use the full path as your --chrome-profile argument

    Common Chrome profile locations:

    • macOS: ~/Library/Application Support/Google/Chrome/Default
    • Linux: ~/.config/google-chrome/Default

    Once the index is built, you can ask questions like:

    • "What websites did I visit about machine learning?"
    • "Find my search history about programming"
    • "What YouTube videos did I watch recently?"
    • "Show me websites I visited about travel planning"

    💬 WeChat Detective: Unlock Your Golden Memories!

    python -m apps.wechat_rag --query "Show me all group chats about weekend plans"
    

    400K messages → 64MB storage Search years of chat history in any language.

    First, you need to install the WeChat exporter,

    brew install sunnyyoung/repo/wechattweak-cli
    

    or install it manually (if you have issues with Homebrew):

    sudo packages/wechat-exporter/wechattweak-cli install
    

    Troubleshooting:

    • Installation issues: Check the WeChatTweak-CLI issues page
    • Export errors: If you encounter the error below, try restarting WeChat
      Failed to export WeChat data. Please ensure WeChat is running and WeChatTweak is installed.
      Failed to find or export WeChat data. Exiting.
      
    Parameters
    --export-dir DIR         # Directory to store exported WeChat data (default: wechat_export_direct)
    --force-export          # Force re-export even if data exists
    
    Example Commands
    # Search for travel plans discussed in group chats
    python -m apps.wechat_rag --query "travel plans" --max-items 10000
    
    # Re-export and search recent chats (useful after new messages)
    python -m apps.wechat_rag --force-export --query "work schedule"
    

    Once the index is built, you can ask questions like:

    • "我想买魔术师约翰逊的球衣,给我一些对应聊天记录?" (Chinese: Show me chat records about buying Magic Johnson's jersey)

    🤖 ChatGPT Chat History: Your Personal AI Conversation Archive!

    Transform your ChatGPT conversations into a searchable knowledge base! Search through all your ChatGPT discussions about coding, research, brainstorming, and more.

    python -m apps.chatgpt_rag --export-path chatgpt_export.html --query "How do I create a list in Python?"
    

    Unlock your AI conversation history. Never lose track of valuable insights from your ChatGPT discussions again.

    Step-by-step export process:

    1. Sign in to ChatGPT
    2. Click your profile icon in the top right corner
    3. Navigate to Settings → Data Controls
    4. Click "Export" under Export Data
    5. Confirm the export request
    6. Download the ZIP file from the email link (expires in 24 hours)
    7. Extract or use directly with LEANN

    Supported formats:

    • .html files from ChatGPT exports
    • .zip archives from ChatGPT
    • Directories with multiple export files
    Parameters
    --export-path PATH           # Path to ChatGPT export file (.html/.zip) or directory (default: ./chatgpt_export)
    --separate-messages         # Process each message separately instead of concatenated conversations
    --chunk-size N              # Text chunk size (default: 512)
    --chunk-overlap N           # Overlap between chunks (default: 128)
    
    Example Commands
    # Basic usage with HTML export
    python -m apps.chatgpt_rag --export-path conversations.html
    
    # Process ZIP archive from ChatGPT
    python -m apps.chatgpt_rag --export-path chatgpt_export.zip
    
    # Search with specific query
    python -m apps.chatgpt_rag --export-path chatgpt_data.html --query "Python programming help"
    
    # Process individual messages for fine-grained search
    python -m apps.chatgpt_rag --separate-messages --export-path chatgpt_export.html
    
    # Process directory containing multiple exports
    python -m apps.chatgpt_rag --export-path ./chatgpt_exports/ --max-items 1000
    

    Once your ChatGPT conversations are indexed, you can search with queries like:

    • "What did I ask ChatGPT about Python programming?"
    • "Show me conversations about machine learning algorithms"
    • "Find discussions about web development frameworks"
    • "What coding advice did ChatGPT give me?"
    • "Search for conversations about debugging techniques"
    • "Find ChatGPT's recommendations for learning resources"

    🤖 Claude Chat History: Your Personal AI Conversation Archive!

    Transform your Claude conversations into a searchable knowledge base! Search through all your Claude discussions about coding, research, brainstorming, and more.

    python -m apps.claude_rag --export-path claude_export.json --query "What did I ask about Python dictionaries?"
    

    Unlock your AI conversation history. Never lose track of valuable insights from your Claude discussions again.

    Step-by-step export process:

    1. Open Claude in your browser
    2. Navigate to Settings (look for gear icon or settings menu)
    3. Find Export/Download options in your account settings
    4. Download conversation data (usually in JSON format)
    5. Place the file in your project directory

    Note: Claude export methods may vary depending on the interface you're using. Check Claude's help documentation for the most current export instructions.

    Supported formats:

    • .json files (recommended)
    • .zip archives containing JSON data
    • Directories with multiple export files
    Parameters
    --export-path PATH           # Path to Claude export file (.json/.zip) or directory (default: ./claude_export)
    --separate-messages         # Process each message separately instead of concatenated conversations
    --chunk-size N              # Text chunk size (default: 512)
    --chunk-overlap N           # Overlap between chunks (default: 128)
    
    Example Commands
    # Basic usage with JSON export
    python -m apps.claude_rag --export-path my_claude_conversations.json
    
    # Process ZIP archive from Claude
    python -m apps.claude_rag --export-path claude_export.zip
    
    # Search with specific query
    python -m apps.claude_rag --export-path claude_data.json --query "machine learning advice"
    
    # Process individual messages for fine-grained search
    python -m apps.claude_rag --separate-messages --export-path claude_export.json
    
    # Process directory containing multiple exports
    python -m apps.claude_rag --export-path ./claude_exports/ --max-items 1000
    

    Once your Claude conversations are indexed, you can search with queries like:

    • "What did I ask Claude about Python programming?"
    • "Show me conversations about machine learning algorithms"
    • "Find discussions about software architecture patterns"
    • "What debugging advice did Claude give me?"
    • "Search for conversations about data structures"
    • "Find Claude's recommendations for learning resources"

    💬 iMessage History: Your Personal Conversation Archive!

    Transform your iMessage conversations into a searchable knowledge base! Search through all your text messages, group chats, and conversations with friends, family, and colleagues.

    python -m apps.imessage_rag --query "What did we discuss about the weekend plans?"
    

    Unlock your message history. Never lose track of important conversations, shared links, or memorable moments from your iMessage history.

    iMessage data location:

    iMessage conversations are stored in a SQLite database on your Mac at:

    ~/Library/Messages/chat.db
    

    Important setup requirements:

    1. Grant Full Disk Access to your terminal or IDE:

      • Open System Preferences → Security & Privacy → Privacy
      • Select Full Disk Access from the left sidebar
      • Click the + button and add your terminal app (Terminal, iTerm2) or IDE (VS Code, etc.)
      • Restart your terminal/IDE after granting access
    2. Alternative: Use a backup database

      • If you have Time Machine backups or manual copies of the database
      • Use --db-path to specify a custom location

    Supported formats:

    • Direct access to ~/Library/Messages/chat.db (default)
    • Custom database path with --db-path
    • Works with backup copies of the database
    Parameters
    --db-path PATH                    # Path to chat.db file (default: ~/Library/Messages/chat.db)
    --concatenate-conversations       # Group messages by conversation (default: True)
    --no-concatenate-conversations    # Process each message individually
    --chunk-size N                    # Text chunk size (default: 1000)
    --chunk-overlap N                 # Overlap between chunks (default: 200)
    
    Example Commands
    # Basic usage (requires Full Disk Access)
    python -m apps.imessage_rag
    
    # Search with specific query
    python -m apps.imessage_rag --query "family dinner plans"
    
    # Use custom database path
    python -m apps.imessage_rag --db-path /path/to/backup/chat.db
    
    # Process individual messages instead of conversations
    python -m apps.imessage_rag --no-concatenate-conversations
    
    # Limit processing for testing
    python -m apps.imessage_rag --max-items 100 --query "weekend"
    

    Once your iMessage conversations are indexed, you can search with queries like:

    • "What did we discuss about vacation plans?"
    • "Find messages about restaurant recommendations"
    • "Show me conversations with John about the project"
    • "Search for shared links about technology"
    • "Find group chat discussions about weekend events"
    • "What did mom say about the family gathering?"

    MCP Integration: RAG on Live Data from Any Platform

    Web documents: Search and fetch with Parallel Search MCP without an API key: python -m apps.parallel_rag searches, indexes, and answers in one command, or export Markdown for leann build.

    Connect to live data sources through the Model Context Protocol (MCP). LEANN now supports real-time RAG on platforms like Slack, Twitter, and more through standardized MCP servers.

    Key Benefits:

    • Live Data Access: Fetch real-time data without manual exports
    • Standardized Protocol: Use any MCP-compatible server
    • Easy Extension: Add new platforms with minimal code
    • Secure Access: MCP servers handle authentication
    💬 Slack Messages: Search Your Team Conversations

    Transform your Slack workspace into a searchable knowledge base! Find discussions, decisions, and shared knowledge across all your channels.

    # Test MCP server connection
    python -m apps.slack_rag --mcp-server "slack-mcp-server" --test-connection
    
    # Index and search Slack messages
    python -m apps.slack_rag \
      --mcp-server "slack-mcp-server" \
      --workspace-name "my-team" \
      --channels general dev-team random \
      --query "What did we decide about the product launch?"
    

    📖 Comprehensive Setup Guide: For detailed setup instructions, troubleshooting common issues (like "users cache is not ready yet"), and advanced configuration options, see our Slack Setup Guide.

    Quick Setup:

    1. Install a Slack MCP server (e.g., npm install -g slack-mcp-server)
    2. Create a Slack App and get API credentials (see detailed guide above)
    3. Set environment variables:
      export SLACK_BOT_TOKEN="xoxb-your-bot-token"
      export SLACK_APP_TOKEN="xapp-your-app-token"  # Optional
      
    4. Test connection with --test-connection flag

    Arguments:

    • --mcp-server: Command to start the Slack MCP server
    • --workspace-name: Slack workspace name for organization
    • --channels: Specific channels to index (optional)
    • --concatenate-conversations: Group messages by channel (default: true)
    • --max-messages-per-channel: Limit messages per channel (default: 100)
    • --max-retries: Maximum retries for cache sync issues (default: 5)
    • --retry-delay: Initial delay between retries in seconds (default: 2.0)
    🐦 Twitter Bookmarks: Your Personal Tweet Library

    Search through your Twitter bookmarks! Find that perfect article, thread, or insight you saved for later.

    # Test MCP server connection
    python -m apps.twitter_rag --mcp-server "twitter-mcp-server" --test-connection
    
    # Index and search Twitter bookmarks
    python -m apps.twitter_rag \
      --mcp-server "twitter-mcp-server" \
      --max-bookmarks 1000 \
      --query "What AI articles did I bookmark about machine learning?"
    

    Setup Requirements:

    1. Install a Twitter MCP server (e.g., npm install -g twitter-mcp-server)
    2. Get Twitter API credentials:
      • Apply for a Twitter Developer Account at developer.twitter.com
      • Create a new app in the Twitter Developer Portal
      • Generate API keys and access tokens with "Read" permissions
      • For bookmarks access, you may need Twitter API v2 with appropriate scopes
      export TWITTER_API_KEY="your-api-key"
      export TWITTER_API_SECRET="your-api-secret"
      export TWITTER_ACCESS_TOKEN="your-access-token"
      export TWITTER_ACCESS_TOKEN_SECRET="your-access-token-secret"
      
    3. Test connection with --test-connection flag

    Arguments:

    • --mcp-server: Command to start the Twitter MCP server
    • --username: Filter bookmarks by username (optional)
    • --max-bookmarks: Maximum bookmarks to fetch (default: 1000)
    • --no-tweet-content: Exclude tweet content, only metadata
    • --no-metadata: Exclude engagement metadata

    Slack Queries:

    • "What did the team discuss about the project deadline?"
    • "Find messages about the new feature launch"
    • "Show me conversations about budget planning"
    • "What decisions were made in the dev-team channel?"

    Twitter Queries:

    • "What AI articles did I bookmark last month?"
    • "Find tweets about machine learning techniques"
    • "Show me bookmarked threads about startup advice"
    • "What Python tutorials did I save?"

    Want to use MCP data with regular LEANN CLI? You can combine MCP apps with CLI commands:

    # Step 1: Use MCP app to fetch and index data
    python -m apps.slack_rag --mcp-server "slack-mcp-server" --workspace-name "my-team"
    
    # Step 2: The data is now indexed and available via CLI
    leann search slack_messages "project deadline"
    leann ask slack_messages "What decisions were made about the product launch?"
    
    # Same for Twitter bookmarks
    python -m apps.twitter_rag --mcp-server "twitter-mcp-server"
    leann search twitter_bookmarks "machine learning articles"
    

    MCP vs Manual Export:

    • MCP: Live data, automatic updates, requires server setup
    • Manual Export: One-time setup, works offline, requires manual data export

    Want to add support for other platforms? LEANN's MCP integration is designed for easy extension:

    1. Find or create an MCP server for your platform
    2. Create a reader class following the pattern in apps/slack_data/slack_mcp_reader.py
    3. Create a RAG application following the pattern in apps/slack_rag.py
    4. Test and contribute back to the community!

    Popular MCP servers to explore:

    • GitHub repositories and issues
    • Discord messages
    • Notion pages
    • Google Drive documents
    • And many more in the MCP ecosystem!

    🚀 Claude Code Integration: Transform Your Development Workflow!

    LEANN features intelligent code chunking that preserves semantic boundaries (functions, classes, methods) for Python, Java, C#, and TypeScript, improving code understanding compared to text-based chunking.

    📖 Read the AST Chunking Guide →

    The future of code assistance is here. Transform your development workflow with LEANN's native MCP integration for Claude Code. Index your entire codebase and get intelligent code assistance directly in your IDE.

    Key features:

    • 🔍 Semantic code search across your entire project, fully local index and lightweight
    • 🧠 AST-aware chunking preserves code structure (functions, classes)
    • 📚 Context-aware assistance for debugging and development
    • 🚀 Zero-config setup with automatic language detection
    # Install LEANN globally for MCP integration
    uv tool install leann-core --with leann
    claude mcp add --scope user leann-server -- leann_mcp
    # Setup is automatic - just start using Claude Code!
    

    Try our fully agentic pipeline with auto query rewriting, semantic search planning, and more:

    LEANN MCP Integration

    🔥 Ready to supercharge your coding? Complete Setup Guide →

    Command Line Interface

    LEANN includes a powerful CLI for document processing and search. Perfect for quick document indexing and interactive chat.

    Installation

    If you followed the Quick Start, leann is already installed in your virtual environment:

    source .venv/bin/activate
    leann --help
    

    To make it globally available:

    # Install the LEANN CLI globally using uv tool
    uv tool install leann-core --with leann
    
    
    # Now you can use leann from anywhere without activating venv
    leann --help
    

    Note: Global installation is required for Claude Code integration. The leann_mcp server depends on the globally available leann command.

    Usage Examples

    # build from a specific directory, and my_docs is the index name(Here you can also build from multiple dict or multiple files)
    leann build my-docs --docs ./your_documents
    
    # Search your documents
    leann search my-docs "machine learning concepts"
    
    # Interactive chat with your documents
    leann ask my-docs --interactive
    
    # Ask a single question (non-interactive)
    leann ask my-docs "Where are prompts configured?"
    
    # Detect file changes since last build/watch checkpoint
    leann watch my-docs
    
    # List all your indexes
    leann list
    
    # Remove an index
    leann remove my-docs
    

    Key CLI features:

    • Auto-detects document formats (PDF, TXT, MD, DOCX, PPTX + code files)
    • 🧠 AST-aware chunking for Python, Java, C#, TypeScript files
    • Smart text chunking with overlap for all other content
    • 📂 File change detection via Merkle tree snapshots (leann watch)
    • Multiple LLM providers (Ollama, OpenAI, HuggingFace)
    • Organized index storage in .leann/indexes/ (project-local)
    • Support for advanced search parameters

    You can use leann --help, or leann build --help, leann search --help, leann watch --help, leann ask --help, leann list --help, leann remove --help to get the complete CLI reference.

    Build Command:

    leann build INDEX_NAME --docs DIRECTORY|FILE [DIRECTORY|FILE ...] [OPTIONS]
    
    Options:
      --backend {hnsw,diskann}     Backend to use (default: hnsw)
      --embedding-model MODEL      Embedding model (default: facebook/contriever)
      --graph-degree N             Graph degree (default: 32)
      --complexity N               Build complexity (default: 64)
      --force                      Force rebuild existing index
      --compact / --no-compact     Use compact storage (default: true). Must be `no-compact` for `no-recompute` build.
      --recompute / --no-recompute Enable recomputation (default: true)
    

    Search Command:

    leann search INDEX_NAME QUERY [OPTIONS]
    
    Options:
      --top-k N                     Number of results (default: 5)
      --complexity N                Search complexity (default: 64)
      --recompute / --no-recompute  Enable/disable embedding recomputation (default: enabled). Should not do a `no-recompute` search in a `recompute` build.
      --pruning-strategy {global,local,proportional}
    

    Watch Command:

    leann watch INDEX_NAME
    
    # Compares the current file system state against the last checkpoint (Merkle tree snapshot)
    # and reports which files have been added, removed, or modified, along with their chunk IDs.
    #
    # - Automatically saves a new checkpoint after detecting changes
    # - Each subsequent run compares against the most recent checkpoint
    # - File change detection uses SHA-256 content hashing via a Merkle tree
    #
    # Example output:
    #   === Changes since last checkpoint ===
    #   modified (1):
    #     - /path/to/file.py
    #       chunks: 42, 43, 44
    

    Ask Command:

    leann ask INDEX_NAME [OPTIONS]
    
    Options:
      --llm {ollama,openai,hf,anthropic}    LLM provider (default: ollama)
      --model MODEL                         Model name (default: qwen3:8b)
      --interactive                         Interactive chat mode
      --top-k N                             Retrieval count (default: 20)
    

    List Command:

    leann list
    
    # Lists all indexes across all projects with status indicators:
    # ✅ - Index is complete and ready to use
    # ❌ - Index is incomplete or corrupted
    # 📁 - CLI-created index (in .leann/indexes/)
    # 📄 - App-created index (*.leann.meta.json files)
    

    Remove Command:

    leann remove INDEX_NAME [OPTIONS]
    
    Options:
      --force, -f    Force removal without confirmation
    
    # Smart removal: automatically finds and safely removes indexes
    # - Shows all matching indexes across projects
    # - Requires confirmation for cross-project removal
    # - Interactive selection when multiple matches found
    # - Supports both CLI and app-created indexes
    

    🚀 Advanced Features

    🎯 Metadata Filtering

    LEANN supports a simple metadata filtering system to enable sophisticated use cases like document filtering by date/type, code search by file extension, and content management based on custom criteria.

    # Add metadata during indexing
    builder.add_text(
        "def authenticate_user(token): ...",
        metadata={"file_extension": ".py", "lines_of_code": 25}
    )
    
    # Search with filters
    results = searcher.search(
        query="authentication function",
        metadata_filters={
            "file_extension": {"==": ".py"},
            "lines_of_code": {"<": 100}
        }
    )
    

    Supported operators: ==, !=, <, <=, >, >=, in, not_in, contains, starts_with, ends_with, is_true, is_false

    📖 Complete Metadata filtering guide →

    🔍 Grep Search

    For exact text matching instead of semantic search, use the use_grep parameter:

    # Exact text search
    results = searcher.search("banana‑crocodile", use_grep=True, top_k=1)
    

    Use cases: Finding specific code patterns, error messages, function names, or exact phrases where semantic similarity isn't needed.

    📖 Complete grep search guide →

    🏗️ Architecture & How It Works

    The magic: Most vector DBs store every single embedding (expensive). LEANN stores a pruned graph structure (cheap) and recomputes embeddings only when needed (fast).

    Core techniques:

    • Graph-based selective recomputation: Only compute embeddings for nodes in the search path
    • High-degree preserving pruning: Keep important "hub" nodes while removing redundant connections
    • Dynamic batching: Efficiently batch embedding computations for GPU utilization
    • Two-level search: Smart graph traversal that prioritizes promising nodes

    Backends:

    • HNSW (default): Ideal for most datasets with maximum storage savings through full recomputation
    • DiskANN: Advanced option with superior search performance, using PQ-based graph traversal with real-time reranking for the best speed-accuracy trade-off

    Benchmarks

    DiskANN vs HNSW Performance Comparison → - Compare search performance between both backends

    Simple Example: Compare LEANN vs FAISS → - See storage savings in action

    📊 Storage Comparison

    SystemDPR (2.1M)Wiki (60M)Chat (400K)Email (780K)Browser (38K)
    Traditional vector database (e.g., FAISS)3.8 GB201 GB1.8 GB2.4 GB130 MB
    LEANN324 MB6 GB64 MB79 MB6.4 MB
    Savings91%97%97%97%95%

    Reproduce Our Results

    uv run benchmarks/run_evaluation.py    # Will auto-download evaluation data and run benchmarks
    uv run benchmarks/run_evaluation.py benchmarks/data/indices/rpj_wiki/rpj_wiki --num-queries 2000    # After downloading data, you can run the benchmark with our biggest index
    

    The evaluation script downloads data automatically on first run. The last three results were tested with partial personal data, and you can reproduce them with your own data!

    🔬 Paper

    If you find Leann useful, please cite:

    LEANN: A Low-Storage Vector Index

    @misc{wang2025leannlowstoragevectorindex,
          title={LEANN: A Low-Storage Vector Index},
          author={Yichuan Wang and Shu Liu and Zhifei Li and Yongji Wu and Ziming Mao and Yilong Zhao and Xiao Yan and Zhiying Xu and Yang Zhou and Ion Stoica and Sewon Min and Matei Zaharia and Joseph E. Gonzalez},
          year={2025},
          eprint={2506.08276},
          archivePrefix={arXiv},
          primaryClass={cs.DB},
          url={https://arxiv.org/abs/2506.08276},
    }
    

    ✨ Detailed Features →

    🤝 CONTRIBUTING →

    ❓ FAQ →

    📈 Roadmap →

    📄 License

    MIT License - see LICENSE for details.

    🙏 Acknowledgments

    Core Contributors: Yichuan Wang & Zhifei Li.

    Active Contributors: Gabriel Dehan, Aakash Suresh

    We welcome more contributors! Feel free to open issues or submit PRs.

    This work is done at Berkeley Sky Computing Lab.

    Star History

    Star History Chart

    🤖 Explore LEANN with AI

    LEANN is indexed on DeepWiki, so you can ask questions to LLMs using Deep Research to explore the codebase and get help to add new features.