← All papers
First page of Lean Finder V2: Semantic Search for Mathlib That Disambiguates User Queries

Lean Finder V2: Semantic Search for Mathlib That Disambiguates User Queries

Jialin Lu, Xiaoyu Liu, Hengrui Luo, Rodrigo Stehling, Linxi Liu, Weiran Sun, Yuepeng Wang, Wuyang Chen

cs.LG Oct 22, 2026 · v2 cs.IR
Builds a semantic search engine over Mathlib declarations, trained with adversarially generated ambiguous queries, and tests it on Lean theorem proving with Claude Code.
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/

Mathematicians and coding agents usually search Mathlib with short, ambiguous queries: properties, notation, aliases or hypotheses. Existing Mathlib search engines assume context-rich queries, and labeled short queries paired with Mathlib statements are scarce.

A Qwen3-4B query generator is trained with RL plus SFT. Its reward combines retriever-guided difficulty with an LLM judge's check that each query stays faithful to its source declaration, so it produces challenging but correct short queries for Mathlib declarations. These query-declaration pairs fine-tune a Qwen3-Embedding-8B retriever by contrastive learning, over two alternating generator-retriever rounds. The same synthetic pairs are reused to optimize a query-rewriting prompt with GEPA.

Figure 2: Lean Finder V2 disambiguates Mathlib queries at two complementary levels. Model-level adversarial training (Section 3.1 ) uses a hybrid objective that combines reinforcement learning and supervised fine-tuning with retriever-guided difficulty rewards to incentivize the query generator LLM to generate faithful, challenging, and ambiguous queries for Mathlib declarations. Contrastive learn

On the 810-query MathlibQR benchmark, Lean Finder V2 reaches nDCG@1 of 0.558 and Recall@10 of 0.893, at least an 11% relative improvement over the previous best Mathlib search engines. LLM judges rank it best on unlabeled real-world human and coding-agent queries. Used as a tool for Claude Code, it gives the highest theorem-proving pass rate, 39.3%.

SystemnDCG@1nDCG@10Recall@10
LeanSearch V2 (retriever+reranker)0.4700.6230.780
Claude Code (Sonnet 5)0.5270.6410.747
Lean Finder0.3700.5330.698
Lean Finder V20.5580.7320.893
MathlibQR retrieval (selected systems)
Retrieval toolPass rate (%)
No semantic retrieval tool34.0 ± 1.0
LeanExplore27.3 ± 0.6
Lean Finder30.7 ± 1.2
LeanSearch V2 (retriever+reranker)36.0 ± 1.0
Lean Finder V239.3 ± 1.2
Claude Code theorem-proving pass rate by retrieval tool