Lean Finder is a semantic search engine for Lean and mathlib that understands and aligns with the intents of mathematicians. The model can be accessed at delta-lab-ai/lean-finder.
This repository provides the code to reproduce the results in the paper and self-host the retrieval service: download the precomputed FAISS indices, load the model, and serve queries over HTTP. Multiple mathlib versions are supported out of the box (currently v4.19.0, v4.24.0, and v4.28.0).
The easiest way to use Lean Finder is through our hosted web service:
No setup required. Use this if your workload is light or interactive.
If you have a heavy workload (batch retrieval, integration with a prover, large-scale evaluation), host the model yourself with the code in this repository.
git clone https://github.com/delta-lab-ai/lean-finder.git
cd lean-finder
pip install -r requirements.txtHardware. A single GPU with at least 16GB of VRAM is required to run the model.
For each supported mathlib version, the server needs two files: a JSONL corpus (the actual declarations) and a FAISS index (precomputed embeddings of that corpus). Both are hosted on the Hugging Face model repo and are downloaded with a single command:
python download_corpus.pyThis populates data/ with the corpus files (mathlib4_19_0.jsonl, mathlib4_24_0.jsonl, mathlib4_28_0.jsonl) and the matching FAISS indices (mathlib4_19_0.index, mathlib4_24_0.index, mathlib4_28_0.index). This step is required — the corpus JSONLs are too large to ship in the git repo, so you must fetch them from Hugging Face before starting the server.
If you want to search over a different corpus — your own project, a different mathlib snapshot, or a private library — encode it yourself with build_index.py. Your input JSONL must follow the same schema as our mathlib corpora (one JSON object per line with path, kind, name, typeFull, informal_name, informal_description, docString fields — inspect any of the downloaded data/mathlib4_*.jsonl files for examples).
python build_index.py \
--inputs path/to/your_corpus.jsonl \
--outputs path/to/your_corpus.index \
--devices cuda:0 \
--batch_size 32You can pass multiple --inputs/--outputs pairs together with one --devices entry per input to embed several corpora in parallel.
python server.pyOn first launch the server downloads the model from delta-lab-ai/lean-finder, loads it onto GPU, and loads every FAISS index into memory. Once you see Handler ready — accepting requests, the service is up at http://localhost:8000.
Useful flags:
python server.py --model-dir delta-lab-ai/lean-finder --data-dir data --port 8000A minimal client is provided in client_example.py:
python client_example.pyOr use it as a library:
from client_example import search
results = search(
"Terminal Objects are Zero Objects",
top_k=5,
version="v4.28.0",
)
for r in results:
print(r["score"], r["formal_name"], r["path"])The HTTP API is small and easy to call from any language:
| Method | Endpoint | Body |
|---|---|---|
| POST | /search |
{"inputs": <query>, "top_k": <int>, "version": <version>} |
| GET | /health |
— |
| GET | /versions |
— |
Each search result includes score, formal_name, informal_name, kind, type, informal_description, and path.
Lean Finder ships indices for multiple mathlib versions so you can search against the snapshot that matches your project:
| Version | Index file | Corpus file |
|---|---|---|
v4.19.0 |
mathlib4_19_0.index |
mathlib4_19_0.jsonl |
v4.24.0 |
mathlib4_24_0.index |
mathlib4_24_0.jsonl |
v4.28.0 |
mathlib4_28_0.index |
mathlib4_28_0.jsonl |
Pass version in the request body to choose. Default is v4.28.0.
The model loaded by server.py (delta-lab-ai/lean-finder, main revision) is a newly updated and optimized version that is significantly stronger than the model described in the original paper. On our internal evaluations it shows substantial improvements in retrieval quality. We recommend this version for all practical use.
Full evaluation details for the updated model will be released soon.
If you want to reproduce the results in the paper, use the original model and code in the lean-finder-original folder — see its README for instructions. For any other use, we do not recommend the original model.
@article{lu2025lean,
title={Lean finder: Semantic search for mathlib that understands user intents},
author={Lu, Jialin and Emond, Kye and Yang, Kaiyu and Chaudhuri, Swarat and Sun, Weiran and Chen, Wuyang},
journal={arXiv preprint arXiv:2510.15940},
year={2025}
}Apache 2.0.
This project builds on the following open-source projects and datasets for Lean:
We thank the authors and maintainers of these projects.
