Lean Finder V2: Semantic Search for Mathlib That Disambiguates User Queries
Organizations: Simon Fraser University · Rice University · University of Pittsburgh
Abstract
We introduce Lean Finder V2, a semantic search framework for Mathlib that disambiguates user queries through complementary model-level adversarial training and input-level query rewriting. Human mathematicians and coding agents rarely search Mathlib by providing detailed context. In practice, they query short properties, notation, aliases, or hypotheses, leaving much of the intended mathematics implicit. In contrast, existing Mathlib search engines unrealistically assume context-rich queries. The scarcity of real-world short queries paired with ground-truth Mathlib statements makes this ambiguity even more intractable. We argue that this is essentially a data problem. Through adversarial training, we scale up the generation of labeled short and ambiguous queries, and learn to disambiguate user queries at both model-level fine-tuning and input-level query rewriting. On the human-curated MathlibQR benchmark, our Lean Finder V2 sets a new state of the art, with at least 11% relative improvement over the previous best Mathlib semantic search engines. On top of our state-of-the-art retriever, optimized query rewriting further improves MathlibQR retrieval. On unlabeled queries from human and coding-agent interactions, Lean Finder V2 is ranked as the strongest system. Integrated with Claude Code, Lean Finder V2 improves proof success on downstream theorem-proving task. Lean Finder V2 is available at: https://leanfinder.github.io/
Figures & tables
| nDCG@ | Recall@ | ||||||
| System | Model size | 1 | 5 | 10 | 10 | 50 | 100 |
| LeanExplore | 109M | 0.246 | 0.358 | 0.393 | 0.569 | 0.743 | 0.789 |
| LeanSearch V2 (retriever-only) | 8B | 0.340 | 0.472 | 0.494 | 0.657 | 0.790 | 0.830 |
| LeanSearch V2 (retriever+reranker) | 8B + 8B | 0.470 | 0.601 | 0.623 | 0.780 | 0.847 | 0.858 |
| Claude Code (Sonnet 5) | – | 0.527 | 0.629 | 0.641 | 0.747 | – | – |
| TheoremGraph | 8B | 0.391 | 0.534 | 0.558 | 0.733 | – | – |
| nDCG@ | Recall@ | |||||
| System | 1 | 5 | 10 | 10 | 50 | 100 |
| LeanExplore | 0.180 | 0.376 | 0.406 | 0.661 | 0.837 | 0.872 |
| LeanSearch V2 (retriever-only) | 0.414 | 0.569 | 0.596 | 0.783 | 0.907 | 0.942 |
| LeanSearch V2 (retriever+reranker) | 0.506 | 0.669 | 0.691 | 0.873 | 0.954 | 0.964 |
| Claude Code (Sonnet 5) | 0.245 | 0.345 | 0.363 | 0.485 | – | – |
| Lean Finder | 0.544 | 0.720 | 0.742 | 0.914 | 0.980 | 0.989 |
| GPT-5.6 Sol | Claude Opus 5 | |||
| System | Mean rank | Rank 1 | Mean rank | Rank 1 |
| LeanExplore | 3.740 | 14 (7.0%) | 3.735 | 8 (4.0%) |
| LeanSearch V2 (retriever+reranker) | 2.380 | 52 (26.0%) | 2.305 | 64 (32.0%) |
| Claude Code (Sonnet 5) | 3.775 | 32 (16.0%) | 3.920 | 22 (11.0%) |
| Lean Finder | 3.125 | 32 (16.0%) | 3.095 | 30 (15.0%) |
| Lean Finder V2 | 1.980 | 70 (35.0%) | 1.945 | 76 (38.0%) |
| nDCG@ | Recall@ | |||||
| Input Rewrite Config. | 1 | 5 | 10 | 10 | 50 | 100 |
| Original query (no rewrite) | ||||||
| LeanSearch augmentation | ||||||
| LeanDex augmentation | ||||||
| GEPA seed rewriting | ||||||
| GEPA-optimized rewriting | ||||||
| Retrieval tool | Pass rate (%) |
| No semantic retrieval tool | |
| LeanExplore | |
| Lean Finder | |
| LeanSearch V2 (retriever+reranker) | |
| Lean Finder V2 |
Appendix figures & tables9 assets
Supplementary material from the paper’s appendix.
Appendix
| Source | Median length | Count | |
| Training data | Informalizations ( Lu et al., 2026 ; Gao et al., 2026 ) | 82 | 309579 |
| Synthetic user queries ( Lu et al., 2026 ) | 34 | 503378 | |
| Our synthetic queries (Round 1) | 15 | 307085 | |
| Our synthetic queries (Round 2) | 14 | 306948 | |
| Real-world & Test queries | MathlibQR ( Gao et al., 2026 ) | 14 | 810 |
| Human queries | 16 | 20000 |
| nDCG@ | Recall@ | |||||
| Configuration | 1 | 5 | 10 | 10 | 50 | 100 |
| Round 0 | 0.463 | 0.590 | 0.611 | 0.760 | 0.864 | 0.901 |
| Round 1 (difficulty only) | 0.453 | 0.575 | 0.602 | 0.762 | 0.870 | 0.919 |
| Round 1 (alignment only) | 0.463 | 0.598 | 0.623 | 0.780 | 0.884 | 0.910 |
| Round 1 (full reward) | 0.520 | 0.657 | 0.682 | 0.842 | 0.925 | 0.951 |
| nDCG@ | Recall@ | |||||
| Configuration | 1 | 5 | 10 | 10 | 50 | 100 |
| Round 0 | 0.563 | 0.720 | 0.743 | 0.910 | 0.967 | 0.981 |
| Round 1 (difficulty only) | 0.530 | 0.689 | 0.711 | 0.879 | 0.956 | 0.975 |
| Round 1 (alignment only) | 0.552 | 0.718 | 0.738 | 0.903 | 0.968 | 0.980 |
| Round 1 (full reward) | 0.569 | 0.728 | 0.743 | 0.916 | 0.985 | 0.993 |
| nDCG@ | Recall@ | |||||
| Round | 1 | 5 | 10 | 10 | 50 | 100 |
| Round 0 | 0.463 | 0.590 | 0.611 | 0.760 | 0.864 | 0.901 |
| Frozen base-generator control | ||||||
| Round 1 | 0.472 | 0.603 | 0.628 | 0.791 | 0.895 | 0.921 |
| Round 2 | 0.469 | 0.597 | 0.620 | 0.789 | 0.898 | 0.919 |
| Expert-query SFT-generator control | ||||||
| nDCG@ | Recall@ | |||||
| Round | 1 | 5 | 10 | 10 | 50 | 100 |
| Round 0 | 0.563 | 0.720 | 0.743 | 0.910 | 0.967 | 0.981 |
| Frozen base-generator control | ||||||
| Round 1 | 0.559 | 0.710 | 0.729 | 0.894 | 0.967 | 0.981 |
| Round 2 | 0.552 | 0.705 | 0.725 | 0.890 | 0.965 | 0.981 |
| Expert-query SFT-generator control | ||||||
| Judge | Agreements | Agreement (%) |
| GPT-5.6 Sol | 738/810 | 91.11 |
| Claude Opus 5 | 745/810 | 91.98 |
| nDCG@ | Recall@ | |||||
| System | 1 | 5 | 10 | 10 | 50 | 100 |
| LeanExplore | 0.246 | 0.358 | 0.393 | 0.569 | 0.743 | 0.789 |
| LeanSearch V2 (retriever-only) | 0.340 | 0.472 | 0.494 | 0.657 | 0.790 | 0.830 |
| LeanSearch V2 (retriever+reranker) | 0.470 | 0.601 | 0.623 | 0.780 | 0.847 | 0.858 |
| Claude Code (Sonnet 5) | 0.527 | 0.629 | 0.641 | 0.747 | – | – |
| Lean Finder | 0.370 | 0.514 | 0.533 | 0.698 | 0.824 | 0.875 |
| nDCG@ | Recall@ | |||||
| System | 1 | 5 | 10 | 10 | 50 | 100 |
| LeanExplore | 0.180 | 0.376 | 0.406 | 0.661 | 0.837 | 0.872 |
| LeanSearch V2 (retriever-only) | 0.414 | 0.569 | 0.596 | 0.783 | 0.907 | 0.942 |
| LeanSearch V2 (retriever+reranker) | 0.506 | 0.669 | 0.691 | 0.873 | 0.954 | 0.964 |
| Claude Code (Sonnet 5) | 0.245 | 0.345 | 0.363 | 0.485 | – | – |
| Lean Finder | 0.544 | 0.720 | 0.742 | 0.914 | 0.980 | 0.989 |
| System | Retrieval configuration | Parameters |
| LeanExplore | Retriever | 109M |
| LeanSearch V2 | Retriever only | 8B |
| LeanSearch V2 | Retriever + reranker | 8B + 8B |
| TheoremGraph | Retriever | 8B |
| Lean Finder | Retriever | 7B |
| Lean Finder V2 | Retriever | 8B |
Semantic Search
Semantic search retrieves information by meaning, matching queries and documents even when they use different words.
See all 42 papers