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

Aaryan Kapoor, Md Abdullah Al Hafiz Khan

Kennesaw State University

Published September 1, 2026 · on the feed September 3, 2026 · ▲ 6 · arXiv 2609.01865

Retrieval, memory & searchCode & software No code arXiv ↗Hugging Face ↗Dataset ↗

The 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.

The Brief

2:48

A short podcast summary of the paper. Written and voiced by AI.

Transcript

ExecRetrieval. Measuring the Functional-Correctness Gap in Code-Embedding Retrieval. By Aaryan Kapoor and one other, from Kennesaw State University. Published on the first of September. No code repository is linked to it.

Embedding-based code retrieval sits at the core of coding agents and of retrieval-augmented code generation. In that setting, retrieving correct code matters more than retrieving code that is lexically similar. Existing code-retrieval benchmarks, though, do not plant controlled near misses in the search pool: variants of each query's canonical implementation that differ by a single edit, with execution confirming they are wrong. So one question goes unanswered in a retrieval setting. Can embeddings functionally tell correct code apart from a near clone that is incorrect?

Answering it requires a benchmark whose search pool itself holds the relevant counterfactuals: buggy variants, verified by execution, that are nearly identical to each canonical solution. With those in place, a retriever's rank ordering can be tested directly for functional discrimination, rather than for topical overlap or for recognising the same code it has seen. The scores reported are exec at ten and exec at one, which, as their names suggest, look at the top ten results and at the single first result. The gap between those two cutoffs is where the story of the benchmark lives.

ExecRetrieval contains nine hundred and thirty-nine Python tasks. Each is paired with one canonical implementation verified by execution, and with up to four buggy distractors, also verified by execution. Every distractor is generated by a mechanical mutation that makes one targeted edit. So the wrong answers in the pool are as close to the right one as a single change allows, and execution, not appearance, is what separates them.

The evaluation covers twenty-three dense embedding configurations plus BM25, each invoked the way its provider natively invokes it. The statistics use paired McNemar tests and bootstrap intervals at the level of individual queries.

With near-clone counterfactuals in the pool, the top hosted system reaches an exec at ten of one point zero zero. Its exec at one is only zero point three three one. Across the four leading systems, when the first-ranked result is a miss, it is a paired buggy variant between ninety-one point five and ninety-nine point four percent of the time.

Looked at from the canonical side, the correct implementation scores below at least one of its own four paired distractors in sixty-seven to seventy-eight percent of queries on the leading systems.

The distance between those two numbers for the top system is the gap in the title. Within the top ten, the correct code was always found. In first place, a broken twin usually took the spot. A retriever can look nearly perfect by the looser measure and still mostly hand back the wrong version of the function. The full dataset, the execution oracle, the embedding matrices, an environment snapshot and the pairwise statistical tests are all released.

Paper Quest · 7 chapters · about 40 min

Play this paper

Learn it by doing: make the calls the authors made, guess the result before you see it, and defend it in a viva graded on your own words. Chapter 1 is right here.

Chapter 1 🧩 · The problem

Lookalike code is everywhere. The question is whether your retriever can tell.

You build a coding agent that retrieves code by embedding similarity before it writes. Retrieving correct code matters more than retrieving code that merely looks alike.

The road ahead

  1. 1 · The problem ~6 min A coding agent needs working code, but no retrieval benchmark yet tests whether embeddings tell working code from a lookalike broken by one edit.
  2. 2 · What came before ~3 min
  3. 3 · The key idea ~9 min Embeddings find correct code within their top ten but rarely rank it first; the winner is usually its own one-edit broken copy.
  4. 4 · Choose your own research ~3 min
  5. 5 · Build the method ~8 min Write correct code per task, mutate it with single edits, confirm by tests, rank the pool with each embedder, then compare them with paired tests.
  6. 6 · The experiment ~6 min You’ll guess: The top hosted system finds a correct implementation somewhere in its top ten for every query. How often is its very first result correct?
  7. 7 · The viva ~5 min Three questions from the examiners, answered in your own words. Win it for the paper’s trophy.
Join free to play the whole quest ›

Free, with Google or an email address. Your stars and progress are kept.

KipQuest: the day’s AI research, as podcasts and quests. All papers Android app Privacy Contact Episodes are written and voiced by AI from each paper. Summaries can contain mistakes: the paper is the source.