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
Cutting AI coding context with a local code index
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 complete timestamped transcript
- 0:01
Hey, I'm Raj. I want to tell a story. Me and my friend Faz, we are building project together. We are using AI coding tools every day. Claude Code, Cursor, Copilot, Codex, normal stuff.
- 0:15
One month, our AI bill was fine. Next month, huge. We did nothing different. Same project, same tools, just more of it. We panicked. We looked what was happening, and we found something surprising.
- 0:31
Most of the money was not the AI thinking. Most of it was
- 0:39
sending too much context, files the AI don't need. Context is important. Code that was not relevant, sent anyway every time. So me and my friend Faz, we started to building something to fix it.
- 0:57
In this talk is about what we built and what we learned.
- 1:05
Every AI coding tools, uh, does same thing. It send your code to the model as a context, and the tools thinks more context is better. We measure typical query on our project.
- 1:22
It was sending forty-five thousand tokens of context, but the part of actually mattered is about five thousand only. Other forty thousand tokens are not useful, but we paid for them every single query.
- 1:38
It's, um... that's like, uh, ordering a pizza and paying for extra nine pizzas you don't eat every time.
- 1:49
We tried three things, uh, before we found what works. First, we changed our prompt. Be short, only show relevant code. Sounds good, but it does not work. The model already got forty-five thousand tokens before it's read the prompt.
- 2:07
Cost already happened. Second, we change model setting like a max token, temperature, same problem. This changes the output, not the input. Uh, money is in the input. Third, uh, output compression.
- 2:22
This one actually works. We told the model to write short answers. It cut the output seventy-five percentage, but output only, uh, about ten percentage of the cost. So seventy-five percentage of a small number, still small number, not enough.
- 2:42
We need to fix the input. This is the most important slide. Ninety percentage of your AI cost is input, files, search results, context you send in. Only ten percentage is output, the code, uh, the AI writes back.
- 3:00
So if you cut the output by seventy-five percentage, you can save about eight-- eight percentage total. But if you cut input by ninety-four percentage, you can save about sixty-one percentage total.
- 3:13
Same math, but different result. Fix the input. That's where your money goes.
- 3:20
We built a local search layer. It sits between your code base and the AI. Instead of sending whole files, the AI search and index, it gets back only small piece of code actually it needs.
- 3:34
Here how it works, five steps. Step one, we read the code and, uh, break into small pieces, functions, classes, methods, not a random chunks, proper piece that makes sense.
- 3:47
Step two, we run two searches at, at the same time. One search find the code by meaning, one search find the code by exact words, then combine the results.
- 4:00
This is the big saving comes from. Steps three, we can shrink the results even more. Keep only the function name and the description. Cut fifty-line function down to five lines.
- 4:14
Step four, uh, we track the connection with the fa-- which function call which. So if you find one piece of code, you can find everything connected to it. Step five, every results get score.
- 4:29
If the score is too low, we don't send it. No bad context. Everything runs on your machine. Nothing goes to the cloud. This is the beauty.
- 4:40
Why do we run two searches instead of one? Because each one has a weakness. Meaning-based search is good at finding related ideas, but it misses exact names. You search for, um, authenticate user function, and it might show you different auth function instead because they are similar meaning.
- 5:06
The word-based search is good at exact names, but it misses related ideas. You search for login flow, and it misses everything that says sign in. By themself, both searches miss about one in four results.
- 5:23
Together, they miss about one in ten. They fix each other weakness spots.
- 5:31
Here is the hard part Faz and I spend most of the time on. The search finds results, but they actually relevant? Sometimes search results returns ten results, and none of them are right.
- 5:45
If the AI use the bad results, it gives confident wrong answer. The worse than no answer. [chuckles] We tried asking AI to judge its own results. Too slow. Add two, three seconds every time.
- 5:59
We try to fix the score limit. Too simple. Short questions score low even when the match is perfect. It worked. Some simple formula, fifty percentage me-meaning score, thirty percentage keyword score, twenty percentage how the recent code is.
- 6:17
And the limit adjusts based on the current result. It runs, uh, pi-- zero point four milliseconds. No extra AI calls needed. The lesson we learned, simple formula beats the complex model most of the time.
- 6:34
We need numbers, not just stories. So here are ours. We tested an open source, uh, real project, FastAPI, fifty-three files, twenty real questions a developer would ask. Without using our tool, eighty-three, uh, K tokens per questions.
- 6:53
With our tools, uh, four point nine K tokens per questions. That is ninety-four percentage less. With the extra compression on top, uh, five hundred and twenty-three tokens per question.
- 7:06
And the accuracy still, um, find the right code, ninety percentage of the code. These numbers are real. Test is public. You can run it yourself. The command is on screen.
- 7:22
I want to be honest about the limits. The ninety-four percentage, again, the worst case, reading full files every time. In a real life, the tools like a Claude Code already smarter than, uh, that.
- 7:37
Real savings are lower than ninety-four percentage. We use full, uh, file base because it is the only one we can measure the same way every time. Big mixed code base are hard.
- 7:51
We tested on a large product, uh, with, uh, three ninety-six files. The recall dropped almost zero. If your files each do one thing, it works well. If your files do many things, it struggles.
- 8:07
Uh, we use a small fast model for search. It's quick. Re-indexing takes under a second. But the bigger model would, uh, find more, which was speed over perfection. Simple choices work better than complex one.
- 8:24
Small database instead of big infrastructure. Two searches instead of one fancy one. Local instead of cloud. Simple one.
- 8:36
Here is something Foss pointed out early on. We use many tools, Claude Code for hard problems, Cursor for q-quick edits, Copilot for small, uh, completions. Each tools starts, uh, fresh every time.
- 8:51
They do not share ev-anything. You explain the same code base to three different AIs. We built one shared index, so all your tools connect to it. Same search, same results for all of them.
- 9:08
Uh, and we added memory. Uh, when one tools learn something about your project, that knowledge stays. Next session, different tool, same project, the context is already there. We explain the code base once, every tool remembered.
- 9:29
This is the saving report on real project. Two forty-seven queries, twelve point four million tokens saved, nearly one eight six not spent.
- 9:41
Most of the savings, eighty-four percentage, came from search layer. The rest of them, compression. This is not an estimate. The tool tracks every query. It compares what would have been sent against what was sent, then it multiplies by the model price.
- 10:00
Run it on your project for a week. See your own number.
- 10:06
Me and Foss built this because we had a huge bill and no good answer. The answer was not a better model. The answer was sending less. We argue about which model is best, Opus or Sonnet, but the models may be thirty percentage of the cost, but other seventy percentage is what you feed it.
- 10:25
Fix the input. The model choice matters less than you think. One command to try it, CCE. It's free, open source, QR code on screen. Try it. See the number.
- 10:38
Tell us what you saved. Thanks. Happy coding.