Embeddings vs. Grep: Rethinking the Dense Advantage in Code Search
Siqiao Xue, Ziyin Zhang, Zihan Liao, Jin Qin, Yixiang Mu, Hang Yu
Key points
From the paper's conclusion- Our experiments trace the advantage to two sources: evaluation choices that favor dense retrieval, such as splitting files into chunks for BM25 and counting edited tests as relevant, and queries that lack the code's rare identifiers.
Abstract
Code-search benchmarks show dense encoders well ahead of BM25, yet coding agents do well with \texttt{grep}. What does this dense advantage measure? Existing benchmarks cannot tell: they use curated queries, old code and a handicapped BM25. To find out, we build Repo-Premium, a realistic repository-level code-search benchmark. It ranks files in real repositories, with curated and raw queries in Python, JavaScript, TypeScript, Go, Rust and Java, pull requests from 2022 to 2026, and a preregistered test pool over $91$ repositories. Our experiments trace the advantage to two sources: evaluation choices that favor dense retrieval, such as splitting files into chunks for BM25 and counting edited tests as relevant, and queries that lack the code's rare identifiers. Expanding the query with LLM-written identifiers (generate-then-grep) helps BM25 far more than dense retrieval, letting it match dense retrieval in every Python pool, even on pull requests opened after the LLM was released. No method we tried predicts which retriever will win on a given query. From these results we derive three guidelines: measure dense gains against a fair lexical baseline, fuse dense retrieval with BM25, and add the code's words to queries that lack them.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Better Call Grep: Evaluating and Improving Grep-Like Lexical Retrieval for Repository-Level Code CompletionProceedings of the ACM on Software Engineering · 2026
- MAP4CS: A Multi-dimensional Data Pruning Framework for Efficient Code Retriever Fine-tuningarXiv · 2026
- Code Comprehensor: Hierarchical Documentation and Cross-Modal Retrieval for Large RepositoriesarXiv · 2026
- Which Code Changes Need Re-embedding? CIPBench and the Limits of Multi-Signal Index MaintenancearXiv · 2026
- Projecting BrowseComp-Plus onto ClimbMix: Toward More Realistic Corpora for Agentic SearcharXiv · 2026
- CompLit: Scientific Literature Search Benchmarks Must Cover Implicit, Cumulative, and Unmet NeedsarXiv · 2026