Skip to content
English

Switch theme

arXiv 2611.20455 · cs.SE · 2026-11-16

Embeddings vs. Grep: Rethinking the Dense Advantage in Code Search

Siqiao Xue, Ziyin Zhang, Zihan Liao, Jin Qin, Yixiang Mu, Hang Yu

high-quality llm benchmarks

In latest · #428 Added on 2026-11-24

One-line takeaway

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, the authors 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. The 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 the authors tried predicts which retriever will win on a given query. From these results they 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.

代码搜索基准往往显示稠密编码器明显领先于 BM25,但编程智能体使用 grep 也能取得良好效果。这种稠密优势究竟在衡量什么?现有基准无法回答:它们使用经过整理的查询、较旧的代码,以及对 BM25 不利的设置。为此,作者构建了面向真实仓库级代码搜索的基准 Repo-Premium:在真实代码仓库中对文件排序,查询既包括整理后的也包括原始查询,覆盖 Python、JavaScript、TypeScript、Go、Rust 和 Java,拉取请求时间为 2022 年至 2026 年,并在 91 个仓库上预登记了测试池。实验将稠密优势追溯到两个来源:有利于稠密检索的评测选择,例如把文件切成块再交给 BM25,以及把被编辑的测试也计为相关;以及查询中缺少代码里的稀有标识符。用大语言模型写出标识符来扩展查询(先生成再 grep)对 BM25 的帮助远大于对稠密检索的帮助,使 BM25 在每一个 Python 测试池上都能与稠密检索持平,即便是在该大语言模型发布之后才发起的拉取请求上也是如此。作者尝试过的方法都无法预测给定查询上哪一种检索器会胜出。据此提出三条原则:相对公平的词法基线来衡量稠密检索的增益,将稠密检索与 BM25 融合,以及在缺少代码用词的查询中补上这些词。

12HF upvotes
–GitHub stars
0Citations (Semantic Scholar)
29.5Buzz score

Read on arXiv PDF Hugging Face discussion

Related papers

About this data

Metadata from the arXiv API (verified); upvotes from Hugging Face Daily Papers; citations from Semantic Scholar. Last refreshed 2026-11-30.

The takeaway is written by AIMap from the abstract; the abstract itself is not reproduced — read the original.

Data updated: Latest AI papers(UTC+8)