Abstract
Code-search benchmarks show dense encoders well ahead of BM25, yet coding agents do well with 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.
Community
Code-search benchmarks show dense encoders well ahead of BM25, yet coding agents do well with 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.
Thank you for running the extra post hoc analysis. Depth-50 fusion lifting the 186 hard queries from 0.152 (dense) to 0.188, and bringing a relevant file into the top 10 on 8 of the 82 shared failures, is a useful detail. Do you expect that gain to hold if the dense side is a stronger retriever than the one used here?
The finding that the dense advantage shrinks once BM25 gets a fair setup, without chunked files and with queries that carry the code's rare identifiers, is a useful correction. Generate-then-grep matching dense retrieval in the Python pools fits how coding agents seem to work in practice. Did fusing dense retrieval with BM25 beat both on the queries where neither did well alone?
Hi,
Yes, when we let fusion look deeper into both rankings.
Section 5.3, Table 3 (https://arxiv.org/html/2611.20455v1#S5.SS3) reports the overall result: across 539 lockbox queries, fusing the top 10 results from each retriever reached 0.551 nDCG@10, ahead of dense retrieval (0.533) and BM25 (0.432).
To answer your more specific question, we ran an additional post hoc analysis of the cached rankings. We grouped queries by their original standalone scores, then compared fusion using up to 10 or 50 candidates from each retriever. Both configurations score the final top 10.
| Original standalone scores | Queries | Dense | BM25 | Fusion: depth 10 | Fusion: depth 50 |
|---|---|---|---|---|---|
| Both below 0.50 | 186 | 0.152 | 0.122 | 0.163 | 0.188 |
| Both below 0.25 | 111 | 0.040 | 0.030 | 0.039 | 0.071 |
| Both zero | 82 | 0 | 0 | 0 | 0.027 |
Scores are mean nDCG@10; the subsets overlap.
Depth-50 fusion outperformed both standalone retrievers on average within these difficult subsets. Its gains over dense were +0.036 for the below-0.50 subset and +0.031 for the below-0.25 subset, with repository-clustered 95% bootstrap intervals excluding zero in both cases.
For the 82 queries where neither retriever put a relevant file in its top 10, depth-10 fusion had no relevant file to promote. With deeper candidate lists, fusion brought at least one relevant file into the final top 10 on 8 of those 82 queries.
The distinction is between helping shared difficult queries and maximizing the overall average: depth-50 fusion helped more on these difficult subsets, while depth-10 fusion scored higher across the full lockbox—0.551 versus 0.536. These exploratory results show that deeper fusion can rescue some shared failures, even though it was not the better setting overall.
This is an automated message from the Librarian Bot. I found the following papers similar to this paper.
The following papers were recommended by the Semantic Scholar API
- Skip the Compressor: Coding Agents Fix More Issues When They Pick Whole Files (2026)
- RAGCompass: Generalizable Retriever Routing via Reranking (2026)
- SAG2: Embedding-Free Multi-Hop Retrieval with BM25 and Decision Models (2026)
- Small Agents with Semantic Search: Efficient Multilingual Code Localization (2026)
- CARET: Training-Free Test-Time Scaling for Repository-Level Code Completion (2026)
- Evaluating Name-Only Directory Routing for One-Shot Code Search (2026)
- From the Zoo to the BULLPEN: Sample-Efficient LLM Profiling via Multi-Channel Model Embeddings (2026)
Please give a thumbs up to this comment if you found it helpful!
If you want recommendations for any Paper on Hugging Face checkout this Space
You can directly ask Librarian Bot for paper recommendations by tagging it in a comment: @librarian-bot recommend
This matches what I see directing coding agents day to day: grep works when you already know the repo's vocabulary, and falls short when you describe what you want in your own words. Generate-then-grep states that cleanly. The model guesses the names the codebase uses, then lexical search does the rest. Two questions. Does the benefit hold in repos with unusual or inconsistent naming, where the guessed identifiers are more likely to miss? And since nothing predicted which retriever wins on a given query, is fusing both always worth the cost, or is there a kind of query where BM25 alone is enough? The preregistered test pool is good to see.
Does the benefit hold with unusual or inconsistent naming?
We have partial evidence, but have not directly tested repositories selected for unusual naming. We simulated a vocabulary mismatch by replacing rare function/class-name tokens absent from the original query with opaque aliases in the lexical index. The query and frozen generation output stayed unchanged, so guesses using the old names could no longer match.
Population Queries Raw BM25 Generate-then-grep After naming intervention All Python queries 1,265 0.488 0.627 0.622 Queries containing affected generated names 372 0.441 0.613 0.596 Scores are mean nDCG@10. The benefit survived this controlled mismatch, although losing identifier matches reduced performance. This supports resilience to that specific failure mode; robustness to real-world naming inconsistency remains unconfirmed. Other matching terms remained available, and dense retrieval was not evaluated under the naming intervention.
Is fusion always worth the cost, or can BM25 alone be enough?
Fusion is not automatically worthwhile for every workload. On the original 539-query lockbox, we tested serving BM25 alone when its leading result had a sufficiently large relative score margin, otherwise using Jina+BM25 fusion. Thresholds were fixed from development data.
Policy Dense calls avoided nDCG@10 Lost fusion hits¹ Always fuse 0 0.551 0 Conservative lexical-first gate 73 / 539 (13.5%) 0.545 4 Primary lexical-first gate 164 / 539 (30.4%) 0.538 11 BM25 alone 539 / 539 (100%) 0.432 71 ¹ Queries where fusion retrieved a relevant file in the top 10 but the cheaper policy did not.
We can reduce dense calls, but the tested rules trade retrieval quality for those savings. We have not identified a reliable query category where BM25 alone is sufficient. A large score margin is a useful budget heuristic, but still misses some files that fusion finds. Whether the savings justify those misses depends on the application; these figures count query embeddings and dense lookups, excluding index construction and maintenance.
Thanks for the tables, that is more than I expected back. The naming test settles the part I was worried about: 0.613 to 0.596 on the affected queries is a small price for swapping out the rare identifiers. On fusion, the lost-hits column is the useful one. The primary gate skips 30% of the dense calls and loses 11 files that fusion would have found, so the trade is a budget decision and not a free one. If you get to real repos picked for messy naming, I'd read that follow-up.
Get this paper in your agent:
hf papers read 2611.20455 Don't have the latest CLI?
curl -LsSf https://hf.co/cli/install.sh | bash Models citing this paper 0
No model linking this paper
Datasets citing this paper 1
Spaces citing this paper 0
No Space linking this paper