Real software tasks are not single functions. A bug report names a symptom, and the model must find the files that matter among thousands before it can write a patch. Retrieval is the first stage of nearly every agent that works on a repository (Jimenez and co-authors, 2024, built a benchmark of this kind; Yang and co-authors, 2024, describe an agent that navigates a repository with tools). We implement the classical ingredient, BM25 (Robertson and Spärck Jones, 1976; Robertson and Zaragoza, 2009), copied in a reduced dictionary-based form from Volume 1, Chapter 4, and study one design decision that is specific to code: how to tokenize.
Real software tasks are not single functions. A bug report names a symptom, and the model must find the files that matter among thousands before it can write a patch. Retrieval is the first stage of nearly every agent that works on a repository (Jimenez and co-authors, 2024, built a benchmark of this kind; Yang and co-authors, 2024, describe an agent that navigates a repository with tools). We implement the classical ingredient, BM25 (Robertson and Spärck Jones, 1976; Robertson and Zaragoza, 2009), copied in a reduced dictionary-based form from Volume 1, the companion book, and study one design decision that is specific to code: how to tokenize.
A function’s text contains identifiers such as parse_config_lines or parseConfigLines. A whole-word tokenizer treats each as one token that never equals the word “config” in a bug report. A code-aware tokenizer splits identifiers at underscores, case changes and digits.
The synthetic repository has 200 functions with unique three-word names (half snake_case, half camelCase) and short docstrings that repeat only some of the name’s words. Each issue contains the name words with probability 0.8 each (at least two), two random nouns and three filler words. This is a toy; it is built so that the identifiers carry the signal, which exaggerates the effect.
With whole-word tokens the true function is first in 0.015 of the issues, in the top five in 0.090 and in the top ten in 0.175 (MRR 0.081): nearly all the signal sits inside identifiers, which the tokenizer cannot see, and the docstring words alone are too few. With identifiers split, recall at one, three, five and ten is 0.580, 0.805, 0.895 and 0.975 (MRR 0.714). The paired difference in recall at five is 0.805 with a 95% bootstrap interval of 0.750 to 0.860. The size of that difference is a property of my construction. The direction, that tokenization that matches how code is written beats tokenization that does not, is the transferable point.
The last block couples retrieval to the code model under an assumption I flag as hypothetical: relevant context multiplies the odds of a correct program by 3 and irrelevant context by 0.5. Under it, pass@1 would move from 0.4133 with no retrieval to 0.5740 with oracle context. With split identifiers and the top three results it would be 0.5226 (recall 0.805), and with the top five 0.5463; with whole-word tokens it would fall to 0.3288 and 0.3340, below the no-retrieval baseline, because retrieval that is usually wrong costs more than it gives. Recall at is the number that matters, and also the number of retrieved results, since longer context raises cost, which is the cost model of the companion book example again.
Continue with the book
Explore the full treatment, worked examples, and exercises in Applied AI for Generation and Control.
Companion article for Applied AI for Generation and Control, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
