AI Engineer World's Fair 2026
We Cut 94% of Our AI Coding Tokens With a Local Code Index. Here's the Architecture.
Read the talk
We Cut 94% of Our AI Coding Tokens With a Local Code Index. Here's the Architecture.
A local retrieval layer can reduce the code sent to an AI assistant, but its value depends on what it retrieves, what it omits, and how savings are measured.
From a talk by Rajkumar Sakthivel
Before you start: Familiarity with AI coding assistants, tokens and basic code search is sufficient; no retrieval-system background is required.
The bill exposed excess context
Rajkumar Sakthivel and his friend Faz were building a project with Claude Code, Cursor, Copilot and Codex. One month their AI bill was manageable; the next it jumped. They had kept the same project and tools, but used them more. Investigating the increase led them to the code being sent with each request: irrelevant context was traveling alongside the material the model actually needed.
Raj reports that a typical query on their project sent 45,000 context tokens, of which about 5,000 mattered. The other 40,000 tokens were still paid for on each request. His analogy is ordering one pizza and paying for nine extra pizzas that nobody eats. The optimization target was therefore context selection before the model call.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Why shorter answers were not enough
Their first three experiments targeted the model’s response rather than the process assembling its input.
| Attempt | Why it fell short |
|---|---|
| Ask for only relevant code | The context had already been sent before the model read that instruction. |
| Change maximum output tokens or temperature | These controls affected the response, not which files entered the request. |
| Request shorter answers | Output shrank, but input remained the larger expense. |
Raj reports a 75% reduction in output, with output accounting for only about 10% of their stated cost split. That made shorter answers useful but insufficient.
The next slide assigns 90% of cost to input and 10% to output. Under that split, reducing output by 75% saves 7.5% overall—approximately the 8% Raj gives. He also claims that reducing input by 94% saves about 61% overall, but that does not follow from the same assumptions: with unchanged pricing and output, the calculation would be 90% × 94% = 84.6%. The percentages cannot all describe one consistent bill calculation. The architectural conclusion remains useful: reduce unnecessary input before paying to process it.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A five-stage local retrieval layer
The team built a search layer between the repository and the coding assistant. Instead of loading whole files by default, the assistant searches an index and receives selected pieces of code. The architecture has five stages:
- Chunk by code structure. Split source into functions, classes and methods rather than arbitrary text windows. The slide identifies Tree-sitter as the chunking component.
- Retrieve through two searches. Run semantic and keyword searches concurrently, then combine their results.
- Compress when appropriate. Retain a function’s name and description instead of its complete implementation. Raj illustrates this as shrinking a 50-line function to five lines.
- Follow code relationships. Track which functions call which, so a retrieved function can lead to connected code.
- Gate by relevance. Score candidates and withhold results that fall below the acceptance threshold.
The slide shows local SQLite files as the storage layer. Raj’s local-only description applies to indexing and search; the downstream coding assistant can still send selected context to a hosted model.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Two searches cover different mistakes
Semantic search and keyword search fail in complementary ways. A semantic query for an authenticate-user function can retrieve a different authentication function because both express a similar idea. Keyword search has the opposite problem: a query for login flow can miss code described as sign in.
| Search | Useful for | Characteristic miss |
|---|---|---|
| Semantic | Related concepts and alternate wording | The exact function among similar functions |
| Keyword | Names and literal terms | Equivalent concepts with different wording |
Raj reports that either search alone misses roughly one in four results, while their combination misses roughly one in ten. He does not define the evaluation set for these particular rates. The mechanism is clearer than the aggregate number: exact matching protects names, while semantic matching bridges vocabulary.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Rejecting plausible but irrelevant results
Finding candidates does not establish that any candidate is useful. A search can return ten results and still miss the requested code entirely. Feeding those results to a model risks a confident answer grounded in the wrong implementation. The team first tried having AI judge the retrieved results; Raj reports that this added two to three seconds per query.
A fixed score threshold was cheaper but rejected short questions even when their matches were good. The replacement combines three signals:
The acceptance threshold then adjusts to the current result rather than remaining fixed across all questions. The talk supplies the weights but not the normalization or threshold-adjustment rule. Raj reports 0.4 milliseconds for this approach without additional AI calls. That timing needs a narrow distinction: the published benchmark’s 0.4-millisecond figure measures median retrieval latency after warm-up, not the scoring formula in isolation.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
What the FastAPI benchmark measured
The published FastAPI benchmark covers 53 files and 20 developer questions. Raj presents rounded context counts:
| Context strategy | Tokens per question |
|---|---|
| Full-file baseline | About 83,000 |
| Retrieved code | About 4,900 |
| Retrieved code with compression | 523 |
The reported 94% reduction compares retrieved code with the full-file baseline. Compression is a further step after retrieval has already removed most of the context.
Raj describes the retrieval quality as finding the right code 90% of the time and points viewers to a public test command. More precisely, the report’s 0.90 Recall@10 measures mean expected-file coverage among the files represented in ten retrieved chunks. It is not generated-code accuracy or the percentage of answers that are correct. The benchmark implementation makes that distinction explicit; the published results were inspected, not independently rerun.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
The baseline and the repository both matter
The headline comparison uses a deliberately expensive baseline: reading full files every time. Raj chose it because it could be measured consistently, while acknowledging that tools such as Claude Code already select context more intelligently. The 94% figure is not measured savings against normal Claude Code behavior. In the inspected runner, the baseline sums complete files represented by the retrieved chunks; it is not necessarily the entire repository on every request.
Repository structure also changes retrieval quality. Raj reports that recall fell almost to zero on a larger, 396-file project. His practical observation is that files with one responsibility work better than files mixing many responsibilities. That is a useful warning about retrieval dilution, but the talk does not establish file responsibility as an isolated cause.
The search model introduces another tradeoff. The team chose a small, fast model rather than a larger model that might find more relevant code. Raj reports re-indexing in under one second, without specifying the update workload; this should not be read as a promise about initial indexing of any repository. The broader implementation follows the same preference for modest infrastructure: a small database, two complementary searches and local operation.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Measure the context difference per query
For a real project, Raj reports 247 queries, 12.4 million tokens saved and nearly 186 in avoided spending, without specifying the currency. He attributes 84% of the savings to search and the remainder to compression.
The tool records each query, compares the context that would have been sent with the context actually sent, and multiplies the difference by the model price. Although Raj describes this as measured rather than estimated savings, the distinction is between logged token counts and a counterfactual bill: the money figure is a price-based estimate, not demonstrated invoice savings. Its interpretation depends on the baseline, applicable prices and caching treatment. His practical invitation is to run the tool on your own project for a week and inspect your own numbers.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Make context selection part of the workflow
The closing comparison is familiar: developers debate Opus versus Sonnet, while the amount of code supplied to either model can remain unexamined. Raj loosely assigns 30% of cost to model choice and 70% to what users feed it; those figures have no defined relationship to the earlier input/output split. The actionable point is to make context selection an explicit part of the coding workflow, then measure whether it preserves useful retrieval while reducing input.
The free, open-source tool is Code Context Engine, or CCE. Raj closes with a one-command invitation and a QR code. The repository’s current documented entry point is:
sh
uvx --from "code-context-engine[local]" cce init
That is the current installation instruction, rather than a transcription of the historical slide command. Trying it on a real repository makes both sides of the tradeoff visible: how much context is removed, and whether the code needed for the task is still found.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Open-source local code retrieval and memory server, with installation instructions and coding-agent integrations.
Per-query token counts and retrieval metrics for the 53-file FastAPI benchmark, including reproduction instructions.
Further reading
The project's companion explanation of its FastAPI experiment, measurement approach and limitations.
A 396-file Go benchmark showing substantial token reduction alongside poor retrieval recall.
Read the transcript and explore slides
Loading transcript and slides…