UC Berkeley发布LEANN:开源向量索引将60M数据压缩至6GB
Meet LEANN: An Open-Source Vector Index that Shrinks a 60M-Chunk RAG Index from 201 GB to 6 GB
RAG基础设施的重大优化,让个人电脑也能跑大规模语义搜索,做本地Agent的同学值得收藏压测。
UC Berkeley’s Sky Computing Lab built LEANN, an open-source vector index that stores almost no embeddings. The LEANN vector index recomputes embeddings at query time instead of saving them to disk. The repo benchmark shows a 60 million chunk Wikipedia index dropping from 201 GB to 6 GB. The research paper won the Best Research Paper award at MLSys 2026. So, it brings semantic search and RAG over personal data, on a laptop.
UC Berkeley 的 Sky Computing Lab 构建了 LEANN,这是一个开源向量索引,几乎不存储任何嵌入向量。LEANN 向量索引在查询时重新计算嵌入向量,而不是将其保存到磁盘。仓库基准测试显示,6000 万分块的维基百科索引从 201 GB 降至 6 GB。该研究论文获得了 MLSys 2026 最佳研究论文奖。因此,它使得在笔记本电脑上对个人数据进行语义搜索和 RAG(检索增强生成)成为可能。
TL;DR
TL;DR(太长不看版)
- Size: 6 GB for 60M chunks (repo); 4 GB in the paper’s 76 GB Wikipedia setup. Default embedder: Contriever (110M params). It is an index, not an LLM, so no context length applies.
- Runs on: laptops and workstations. The paper tested an RTX 4090 box with 32 GB RAM and an M1 Ultra Mac. A CPU-only Linux install exists, with no published CPU latency.
- Performance: matches HNSW downstream accuracy at 90% recall, using under 5% of raw-data storage.
- Best: 25.5% NQ accuracy, identical to HNSW, using 4 GB instead of 188 GB.
- Worst: HotpotQA retrieval takes 44.80 s on the Mac, 50.1% of total pipeline time.
- 大小:6000 万分块为 6 GB(仓库);论文中的 76 GB 维基百科设置为 4 GB。默认嵌入器:Contriever(1.1 亿参数)。它是一个索引,而非大语言模型(LLM),因此不适用上下文长度限制。
- 运行环境:笔记本电脑和工作站。论文测试了配备 RTX 4090、32 GB 内存的 PC 以及 M1 Ultra Mac。存在仅 CPU 的 Linux 安装版本,但未公布 CPU 延迟数据。
- 性能:在召回率为 90% 时,其下游准确率与 HNSW 相当,且使用的存储空间不到原始数据的 5%。
- 最佳表现:NQ 准确率达到 25.5%,与 HNSW 相同,但仅使用 4 GB 而非 188 GB。
- 最差表现:在 Mac 上,HotpotQA 检索耗时 44.80 秒,占总流水线时间的 50.1%。
What is LEANN?
什么是 LEANN?
LEANN is a low-storage approximate nearest neighbor (ANN) index built on top of FAISS. It targets one problem: vector indexes are often bigger than the data they index. The research paper shows a 76 GB corpus needs 173 GB of embeddings plus a 15 GB HNSW graph. That more than doubles the raw data.
LEANN 是一个基于 FAISS 构建的低存储近似最近邻(ANN)索引。它旨在解决一个问题:向量索引通常比它们索引的数据还要大。研究论文显示,一个 76 GB 的语料库需要 173 GB 的嵌入向量加上一个 15 GB 的 HNSW 图结构。这使原始数据量翻了一倍多。
LEANN keeps a pruned graph, drops the full vectors, and rebuilds them on demand. The code is MIT licensed and installs with uv pip install leann.
LEANN 保留修剪后的图结构,丢弃完整向量,并在需要时重建它们。代码采用 MIT 许可证,可通过 uv pip install leann 安装。
How does LEANN recompute embeddings without stalling search?
LEANN 如何在不停滞搜索的情况下重新计算嵌入向量?
Graph indexes like HNSW visit only a small set of nodes per query. LEANN exploits that. It stores the graph plus a compact product quantization (PQ) table. At query time, it re-embeds only nodes on the search path.
像 HNSW 这样的图索引每次查询只访问少量节点。LEANN 利用了这一点。它存储图结构以及一个紧凑的产品量化(PQ)表。在查询时,它仅对搜索路径上的节点进行重新嵌入。
3 techniques keep this practical:
三种技术使其具有实用性:
- Two-level search: cheap PQ distances rank neighbors first. Only top candidates get exact recomputation.
- Dynamic batching: candidates from several hops are grouped, for example 64 at once, for GPU efficiency.
- High-degree preserving pruning: most nodes keep few edges, while the top 2% “hub” nodes keep more.
- 两级搜索:低成本 PQ 距离首先对邻居进行排序。只有顶级候选者才会进行精确重新计算。
- 动态批处理:来自多个跳数的候选者被分组,例如一次 64 个,以提高 GPU 效率。
- 保留高连接度节点的修剪:大多数节点保持较少的边,而前 2% 的“枢纽”节点则保留更多边。
In ablations, two-level search gives an average 1.4x speedup. Adding batching raises it to 1.8x. Embedding recomputation still accounts for about 76% of query latency.
在消融实验中,两级搜索带来了平均 1.4 倍的加速。加入批处理后提升至 1.8 倍。嵌入向量的重新计算仍占查询延迟的约 76%。
How does LEANN perform on benchmarks?
LEANN 在基准测试中表现如何?
The research team tested NQ, TriviaQA, GPQA and HotpotQA against a 60M-passage RPJ-Wiki datastore. Latency is measured at 90% Recall@3. All figures below are self-reported in the research paper.
研究团队针对包含 6000 万段落的 RPJ-Wiki 数据存储,对 NQ、TriviaQA、GPQA 和 HotpotQA 进行了测试。延迟以 Recall@3 为 90% 时测量。以下所有数据均为研究论文中自报的结果。
On NQ, with Qwen3-4B on an RTX 4090, LEANN and HNSW both reach 25.5% downstream accuracy. LEANN uses 4 GB of storage. HNSW uses 188 GB. BM25 scores 18.3%, and PQ compression scores 17.9%.
在 NQ 数据集上,使用 RTX 4090 运行 Qwen3-4B 模型时,LEANN 和 HNSW 均达到 25.5% 的下游准确率。LEANN 占用 4 GB 存储空间,而 HNSW 占用 188 GB。BM25 得分为 18.3%,PQ 压缩得分为 17.9%。
The cost is search time. LEANN retrieval takes 2.48 s on NQ, versus 0.05 s for HNSW. Generation takes about 20 s, so end-to-end latency rises from 20.95 s to 23.34 s.
成本在于搜索时间。在 NQ 数据集上,LEANN 检索耗时 2.48 秒,而 HNSW 仅需 0.05 秒。生成过程耗时约 20 秒,因此端到端延迟从 20.95 秒增加至 23.34 秒。
Across datasets on the RTX 4090, LEANN retrieval ranges from 1.12 s (GPQA) to 7.12 s (HotpotQA). The IVF-based recomputation baseline, inspired by EdgeRAG, is up to 200x slower. LEANN improves exact match by up to 11.8% over BM25.
在 RTX 4090 上的各数据集中,LEANN 检索时间范围为 1.12 秒(GPQA)至 7.12 秒(HotpotQA)。受 EdgeRAG 启发的基于 IVF 的重计算基线方法速度最高慢 200 倍。与 BM25 相比,LEANN 将精确匹配率提高了高达 11.8%。
The GitHub repo reports similar savings on personal data. 400K chat messages shrink from 1.8 GB to 64 MB. 38K browser entries shrink from 130 MB to 6.4 MB.
GitHub 仓库报告了类似的个人数据节省效果:40 万条聊天记录从 1.8 GB 缩减至 64 MB;3.8 万条浏览器记录从 130 MB 缩减至 6.4 MB。
LEANN vs other vector indexes
LEANN 与其他向量索引的对比
| Feature | LEANN | HNSW (FAISS) | DiskANN | IVF-Recompute (EdgeRAG-style) | PQ compression |
|---|---|---|---|---|---|
| Approach | Pruned graph, recompute on demand | Graph plus all vectors in RAM | Graph and vectors on SSD, PQ in RAM | IVF clusters, recompute on demand | Compressed vectors plus graph |
| Storage, 76 GB corpus | 4 GB | 188 GB | 270 GB | Below 5% of raw data | 20 GB |
| NQ retrieval at 90% recall (RTX 4090) | 2.48 s | 0.05 s | 0.03 s | 307.61 s | Fails to reach 90% |
| HotpotQA retrieval at 90% recall (RTX 4090) | 7.12 s | 0.05 s | 0.11 s | 429.46 s | Fails to reach 90% |
| NQ downstream accuracy (Qwen3-4B) | 25.5% | 25.5% | Not disclosed | Not disclosed | 17.9% |
| Fits 32 GB RAM workstation | Yes | No (OOM) | Yes | Yes | Yes |
| License | MIT | MIT | MIT | Not disclosed | Varies by implementation |
| 特性 | LEANN | HNSW (FAISS) | DiskANN | IVF-Recompute (EdgeRAG 风格) | PQ 压缩 |
|---|---|---|---|---|---|
| 方法 | 剪枝图,按需重计算 | 图结构加上 RAM 中的所有向量 | SSD 上的图和向量,RAM 中的 PQ | IVF 聚类,按需重计算 | 压缩向量加上图 |
| 存储,76 GB 语料库 | 4 GB | 188 GB | 270 GB | 低于原始数据的 5% | 20 GB |
| NQ 召回率 90% 时的检索时间 (RTX 4090) | 2.48 s | 0.05 s | 0.03 s | 307.61 s | 无法达到 90% |
| HotpotQA 召回率 90% 时的检索时间 (RTX 4090) | 7.12 s | 0.05 s | 0.11 s | 429.46 s | 无法达到 90% |
| NQ 下游准确率 (Qwen3-4B) | 25.5% | 25.5% | 未披露 | 未披露 | 17.9% |
| 适配 32 GB RAM 工作站 | 是 | 否 (OOM) | 是 | 是 | 是 |
| 许可证 | MIT | MIT | MIT | 未披露 | 因实现而异 |
Storage, latency and accuracy figures come from the LEANN paper v2, Tables 1 and 2 and Section 7.2 (self-reported). License and design rows link to each project’s own source.
存储、延迟和准确率数据来自 LEANN 论文 v2 版(自报),包括表 1、表 2 和第 7.2 节。许可证和设计行链接指向各项目自身的源代码。
Where can developers use LEANN?
开发者可以在哪里使用 LEANN?
The repo ships ready apps for documents, Apple Mail, Chrome history, WeChat, iMessage, and ChatGPT or Claude exports. MCP readers pull live data from Slack and Twitter bookmarks. LEANN also runs as a semantic search MCP server for Claude Code.
该仓库提供了适用于文档、Apple Mail、Chrome 历史记录、微信、iMessage 以及 ChatGPT 或 Claude 导出的现成应用。MCP 阅读器可从 Slack 和 Twitter 书签中拉取实时数据。LEANN 还可作为 Claude Code 的语义搜索 MCP 服务器运行。
On 30 SWE-Bench Pro tasks from ContextBench, the team reports 24.2% initial relevant-code recall versus 11.4% for BM25. The agent also used 8.4% fewer tokens.
在 ContextBench 的 30 个 SWE-Bench Pro 任务中,团队报告的初始相关代码召回率为 24.2%,而 BM25 仅为 11.4%。智能体还减少了 8.4% 的 token 使用量。
HNSW is the default backend, with DiskANN for faster search. Generation works with Ollama, Hugging Face, Anthropic, or any OpenAI-compatible API. It supports Ubuntu, Arch, WSL, macOS and Windows. Some apps, like Apple Mail search, are macOS only.
HNSW 是默认后端,DiskANN 用于加速搜索。生成模块支持 Ollama、Hugging Face、Anthropic 或任何 OpenAI 兼容 API。系统支持 Ubuntu、Arch、WSL、macOS 和 Windows。部分应用(如 Apple Mail 搜索)仅限 macOS。
Key Takeaways
关键要点
- LEANN stores a pruned graph and recomputes embeddings at query time.
- 60M chunks: 201 GB down to 6 GB in the repo benchmark.
- Matches HNSW accuracy (25.5% on NQ) at 90% recall.
- Search costs seconds: 2.48 s vs 0.05 s for HNSW on NQ.
- MIT licensed and an MLSys 2026 Best Research Paper.
- LEANN 存储一个剪枝图,并在查询时重新计算嵌入向量。
- 60M chunks:在仓库基准测试中,从 201 GB 降至 6 GB。
- 在 90% 召回率下,匹配 HNSW 的准确率(NQ 上为 25.5%)。
- 搜索耗时仅数秒:在 NQ 上,HNSW 需 2.48 秒,而本方法仅需 0.05 秒。
- 采用 MIT 许可证,并荣获 MLSys 2026 最佳研究论文奖。
Check out the Paper, GitHub Repo and PyPI package. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.
查看论文、GitHub 仓库和 PyPI 包。也欢迎在 Twitter 上关注我们,别忘了加入我们有 15 万+成员的 ML SubReddit,并订阅我们的新闻通讯。等等!你在 Telegram 上吗?现在你也可以加入我们的 Telegram 群组。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力