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

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

arXiv:2611.20455 · 2026-11-22 공개 · arXiv · PDF

bm25 code-search code-repositories pull-requests llm-generated-queries lexical-baseline retrieval-fusion dense-encoders

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.

한국어 요약

한 줄 요약

코드 검색에서 밀집형 임베딩의 우위가 BM25 기반 검색과 비교 시 평가 조건에 따라 달라진다는 점을 실증적으로 밝힌 연구.

핵심 기여도

핵심 아이디어

기존 코드 검색 벤치마크는 **BM25 기반 검색을 불리하게 평가하는 조건**(예: 파일 분할, 편집된 테스트 파일 제외)을 사용해 밀집형 임베딩의 우위를 과장하고 있었다. 연구팀은 **실제 저장소 환경을 반영한 RepoPremium**을 제안하며, 이는 **파일 단위 라벨링**, **실제 PR 텍스트**, **다양한 언어(6개 언어 포함)**, **91개 저장소로 구성된 preregistered 테스트 풀**을 포함한다.

핵심 통찰은, **쿼리가 코드의 고유 식별자를 포함하지 않을 때 LLM을 사용해 식별자를 생성하고 grep을 활용하는 방식**(generate-then-grep)이 BM25의 성능을 크게 향상시킨다는 점이다. 이는 밀집형 임베딩이 단순히 코드 구조를 더 잘 이해한다고 보는 것보다, **평가 조건과 쿼리 구성에 따라 성능 차이가 발생**한다는 것을 의미한다.

기술적 접근법

주요 결과

의의 및 한계

실용적 활용