Braj Kishore
JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
Say hi

Hiring · Building · Investing

Have a system — or a team —that needs to scale?

info@avyxon.ai

Usually replies within a day · track record here

JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
LinkedInXYouTubeSubstackInstagramThreadsFacebookDiscordGitHubTopmate
© 2026 Braj Kishore · Bengaluru, INThink Big · Start Small · Scale Fast
Agentic engineering
Lesson 08Patterns

Retrieval, honestly

Ask a candidate to design a document-question-answering system and almost all of them reach for a vector database in the first sentence. The interesting answers start somewhere else. So do the ones that survive production.

Lewis et al. named retrieval-augmented generation at NeurIPS 2020. The idea was to pair a model’s parametric memory — what it absorbed during training — with a non-parametric index it can look things up in. Six years on, the architecture in that paper is mostly history. The framing is not.

You are deciding what the model gets to see. That decision sits upstream of everything the model then does.

So the interview question is almost never “what is RAG”. It is why did yours not work. That answer separates the people who have shipped this from the people who have read about it.

Retrieval-Augmented Generation for Knowledge-Intensive NLP TasksarXiv 2005.11401ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERTarXiv 2004.12832Dense Passage Retrieval for Open-Domain Question AnsweringarXiv 2004.04906
Interactive · the honest hierarchy

Four steps, and what earns you the right to move right

Read the middle lane left to right — each step is admitted by a condition, not by taste. Select a step for the detail.

You are allowed here only when
Always start here. There is nothing to justify.
Only once the corpus no longer fits — above roughly 200,000 tokens.
Only once lexical search is not enough.
Only once recall@50 is clearly better than recall@5. Without that gap you are paying p99 for nothing.
What it charges you
Cache reads at a tenth of base input tokens. No index, no embedding model, no chunking strategy.
A pip install and one index.
A vector database to operate, an embedding model to version, a chunking strategy to defend.
Latency on every query, forever — not a batch cost paid once at index time.

Most teams start at step four. They never find out whether steps one to three would have been enough.

First, consider not building it

The strongest opening move is to ask whether you need retrieval at all. Anthropic’s own guidance: under roughly 200,000 tokens — about five hundred pages — put the entire knowledge base in the prompt and let caching carry the cost. Cache reads are priced at a tenth of base input tokens. That price is what changes the arithmetic.

Say that out loud in an interview and you have set yourself apart in about fifteen seconds. Look at what you just declined to build. A vector database to operate. An embedding model to version. A chunking strategy to defend. And a whole class of failures that simply do not exist when the model can see everything.

The honest hierarchy: fit it in the context window; if you cannot, search it lexically; if that is not enough, add vectors; if that is not enough, rerank. Most teams start at step four. They never find out whether steps one to three would have been enough.

Where it actually breaks

Once you do need retrieval, treat it as a pipeline. Pipelines fail at their weakest stage, not their most sophisticated one.

The debugging instinct is to start at the end. The model said something wrong, so you go and look at the model. That instinct is almost always pointing the wrong way.

Interactive · where retrieval breaks

Six stages, and the fault is rarely in the last one

Select a stage for what goes wrong there and what actually fixes it. Most teams debug this pipeline right to left; the evidence says start at the left.

Corpuswhat you haveChunkhow you cut itIndexdense + lexicalRetrievetop-k candidatesRerankand orderGeneratewith citations
What breaks at corpus

The answer is not in the knowledge base at all. In Digital Green's deployment across four countries, two thirds of unanswered queries were exactly this — content gaps, not retrieval misses.

What fixes it

Log the queries you fail and triage them by cause before touching the retriever. If most failures are coverage, every hour spent on embedding models is an hour spent on the wrong problem.

The finding that should reorder your roadmap

