向量检索赢BM25,赢在评测
编程助手用 grep 搜代码就够用,可榜单上向量检索总把 BM25 甩在后面。这篇把差距拆开看:一部分来自评测本身偏心——把文件切碎再喂给 BM25、把改过的测试也算相关;另一部分来自查询里缺了代码里的稀有标识符。他们造了个更贴近真实的仓库级基准,覆盖六种语言、2022 到 2026 年的 PR,结果让 LLM 先写出查询里缺的标识符再交给 BM25,提升远大于向量检索,在 Python 各池里追平,连模型发布后才开的 PR 也一样。他们试过的办法都没法预测某条查询谁会赢。对写代码的人,结论很直接:别默认向量检索更强,先给词法检索一个公平的基线,再把两路结果融合。
📄 原文摘要(英文)
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.