ExecRetrieval:衡量代码嵌入检索中的功能正确性差距

·

研究论文 · 2026/09/03

嵌入代码检索是编码代理和检索增强代码生成的核心组件,检索正确代码比检索词法相似代码更重要。现有基准未在搜索池中植入经过执行验证的单一编辑变体,无法测试嵌入能否在功能上区分正确代码与近似克隆但有缺陷的代码。为此,我们提出ExecRetrieval,包含939个Python任务,每个任务配有一个执行验证的标准实现和最多四个执行验证的有缺陷干扰项,每个干扰项通过单一目标编辑生成。我们评估了23种密集嵌入配置及BM25,使用配对McNemar检验和查询级自助法区间。结果显示,在近克隆反事实存在时,顶级托管系统exec@10=1.00但exec@1=0.331;排名第一的遗漏中,配对缺陷变体占91.5-99.4%,且标准实现在67-78%的查询中得分低于至少一个干扰项。数据集、执行预言机、嵌入矩阵、环境快照和统计检验已发布。

该论文提出了一个新颖的基准ExecRetrieval,专门测试代码检索模型的功能正确性区分能力,填补了现有基准的空白。实验结果揭示了当前嵌入模型在检索正确代码方面的显著不足,对改进代码检索和生成系统具有重要指导意义。

Embedding-based code retrieval is a core component of coding agents and retrieval-augmented code generation, where retrieving correct code matters more than retrieving lexically similar code. Existing code-retrieval benchmarks do not plant controlled, execution-verified single-edit variants of each query's canonical implementation in the search pool, leaving the question of whether embeddings can functionally discriminate correct from near-clone-but-incorrect code unanswered in a retrieval setting. Resolving this requires a benchmark whose search pool itself contains the relevant counterfactuals -- execution-verified buggy variants near-identical to each canonical -- so that a retriever's rank ordering can be directly tested for functional discrimination rather than topical or identity overlap. We introduce ExecRetrieval, 939 Python tasks each paired with one execution-verified canonical implementation and up to four execution-verified buggy distractors, each generated by a mechanical mutation making a single targeted edit, and evaluate 23 dense embedding configurations plus BM25 under provider-native invocation with paired McNemar tests and query-level bootstrap intervals. With near-clone counterfactuals in the pool, the top hosted system reaches exec@10 = 1.00 but only exec@1 = 0.331; rank-1 misses are paired buggy variants 91.5-99.4% of the time across the four leading systems, and the canonical scores below at least one of its four paired distractors in 67-78% of queries on the leading systems. The full dataset, execution oracle, embedding matrices, environment snapshot, and pairwise statistical tests are released at the URL in Appendix D.

阅读原文

参与讨论