Digital Green ran an agricultural question-answering service, Farmer.Chat, and about a quarter of the queries came back unanswered. Rather than describe those failures, they classified them — which is why this is the most useful published triage I know of. Of that unanswered quarter, 66% were content gaps — the answer was not in the knowledge base — 23% were out of context, and 11% concerned crops the collection did not cover.

Two thirds of the failures were a librarian’s problem, not an engineer’s. No embedding model, reranker or chunking strategy fixes a document that does not exist.

Now turn that on your own roadmap, because it is a real fork. Spend the next month on the retriever, or spend it on the corpus? Most teams pick by instinct, and instinct points at the retriever every time. Classifying fifty of your own failures costs an afternoon and answers the question properly. That single ratio is the best argument I know for spending your first week on a failure triage rather than on a retrieval bake-off.

Farmer.Chat: Scaling AI-Powered Agricultural Services for Smallholder FarmersarXiv 2409.08916BM25 (rank_bm25)Python

What each technique measurably buys

When the problem genuinely is retrieval, there is unusually good public data on what helps. Anthropic measured four configurations on the same corpus. That lets you talk about this in numbers rather than preferences. More usefully, it lets you talk about what each step costs.

Interactive · what each technique actually buys

Retrieval failure rate, measured

Step through the four configurations Anthropic measured. Each one buys a real reduction and charges a real price — the second column is the one usually left off the chart.

Failed retrievals
5.7%
The starting point, not a target.
What it adds

Embed each chunk, retrieve the top k. The default that almost every team ships first.

What it costs

Baseline. One embedding pass over the corpus, one vector lookup per query.

Source: Introducing Contextual Retrieval, Anthropic, September 2024. These are the four combinations that were measured; intermediate mixtures were not, so this component does not let you compose one and invent a number for it.

Watch what the last step charges. Contextual enrichment is a batch cost, paid once at index time. Reranking is latency, paid on every query, forever. Those are two very different lines in a budget, and treating them as one line is how a p99 target quietly dies.

Order is a correctness property

Liu et al. found that accuracy is highest when the relevant passage sits at the beginning or the end of the input. It degrades noticeably when the model has to reach into the middle. The curve is U-shaped, and it persists in models built explicitly for long contexts.

That has a consequence people miss. Reranking is usually sold as better precision. It is also deciding position, and position moves accuracy on its own. Retrieving the right chunk and burying it among forty others is not the same as retrieving it and putting it first.

assemble.py
def assemble(chunks, question):
    """chunks arrive best-first from the reranker."""
    # Best-first order puts the strongest evidence where accuracy is highest,
    # and the weakest in the middle, where the model is least reliable anyway.
    ordered = chunks[::2] + chunks[1::2][::-1]

    body = "\n\n".join(
        f"<doc id={c.id!r} source={c.source!r}>\n{c.text}\n</doc>"
        for c in ordered
    )
    return (
        f"{body}\n\n"
        f"Question: {question}\n"
        "Answer using only the documents above. Cite the id of every document "
        "you rely on as [id]. If the documents do not contain the answer, say "
        "so and name what is missing — do not answer from prior knowledge."
    )
Two lines that matter more than they look: the best chunk goes at an end rather than the middle, and every chunk carries an id the model must cite. The citation is what makes the failure mechanically checkable afterwards.

The instruction to name what is missing is doing real work. An agent that reports a coverage gap hands you a triage category. An agent that quietly answers from its own weights hands you an incident six weeks later.

What changes when an agent does the retrieving

Everything above treats retrieval as a single step before generation. Inside an agent it becomes a tool, called repeatedly, with the model writing its own queries. Three things change, and all three are worth being able to name.

First, the model can reformulate. A failed search is recoverable rather than fatal. That holds as long as your tool returns “nothing matched” as a result, rather than an empty list that reads as an answer.

Second, every retrieval becomes context you pay for again on every later turn. A chatty retriever is a compounding cost, not a one-off.

Third, the agent can search several times and contradict itself between calls. That is a failure mode single-shot RAG simply does not have.

