# LEANN

> Tiny-footprint vector database for private, on-device RAG over your own data

- Category: Retrieval & Knowledge (RAG) / RAG Frameworks & Platforms
- Language: Python
- Licence: MIT
- Repository: https://github.com/StarTrail-org/LEANN
- Website: https://arxiv.org/abs/2506.08276
- Canonical page: https://ai-tldr.dev/tools/leann/

## In short

LEANN is an open-source vector database built for running RAG (retrieval-augmented generation) on your own machine. It lets a laptop index and search across millions of documents while keeping everything local, so your data never leaves your device and there are no cloud costs. It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed MIT.

## Overview

LEANN is an open-source vector database built for running RAG (retrieval-augmented generation) on your own machine. It lets a laptop index and search across millions of documents while keeping everything local, so your data never leaves your device and there are no cloud costs.

Its main trick is storage savings: instead of saving every embedding, LEANN uses graph-based selective recomputation with graph pruning to compute embeddings on demand. The project reports up to 97% less storage than traditional vector databases without losing search accuracy, and it can connect to many LLM providers including Ollama, OpenAI, Anthropic, HuggingFace, and other OpenAI-compatible endpoints.

## What it does

- Graph-based selective recomputation computes embeddings on demand, cutting index storage by up to 97% with no reported accuracy loss
- Simple declarative Python API with LeannBuilder, LeannSearcher, and LeannChat for building, searching, and chatting with an index
- Command-line tools (leann build, search, ask, list, remove, watch) with auto-detection of formats like PDF, TXT, MD, DOCX, and code files
- Connects to many LLM and embedding providers, including local engines (Ollama, LM Studio, vLLM, llama.cpp) and cloud APIs via OpenAI-compatible endpoints
- RAG over personal data sources such as the file system, Apple Mail, browser history, WeChat, iMessage, and ChatGPT or Claude conversations
- Native MCP integration that adds semantic search to Claude Code and pulls live data from platforms like Slack and Twitter

## Getting started

LEANN installs from PyPI and uses uv for environment management. After installing it, you can build an index from your documents and query it from Python or the command line.

1. Install LEANN

   Create a virtual environment with uv and install the package from PyPI.

```bash
uv venv
source .venv/bin/activate
uv pip install leann
```

2. Build, search, and chat in Python

   Use the declarative API to build an index, run a semantic search, and ask questions over your data.

```python
from leann import LeannBuilder, LeannSearcher, LeannChat
from pathlib import Path
INDEX_PATH = str(Path("./").resolve() / "demo.leann")

builder = LeannBuilder(backend_name="hnsw")
builder.add_text("LEANN saves 97% storage compared to traditional vector databases.")
builder.build_index(INDEX_PATH)

searcher = LeannSearcher(INDEX_PATH)
results = searcher.search("storage savings", top_k=1)

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)
```

3. Use the command line

   Build an index from a folder of documents, then search or ask questions against it.

```bash
leann build my-docs --docs ./your_documents
leann search my-docs "machine learning concepts"
leann ask my-docs --interactive
```

4. Manage your indexes

   List the indexes you have built and remove ones you no longer need.

```bash
leann list
leann remove my-docs
```

## When to use it

- Build a private RAG assistant on your laptop that semantic-searches your files, emails, browser history, and chat archives without sending data to the cloud
- Index very large document collections on limited storage, where saving full embeddings would be too big or would crash a traditional vector database
- Add semantic search to Claude Code through LEANN's MCP service, so an agent can retrieve relevant context instead of relying only on keyword grep
- Connect a local LLM such as Ollama to your indexed knowledge base for fully offline question answering over personal or team data
