TL;DR
This paper investigates why dense encoders (embeddings) appear to dominate code search benchmarks while simple lexical search (like grep) remains highly effective for real-world coding agents. By building a new, realistic benchmark called REPOPREMIUM, the authors show that the "dense advantage" is largely an artifact of benchmark design—specifically handicapped lexical baselines and queries that lack specific code identifiers—and that a simple "generate-then-grep" strategy allows lexical search to match or beat state-of-the-art embeddings.
What Problem Does This Paper Address?
In the world of AI-assisted coding, there is a weird disconnect. Academic benchmarks consistently show that dense retrievers (neural embeddings) crush traditional lexical methods like BM25. However, practitioners building "SWE-agents" (AI software engineers) often find that simple grep and find are not the bottleneck.
The authors argue that existing benchmarks are "handicapped" in three ways:
- Weak Baselines: They often force BM25 to use the same small text chunks as dense encoders, even though BM25 performs better on whole files.
- Curated Queries: They use clean, docstring-style queries rather than the messy, raw text found in GitHub Issues or Pull Requests (PRs).
- Labeling Bias: They often count edited test files as "relevant," a metric that happens to favor the specific retrieval patterns of dense encoders.
Methods
The authors developed REPOPREMIUM, a benchmark designed to simulate repository-level code search. They compared 13 state-of-the-art dense encoders (like Jina, Qwen, and E5) against BM25 and a literal "grep" baseline.
Key methodological interventions included:
- Generate-then-grep: Using a Large Language Model (LLM) to expand a natural language query with predicted code identifiers (variable names, APIs, file paths) before running a lexical search.
- Fair Baselines: Testing BM25 on whole files versus chunks to see how much the "dense premium" is just a result of poor chunking choices.
- Contamination Testing: Using PRs from 2026 (future-dated relative to the models' training cutoffs) to ensure the models aren't just "remembering" the code they were trained on.
- Hybrid Fusion: Using Reciprocal Rank Fusion (RRF) to combine the strengths of both lexical and dense retrieval.
Datasets
The study introduces REPOPREMIUM, which consists of:
- REPOPREMIUM-CORE: 1,265 queries across 10 Python repositories (from the SWE-bench Verified set). It includes both curated problem statements and raw GitHub PR text from 2022, 2023, and 2026.
- REPOPREMIUM-EXT: An extension set with 1,560 queries covering five more languages (JS, TS, Go, Rust, Java) and 91 additional repositories.
- Gold Labels: Unlike some benchmarks, labels are derived directly from merged PR changes, identifying exactly which files a developer had to edit to solve a task.
Key Insights and Ideas
- The "Dense Premium" is Fragile: Much of the reported advantage of embeddings disappears when you give BM25 whole files to index instead of 1,000-character chunks. Tuning the lexical baseline alone cut the "dense premium" by nearly 75%.
- Lexical Rescue via LLMs: The primary reason embeddings win is that they can handle queries that don't mention specific code tokens. If you use an LLM to "guess" the missing identifiers (the
generate-then-grepapproach), BM25 catches up immediately, even on code the LLM has never seen. - The Test File Distraction: Dense retrievers are significantly more likely to rank test files at the top. If a benchmark considers finding a test file a "win," the dense retriever's score is artificially inflated.
- No Smart Routing: The authors tried to build a "router" to decide which queries should go to BM25 vs. Embeddings. It failed. The two methods win on different types of queries, but there is no clear signal to predict which is which.
Key Results
- Baseline Leveling: Against a "tuned" whole-file BM25, the dense advantage on curated queries dropped from +0.121 to +0.034 nDCG@10.
- LLM Expansion: Adding LLM-written "anchors" (identifiers) to the query helped BM25 far more than it helped dense encoders. In every Python test pool,
generate-then-grepmatched or beat the best dense retrieval. - Robust Fusion: A fixed hybrid fusion (RRF) of dense and lexical search was the most reliable performer, beating either method alone on a 539-query "lockbox" test set.
- Agent Performance: In end-to-end agent tests, the choice of the LLM (the "brain") mattered significantly more for success than the specific search tool (the "eyes") it used.
Limitations and Future Work
- Language Scope: While the extension set covers multiple languages, the deepest analysis is focused on Python.
- Granularity: The benchmark focuses on file-level retrieval. The authors note that function-level or line-level targets remain untested in this framework.
- LLM Dependency: The "generate-then-grep" strategy relies on a high-quality generator. While it worked with Qwen-35B, the effect size varies with the model's strength.
- Future Direction: The authors suggest that instead of building better embedding models, researchers might find more value in improving how agents "draft" their own search queries.
Summary updated