Embeddings vs. Grep: Rethinking the Dense Advantage in Code Search
Siqiao Xue, Ziyin Zhang, Zihan Liao, Jin Qin, Yixiang Mu, Hang Yu
Ant Group
Published November 16, 2026 · on the feed November 20, 2026 · ▲ 11 · arXiv 2611.20455
The 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.
The Brief
2:21A short podcast summary of the paper. Written and voiced by AI.
Transcript
Embeddings vs. Grep. Rethinking the Dense Advantage in Code Search. By Siqiao Xue and five others, from Ant Group. Published on the sixteenth of November.
Code-search benchmarks show dense encoders well ahead of BM25, yet coding agents do well with plain grep. The authors ask what that dense advantage is actually measuring, and their answer is that a large part of it comes from how the evaluation is set up and from what the queries leave out. Existing benchmarks cannot settle the question on their own, because they use curated queries, old code and a handicapped BM25.
To find out, the authors build Repo-Premium, a realistic repository-level code-search benchmark. It ranks files in real repositories, with both curated and raw queries, in Python, JavaScript, TypeScript, Go, Rust and Java. It draws on pull requests dating from two thousand twenty-two through to two thousand twenty-six, and it has a preregistered test pool over ninety-one repositories. Each of those choices answers one of the weaknesses just named. Raw queries stand beside curated ones, recent code stands beside old, and the lexical side of the comparison is given a fair chance rather than a handicapped one.
Experiments trace the advantage to two sources. One is evaluation choices that favour dense retrieval, such as splitting files into chunks for BM25 and counting edited tests as relevant. The other is queries that lack the code's rare identifiers. Expanding a query with identifiers written by an LLM, an approach called generate-then-grep, helps BM25 far more than it helps dense retrieval. With it, BM25 matches dense retrieval in every Python pool, even on pull requests opened after the LLM was released.
The result has edges. The match with dense retrieval is reported for every Python pool specifically, so the strongest version of the claim is tied to that language. The post-release pull requests matter here, since they show the gain from generate-then-grep is not simply the LLM recalling code it saw before. And no method the authors tried predicts which retriever will win on a given query, so the finding describes how the two compare across pools, not a rule for choosing between them search by search.
Three guidelines follow from the results. Measure dense gains against a fair lexical baseline. Fuse dense retrieval with BM25. And add the code's words to queries that lack them. Taken together, they recast much of the gap between embeddings and grep as a matter of vocabulary and of how the comparison was arranged, which also makes sense of why agents get so far with grep.
More with an account
Listen to every day’s papers
Daily playlists, deep dives, quests for the papers, and quizzes on their key terms.
Join free