Here is the version I would defend in an interview. Give the agent a retrieval tool with a small, bounded return, and make it cite. Do not give it a tool that returns forty thousand tokens of documents. That second design fails as a context problem long before it fails as a retrieval one.

Measuring it, and not trusting the measurement

Measure recall@k on a few hundred real queries with known-correct sources. It is boring, and it is the only thing that tells you whether an index change helped. Read the result like this. Strong recall@50 with weak recall@5 is a ranking problem. Both weak is a coverage problem. Those two findings send you into entirely different quarters of work.

Then be careful with the off-the-shelf metrics. Digital Green fine-tuned their model and it got better on everything that mattered: domain-expert F1 rose from 37.2% to 51.8%, and human raters preferred the new model in 203 of 308 comparisons. The frameworks disagreed — RAGAS scored it lower, 0.81 down to 0.76, and FActScore lower too, 0.72 down to 0.68. A team that trusted the framework metric would have shipped the worse, more expensive model. And it would have had a chart to justify the decision.

Which of this you should actually build

Retrieval is the area where stage matters most. The sophisticated techniques all address problems a small team does not have yet. The boring one — knowing why your failures failed — pays at every size.

Interactive · calibrate to your stage

What to actually do about this, at your size

Nearly all guidance on this topic is written for one company size and then read by everyone. Pick yours — the list re-sorts, and what you should deliberately not build drops to the bottom.

  • A written failure triageNon-negotiable

    Log every query you answer badly and classify the cause: content gap, retrieval miss, ranking, or generation.

    At this stage · Now automated: a weekly job that samples failures and routes them to whoever owns that stage. The triage categories become the team's shared vocabulary.

  • Lexical search alongside vectorsDo it

    A BM25 index run in parallel with the dense index, candidates merged before ranking.

    At this stage · Now run both. This is the single highest-return retrieval change available and it is a day of work.

  • A held-out query set with recall@kDo it

    A few hundred real queries with known-correct source documents, scored automatically on every index change.

    At this stage · Two to three hundred queries drawn from real traffic, in CI. This is the point where changing an embedding model stops being a leap of faith.

  • Contextual chunk enrichmentCheap version

    A generated one-line description of what each chunk is and where it sits, prepended before embedding.

    At this stage · Worth it on your highest-traffic document set only, once that set has stopped changing daily.

  • Cross-encoder rerankingCheap version

    Rescore the top candidates properly and decide the final order before they reach the model.

    At this stage · Only once recall@50 is clearly better than recall@5 — that gap is what reranking exists to close. Without the gap, you are paying p99 for nothing.

Nothing is optional at this stage. That is itself the finding — the cost of the control set is part of the cost of operating here.

The system that measured its own failures

🇮🇳🇰🇪🇪🇹🇳🇬 India · Kenya · Ethiopia · Nigeria

Digital Green Farmer.Chat — triage before tuning

66%
of misses were content gaps
9.05s
average response time
71%
context precision

Farmer.Chat answers agricultural questions for smallholder farmers over WhatsApp, Telegram and a purpose-built Android app. It runs across four countries and seven-plus languages, including Swahili, Amharic, Hausa, Hindi, Odia and Telugu — 1.5 million queries by the time of the follow-up paper. At the deployment paper’s smaller scale, roughly 75% of queries were answered successfully. The team then did the thing almost nobody does: they classified the other 25%.

Two findings travel well beyond agriculture. The first is that two thirds of failures were knowledge-base coverage. That makes retrieval work a content problem with an engineering component, rather than the other way round. The second is that generating directly in the source language performed worse than translating to English, reasoning, and translating back. That is the opposite of what “multilingual model” marketing implies, and a reminder that the pipeline around the model is usually where quality is won or lost.

