← All AI Engineer talks

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.

Slide titled “The Assumption” compares a red box showing 45,000 tokens per query with a green box showing approximately 5,000, connected by an arrow.
The context gap: 45,000 tokens sent per query versus approximately 5,000 useful tokens.
0:010:15
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

0:01 · section reference included

Why shorter answers were not enough

Their first three experiments targeted the model’s response rather than the process assembling its input.

AttemptWhy it fell short
Ask for only relevant codeThe context had already been sent before the model read that instruction.
Change maximum output tokens or temperatureThese controls affected the response, not which files entered the request.
Request shorter answersOutput 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.

1:492:07
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:49 · section reference included

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:

  1. 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.
  2. Retrieve through two searches. Run semantic and keyword searches concurrently, then combine their results.
  3. 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.
  4. Follow code relationships. Track which functions call which, so a retrieved function can lead to connected code.
  5. 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.

Five connected boxes show Tree-sitter Chunking, Hybrid Retrieval, Chunk Compression, Code Graph, and Confidence Scoring. A footer states that everything runs locally using SQLite files.
Five stages of the local retrieval layer, from Tree-sitter chunking to confidence scoring.
3:203:34
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

3:20 · section reference included

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:

score=0.50×semantic score+0.30×keyword score+0.20×recency score\begin{aligned} \text{score} &= 0.50 \times \text{semantic score} \\ &\quad + 0.30 \times \text{keyword score} \\ &\quad + 0.20 \times \text{recency score} \end{aligned}

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.

5:315:45
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

5:31 · section reference included

What the FastAPI benchmark measured

The published FastAPI benchmark covers 53 files and 20 developer questions. Raj presents rounded context counts:

Context strategyTokens per question
Full-file baselineAbout 83,000
Retrieved codeAbout 4,900
Retrieved code with compression523

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.

6:346:53
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

6:34 · section reference included

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.

Slide titled “What we're honest about” has four panels: “94% is against full-file reads,” “Monorepos dilute recall,” “Embedding model matters,” and “What actually worked.” The presenter inset overlaps part of the lower-right panel.
Tradeoffs include the full-file baseline, reduced recall in monorepos, and embedding-model choices.
7:227:37
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

7:22 · section reference included

One index across tools and sessions

The team’s workflow spans several assistants: Claude Code for hard problems, Cursor for quick edits and Copilot for small completions. Without shared context, each tool starts over, and the developer explains the same repository repeatedly. Connecting them to one index gives them a common search layer and the same retrieval results.

Persistent memory extends that arrangement beyond source search. When one tool learns something about the project, the knowledge remains available to another tool in a later session. The index supplies code; memory preserves accumulated project context. Together they reduce both repeated retrieval setup and repeated explanations by the developer.

8:368:51
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

8:36 · section reference included

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.

9:299:41
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

9:29 · section reference included

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.

Closing slide says the biggest optimization in AI coding is context, with an installation command, “94%,” “local,” and “MIT” labels, plus a “Try it now” panel containing a QR code and repository link.
The closing slide emphasizes context optimization and invites viewers to try the open-source tool.
10:0610:25
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

10:06 · section reference included

Resources

From the talk

Read the complete timestamped transcript
  1. 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.

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

  3. 0:31

    Most of the money was not the AI thinking. Most of it was

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

  5. 0:57

    In this talk is about what we built and what we learned.

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

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

  8. 1:38

    It's, um... that's like, uh, ordering a pizza and paying for extra nine pizzas you don't eat every time.

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

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

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

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

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

  14. 3:13

    Same math, but different result. Fix the input. That's where your money goes.

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

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

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

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

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

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

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

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

  23. 5:23

    Together, they miss about one in ten. They fix each other weakness spots.

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

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

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

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

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

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

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

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

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

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

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

  35. 8:24

    Small database instead of big infrastructure. Two searches instead of one fancy one. Local instead of cloud. Simple one.

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

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

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

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

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

  41. 10:00

    Run it on your project for a week. See your own number.

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

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

  44. 10:38

    Tell us what you saved. Thanks. Happy coding.