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
在最新榜 #428 本站收录于 2026-11-24
一句话要点
代码搜索基准往往显示稠密编码器明显领先于 BM25,但编程智能体使用 grep 也能取得良好效果。这种稠密优势究竟在衡量什么?现有基准无法回答:它们使用经过整理的查询、较旧的代码,以及对 BM25 不利的设置。为此,作者构建了面向真实仓库级代码搜索的基准 Repo-Premium:在真实代码仓库中对文件排序,查询既包括整理后的也包括原始查询,覆盖 Python、JavaScript、TypeScript、Go、Rust 和 Java,拉取请求时间为 2022 年至 2026 年,并在 91 个仓库上预登记了测试池。实验将稠密优势追溯到两个来源:有利于稠密检索的评测选择,例如把文件切成块再交给 BM25,以及把被编辑的测试也计为相关;以及查询中缺少代码里的稀有标识符。用大语言模型写出标识符来扩展查询(先生成再 grep)对 BM25 的帮助远大于对稠密检索的帮助,使 BM25 在每一个 Python 测试池上都能与稠密检索持平,即便是在该大语言模型发布之后才发起的拉取请求上也是如此。作者尝试过的方法都无法预测给定查询上哪一种检索器会胜出。据此提出三条原则:相对公平的词法基线来衡量稠密检索的增益,将稠密检索与 BM25 融合,以及在缺少代码用词的查询中补上这些词。
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.
要点
- 现有代码搜索基准因使用人工构造查询和老旧代码,无法真实反映稠密编码器的相对优势,存在系统性偏差。
- 研究构建了Repo-Premium基准,包含2022至2026年的真实拉取请求与多语言源码,通过真实场景验证检索方法的有效性。
- 实验表明,将LLM生成的代码标识符融入查询(generate-then-grep)可使传统BM25在多个Python数据集上达到稠密检索水平,甚至优于其在新提交中的表现。
- 研究指出当前评估方式存在偏差,如文件分块处理和测试变更计为相关性,建议未来采用更公平的基线并融合稠密与词向量检索。
English overview
Existing code search benchmarks overestimate dense retrieval performance due to curated queries and biased evaluation settings. Repo-Premium, a realistic benchmark using real repositories and pull requests, reveals that BM25 with LLM-generated identifiers performs comparably to dense methods. The advantage of dense encoding is largely attributed to flawed evaluation practices and query deficiencies, not inherent superiority.
只根据 arXiv 官方摘要,由开源模型整理,经数字/专名自动核对(必须在摘要中出现),以论文原文为准。
阅读 arXiv 原文 PDF Hugging Face 讨论
相关论文
- 同主题 · AgentSWE: Can Coding Agents Build the Agent You Actually Want? 2026-10-09
- 同主题 · Doc2Harness: Benchmarking LLMs on Long-Horizon Harness Engineering of Coding Agents 2026-10-14
- 同期 · InclusionMed: Benchmarking AI for Inclusive Healthcare 2026-11-16
数据说明
元数据来自 arXiv API(已核实);点赞来自 Hugging Face 每日论文;引用来自 Semantic Scholar。最近刷新 2026-11-30。
要点由本站根据摘要自写,不转载摘要原文,请阅读原文。