What to remember

  1. 1
    Ask whether you need it at all

    Under roughly 200,000 tokens, put the corpus in the prompt and let caching carry it. Declining to build a vector database, for a stated reason, is a stronger answer than designing one.

  2. 2
    Triage failures before tuning anything

    Two thirds of real-world misses in a large multi-country deployment were content gaps. No embedding model fixes a document that does not exist. You cannot tell which problem you have until you classify fifty failures, and that is an afternoon of work.

  3. 3
    Lexical search is not legacy

    Embeddings are built to blur exactly the distinctions that matter for IDs, error codes and names. Running BM25 alongside vectors took measured retrieval failure from 3.7% to 2.9%.

  4. 4
    Position is part of correctness

    Accuracy is highest at the start and end of the context and sags in the middle. Reranking decides order, not just membership. Retrieving the right chunk and then burying it is not success.

Sources

Every source in this lesson

Primary sources wherever one exists. Where a claim is contested or vendor-reported, the lesson says so at the point it is made.

Paper
  • Retrieval-Augmented Generation for Knowledge-Intensive NLP TasksarXiv 2005.11401

    Lewis et al., NeurIPS 2020. The paper that named the thing: combining a model's parametric memory with a non-parametric index it can look things up in. Worth reading for the framing rather than the architecture, which has moved on.

  • Lost in the Middle: How Language Models Use Long ContextsarXiv 2307.03172

    Liu et al., TACL 2023. Accuracy is highest when the relevant passage sits at the start or the end of the context and degrades in the middle — a U-shaped curve that persists in models explicitly built for long contexts. Retrieval order is a correctness property, not a presentation detail.

  • Farmer.Chat: Scaling AI-Powered Agricultural Services for Smallholder FarmersarXiv 2409.08916

    Singh et al., 2024. Digital Green's deployment across India, Kenya, Ethiopia and Nigeria. The triage of failures is the most portable idea in the paper: of the roughly 25% of queries not answered, 66% were knowledge-base content gaps, 23% out of context, 11% out of collection.

  • Fine-Tuning and Evaluating Conversational AI for Agricultural AdvisoryarXiv 2603.03294

    The follow-up. RAGAS scored the fine-tuned model lower (0.81 to 0.76) and FActScore likewise (0.72 to 0.68), while domain-expert F1 rose from 37.2% to 51.8% and human raters preferred it in 203 of 308 comparisons. A team trusting the off-the-shelf RAG metric would have shipped the worse, costlier model.

  • ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERTarXiv 2004.12832

    Khattab and Zaharia, SIGIR 2020. Late interaction — score query tokens against document tokens rather than collapsing both to one vector — at roughly two orders of magnitude less cost than running a full cross-encoder over every candidate. The reference point for why one embedding per chunk throws information away.

  • Dense Passage Retrieval for Open-Domain Question AnsweringarXiv 2004.04906

    Karpukhin et al., EMNLP 2020. Established dense retrieval as a serious alternative rather than a curiosity, beating a strong Lucene-BM25 baseline by 9 to 19 points absolute on top-20 passage accuracy. Note the framing: it beat BM25, it did not make BM25 useless.

Read
  • Introducing Contextual RetrievalAnthropic

    September 2024. The measured stack: retrieval failure 5.7% baseline, 3.7% with contextual embeddings, 2.9% adding contextual BM25, 1.9% adding reranking. Also the advice most teams skip — under about 200,000 tokens, do not build retrieval at all.

Code
  • BM25 (rank_bm25)Python

    A lexical baseline you can stand up in an afternoon. Worth doing before any vector database, because it tells you how much of your problem was ever a semantic one.

Docs
  • Prompt cachingAnthropic docs

    The mechanism that makes the no-retrieval option viable: cache reads are priced at 0.1x base input tokens, so a stable corpus in a cached prefix is read repeatedly at a tenth of list price. There is a per-model floor below which nothing is cached at all, and no error is returned when you fall under it.

Lesson 07
Shipping an MCP server
Lesson 09
Frameworks, honestly