arXiv:2609.01865cs.SESep 2026

Manuscript Offprint

arXiv:2609.01865

ExecRetrieval: Measuring the Functional-Correctness Gap in Code-Embedding Retrieval

Aaryan Kapoor, Md Abdullah Al Hafiz Khan

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

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.

1 Introduction

Embedding-based retrieval is becoming central to practical software engineering: coding assistants retrieve snippets from local repositories and the wider

open-source corpus to ground their suggestions (Zhang et al., 2023; Wang et al., 2025); IDEs use embeddings to locate prior occurrences of a function; and retrieval-augmented generation pipelines for code (Lewis et al., 2020; Zhang et al., 2023) rely on embeddings to surface relevant context. In all of these settings, the embedding model serves as the candidate-recall stage of a longer pipeline: correctness is ultimately checked downstream by reranking, execution, tests, or agentic post-processing, but the first-stage ranking determines which candidates those later stages ever see, and in what order. What has not been measured is how much of the correctness-discrimination work this first stage passes on to the rest of the system when a near-identical buggy variant of the correct implementation sits in the search pool.

There is a measurement gap. The axis we care about — whether the retriever surfaces an implementation that actually passes a test suite when a near-identical buggy variant is one cosine-similarity step away — is not isolated as a controlled measurement anywhere. Public code-retrieval benchmarks score against canonical identity and topical similarity on found code: CodeSearchNet (Husain et al., 2019), CodeXGLUE (Lu et al., 2021), CoSQA (Huang et al., 2021), CoIR (Li et al., 2025a), and CodeRAG-Bench (Wang et al., 2025) all operate above this axis. None of them pair every canonical with controlled single-edit buggy variants in the search pool, so a perfect topical retriever and a perfect functional retriever score identically on them, even though the two notions disagree on the cases that matter for downstream code use.

This paper isolates the functional-correctness gap. Figure 1 shows a concrete instance: for the query lowest_set_bit, the strongest hosted embedder ranks three execution-failing buggy variants above the canonical implementation, which passes all of its tests yet lands only at rank 4. Con-

Figure

Figure 1: EXECREtrieval in one figure (query q_0348, lowest_set_bit). The five paired snippets occupy the top-5 retrieval slots under Gemini Embedding 2 (best of 24 systems); the canonical lands at rank 4 because three buggy variants embed closer to the query. Across all 939 queries, the best embedder reaches exec@10=1.000 yet exec@1=0.331; rank-1 misses are paired buggy variants 91.5–99.4% of the time across the four leading systems.

cretely, we ask: when each natural-language query in a code-retrieval benchmark has both a canonical implementation and several near-identical buggy variants in the search pool, can modern embedding models still place a passing implementation at the top of the ranking? Every magnitude we report is conditional on that premise — a near-clone candidate present in the pool — not an estimate of how often deployed corpora pose this choice; Section 5.3 measures how the gap scales with density, and Limitations states the scope.

Closing this gap requires a benchmark with four properties: (i) for each query, a search pool containing both a known-correct implementation and a small set of near-identical buggy variants; (ii) correctness verified by execution against a deterministic test suite, not by human labelling; (iii) coverage across enough algorithmic domains and mutation archetypes that failure modes cannot be attributed to a single domain or bug pattern; and (iv) per-query paired statistics, so that retrievers are compared on the same inputs rather than on aggregate scores. We refer to a benchmark satisfying these as functionally grounded code retrieval; EXECREtrieval is one instantiation.