AI Engineering · Concept Library · Free article
RAG (Retrieval-Augmented Generation)
A language model knows a lot about the world in general and nothing about your product in particular, and its knowledge froze months ago. RAG fixes that without retraining: when a question comes in, look up the few relevant passages from your own docs and let the model answer from them. This page builds the whole pipeline from first principles, chunk, embed, retrieve, ground, cite, plus the unglamorous half that decides whether it works: reranking, evaluation, freshness, and security.
A model is frozen at its training cutoff and never saw your private docs, so asked about your product it invents a plausible answer. RAG, retrieval-augmented generation, stops that by looking the answer up at request time instead of relying on memory: split your documents into passage-sized chunks, turn each into an embedding that captures meaning, and at query time fetch the handful of chunks closest to the question, drop them into the prompt, and instruct the model to answer only from them and cite. The mechanism is simple; the engineering that makes it reliable is not, chunking that keeps a thought whole, retrieval that matches meaning and exact terms, reranking so the right passage actually comes back, an eval harness that scores retrieval and generation separately, a fresh index, and a trust boundary around text you didn't write. RAG earns its place when knowledge is too large to paste, too fresh to bake in, or too important to leave uncited.
Wrenlet is fast, cheap, and finally sounds like the team. Then a customer asks about the product itself: “Can I schedule a reply to send later?” Wrenlet answers instantly and warmly, “Yes! Open Settings → Scheduled Send, pick a date and time, and we'll queue the draft.” Clear, confident, helpfully specific. And completely made up. There is no Scheduled Send. There never was.
This isn't the confident-nonsense problem from chapter one that you fix with a better prompt. The model knows a great deal about software in general and nothing about Wrenlet in particular. Its training data closed months ago and never included your private changelog, your help center, or last week's policy update. Asked about your product, it does the only thing it can: pattern-matches the average SaaS it did see and fills in a feature that sounds right. No instruction closes that gap, because the gap is missing knowledge, not bad wording. The fix is to hand the model your actual docs, at the moment it answers.
Two fixes that don’t work, and the one that does
The first instinct is to paste the whole product handbook into every prompt. Context engineering already dismantled that: the window is a budget, a wall of mostly-irrelevant text drops accuracy and costs money on every single call, and the handbook is out of date the moment any doc changes. It also simply doesn't scale, a real knowledge base is far larger than any prompt.
The second instinct is to fine-tune the model on your docs, train the facts into its weights. But fine-tuning is the wrong tool for facts. It's expensive to redo every time a policy changes, it can't point at a source when a customer (or your legal team) asks where an answer came from, and a model tuned on facts still blends them into new fabrications. Fine-tuning is for teaching a model how to behave, a voice, a format, a skill, not for a knowledge base that keeps changing (the few-shot-or-fine-tune call from the last chapter was the same distinction).
Both non-fixes share one flaw: they try to make the model memorize everything about your product, up front, for every question it might ever get. The alternative is to not memorize at all. When a question actually arrives, look up the few passages that bear on it and let the model answer from those. That is retrieval-augmented generation, RAG, introduced by Lewis et al. in 2020, who paired a model's built-in memory with a separate, searchable store it can pull from at generation time.
How does RAG work, end to end?
RAG inserts one step before the model writes a word. A question comes in → search a store of your documents for the few most relevant snippets → paste those snippets into the prompt → ask the model to answer from them. The model's job shrinks from “know everything about Wrenlet” to “answer this question using these passages.” That is the entire mechanism. Everything else on this page is making each of those steps better.
Watch it flip on the Scheduled Send question. Same model, same question, retrieval is the only thing that changes:
The interactive version of this example is available when JavaScript loads.
How big should a RAG chunk be?
Big enough to stand on its own, small enough to be a precise match, which in practice means the low hundreds of tokens, cut along the document's own structure. You can't retrieve a whole forty-page policy, it wouldn't fit the window, and almost none of it bears on any one question. So indexing starts by splitting each document into chunks: passage-sized pieces, small enough to be a precise match, big enough to stand on their own. Where you make the cut matters far more than it first appears.
Two failure shapes bracket the choice. Cut too small and a single rule gets torn across two chunks, neither one answers the question whole. Cut too big and each chunk drags in unrelated text that dilutes the match and wastes budget. Slide the knobs on a real Wrenlet refund rule and feel both edges:
The interactive version of this example is available when JavaScript loads.
A common starting point (treat it as a range, not a law): split on structure first, headings, then paragraphs, then sentences, with chunks in the low hundreds of tokens, and a little overlap so a thought that straddles a boundary survives whole in at least one chunk (Pinecone's chunking guide is a solid reference for the usual defaults). But “always overlap” is folklore worth questioning, careful analyses find overlap often buys little recall while adding indexing cost, and the right size is corpus-specific. The honest rule: pick a starting size, then measure retrieval and adjust, never inherit a magic number.
Retrieving on meaning, not words
Now each chunk has to be findable. The naive way, keyword search, breaks on how real customers write. Someone types “you charged me twice”; the article that resolves it is filed under “duplicate billing reversal,” sharing not one word with the complaint. Keyword search would sail right past it.
RAG instead turns every chunk into an embedding, a list of numbers that captures what the text means, arranged so that passages about the same idea land near each other even with no words in common. “Charged me twice” and “duplicate billing reversal” become neighbors. Flip between the two ways of scoring and watch the ranking rearrange:
The interactive version of this example is available when JavaScript loads.
How a model turns text into a meaning-vector, which embedding model to pick (they vary a lot by task, MTEB is the standard benchmark, and its honest lesson is that no single model wins everything, so choose one that's strong at retrieval on data like yours via the leaderboard), and the geometry of “near”, all of that is a topic in its own right, and the embeddings page goes deep on it. For RAG, the working idea is enough: chunk → embed → store the vectors. That's your index.
And that store isn't just an abstraction, it's a space you can look at. Play a handful of Wrenlet snippets through the pipeline below: watch each one become a vector, take a position, and drift into a neighbourhood of snippets that mean something similar, with no one labelling the groups. Then drop the customer's question in and see it land right among its answers.
The interactive version of this example is available when JavaScript loads.
Two things in that picture are the whole of indexing. Nobody labelled those neighbourhoods: the snippets about refunds sit together because the encoder placed them there, and the customer's question lands among its answers for exactly the same reason. The map is a two-dimensional projection so the grouping is visible at all, real embeddings have hundreds to thousands of dimensions, but the geometry it shows is the geometry retrieval actually searches.
How does vector search find the nearest chunks?
At query time you embed the incoming question the very same way, then ask the store for the chunks whose vectors sit closest to it, the top-k nearest neighbors. Closeness is usually cosine similarity: the angle between two vectors, where a smaller angle means more alike. And k is a dial you'll tune, too small and you miss a needed chunk; too large and you drag in noise, which is the crowded-window problem from context engineering showing up again.
With millions of chunks you can't compare the question against every stored vector on each request, far too slow. A vector index (the data structure inside a vector database) trades a sliver of accuracy for an enormous speed-up, returning the approximate nearest neighbors in milliseconds; the index family you'll meet most is HNSW. How that structure works, and exact-versus-approximate search, is its own page later in this chapter. For RAG, hold just this: retrieval is a fast top-k meaning-lookup, and its output is a handful of chunks.
How do you ground the model in what you retrieved?
You ground it by handing the model the passages and forbidding it everything else. Take the retrieved chunks, drop them into the prompt as clearly-marked reference material, and instruct the model plainly: answer using only the passages provided; if they don't contain the answer, say you don't know. Everything context engineering taught applies here, order the chunks so the strongest sits at an edge (models read the start and end of a prompt best and skim the middle, the effect Liu et al. 2023 measured across many models), and resist the urge to overstuff.
When should you use RAG instead of fine-tuning or long context?
RAG is not the only way to give a model knowledge it didn't train on, and it isn't always the best. There are three tools for three different jobs: fine-tune to change how the model answers (voice, format, a skill); long context to simply paste a small, stable document into the window on every call; and RAG when the knowledge is large, changes often, or must be cited. Describe your case and watch the right one light up:
The interactive version of this example is available when JavaScript loads.
The “long context killed RAG” claim resurfaces every time windows grow, models now advertise hundreds of thousands, even millions, of tokens. It didn't kill RAG; it moved the line. Pasting a whole corpus into every call is slower (the model reprocesses all of it), far more expensive (you pay for every token every time: a million-token corpus per call against five 300-token chunks is roughly a 600-fold difference in input tokens, and about 60-fold once a cached prefix is doing its work), and it degrades anyway as the window fills (the middle-skimming above, plus accuracy sagging well before the advertised limit). Providers do now return span-level citations for a document you paste in, so citation alone is no longer the tiebreak: what a pasted corpus cannot give you is provenance for the RETRIEVAL, an auditable record of which documents were selected and why, because nothing selected them. Long context wins for a small corpus you reason over as a whole; RAG wins for a large, living, must-cite knowledge base. Mature systems route between them rather than pledging to one.
Where does RAG break?
RAG trades “the model made something up” for a pipeline that can fail at any stage, and most of those failures hide behind a fluent, confident-looking answer. Learn them by name so a bad answer becomes a diagnosis, not a mystery.
The failure modes that bite in production
- Retrieval miss. The chunk that answers the question was never fetched, a weak embedding match, a vocabulary gap, or k set too low. The most common failure by far.
- Torn answer. Chunking split the rule across two chunks, so no single retrieved chunk answers it whole, the boundary problem from earlier, now downstream.
- Buried evidence. The right chunk was retrieved but sits in the middle of a long context where the model under-reads it. A position bug, not a knowledge gap.
- Stale index. A doc changed; the index still holds the old version, so retrieval is confidently out of date and nothing in the answer looks wrong.
- Ungrounded answer. The correct passage was in the prompt and the model answered from its own prior anyway. RAG reduces fabrication; it doesn't abolish it.
- Wrong-source citation. The answer cites a passage that doesn't actually support the claim, a citation that looks rigorous and isn't, which is worse than none.
- Trusting the citation. Showing sources without checking that the cited passage actually supports the claim: a citation that is present is not a citation that is correct.
- Distraction. Too many chunks retrieved; the noise crowds out the signal and inflates cost, exactly as over-stuffing does in a hand-written prompt.
The single most useful habit when an answer is wrong: split the pipeline in two. Was the passage that answers it inside what retrieval returned? If not, it's a retrieval problem, fix chunking, search, k, or reranking. If it was right there and the answer still missed it, it's a generation problem, fix the prompt, the grounding instruction, or the model. Fixing the wrong half is the classic RAG time-sink. Diagnose three real incidents:
The interactive version of this example is available when JavaScript loads.
Work through those incidents and the split does the diagnosing for you. When the answering passage is missing from what came back, no prompt change will help: the fix is upstream, in chunking, search, k, or reranking. When it is right there and the reply contradicts it, retrieval did its job and the fix is grounding: the instruction, the model, or the citation requirement. The same wrong answer on the surface, opposite repairs underneath, which is why guessing costs days.
How do you make retrieval better?
When plain top-k retrieval isn't enough, there's a deep toolbox, but treat it as a map from failure to fix, not a checklist of buzzwords to name-drop. The moves cluster by where in the pipeline they act:
The main techniques, and when to reach for each
- Hybrid search. Meaning-based search is great with paraphrases, but it can slip on exact strings, a customer who types a plan name like Scale, or an event name like
draft.approved, wants a document that contains those precise words. So run two searches at once: the meaning-based one you already have, plus an old-fashioned keyword search that ranks documents by the literal words they share with the question (the classic keyword method is BM25). Then merge the two lists of results into one. You get the strengths of both, paraphrases and exact terms. Reach for it when retrieval keeps missing documents that hinge on one specific word or code. The next chapter covers it in depth. - Reranking. The fast first-stage search scores each document on its own, so the single document that truly answers the question can end up below the cut and get dropped before the model ever sees it. A reranker is a second, slower pass that looks at the question and a candidate document as a pair and judges how well they actually fit. You run it only on the shortlist the first search returned, then keep the best few. Reach for it when you can see the right document was retrieved but sat too far down the list to make the cut.
- Query rewriting. People ask questions in a different shape from how documents are written, short, vague, full of “it” and “that.” Before searching, you can have a model tidy the question up, split it into a few clearer variations, or even write a quick throwaway answer and search using that instead of the raw question (a trick called HyDE: the draft answer might be wrong, but it reads a lot more like the document you are hunting for). Reach for it when the question and the answer are about the same thing but worded so differently that plain search can't connect them.
- Smarter chunking. Sometimes the best-matching chunk is too small to answer on its own, and sometimes a chunk loses its meaning once it is cut away from the section it came from. Two fixes. First, match on a small, precise chunk but hand the model the larger passage around it (the community calls this small-to-big, or parent-document, retrieval). Second, before you embed a chunk, prepend a one-line note saying which document and section it came from, so it stays findable even in isolation, this is Anthropic's contextual retrieval, which reports cutting retrieval failures by roughly a third with that step alone, and by up to about two-thirds when combined with keyword search and reranking, in their own tests. Reach for these when your chunks are individually too thin, or lose the thread once separated from their source.
- Structure-aware retrieval. Some questions, “what themes keep coming up across all our tickets?”, have no single chunk that answers them, because the answer is spread across the whole collection. Ordinary retrieval, which only ever grabs a few nearby chunks, simply can't see the big picture. The fix is to build a map of the collection ahead of time: pull out the people, products, and topics, link them into a graph, and write summaries of each group, so the system can reason over the whole corpus instead of a handful of snippets (Microsoft's GraphRAG). Reach for it when the question is about the collection as a whole, not one specific fact inside it.
- Letting the model drive. In everything above, retrieval happens the same way on every question, one search, whether the question needs it or not. The more advanced setups hand that judgment to the model itself: let it decide when a lookup is even necessary and check its own draft answer against the sources (Self-RAG), or add a small grader that inspects what came back and kicks off a fresh search when the first batch looks weak (Corrective RAG). Reach for these when one fixed retrieve-then-answer isn't enough, when some questions need no lookup at all and others need a second, better one.
The first two are the highest-leverage and the ones you reach for first. Reranking especially earns its keep: cast a wide, cheap net, then filter it precisely.
The interactive version of this example is available when JavaScript loads.
How do you know whether your RAG actually works?
You can't tune what you don't measure, and RAG hides its failures behind fluent answers. The core discipline is the same split you used to debug: score retrieval and generation apart, because they fail for different reasons and improve with different fixes.
| Metric | What it asks | Grades |
|---|---|---|
| Recall@k | Did the chunk you needed make it into the top k? | Retrieval |
| Precision@k | How much of what you retrieved was actually relevant? | Retrieval |
| Faithfulness | Is every claim in the answer supported by the retrieved text? | Generation |
| Answer relevance | Does the answer actually address the question asked? | Generation |
The two halves localize the fault before you touch code: an answer that's wrong with high retrieval recall is a generation problem; wrong with low recall is a retrieval problem. The open-source RAGAS framework packages exactly this split, context precision and recall for the retriever, faithfulness and answer-relevancy for the generator. Building a real eval harness, a golden set of question→answer pairs you re-run on every change, gets its own page; here, the mindset is the point: RAG is a system you measure and tune, not a demo you ship once and hope over.
What does the extra retrieval hop cost?
RAG isn't free: a few milliseconds to embed and search, tens to hundreds more if you rerank, and a larger prompt on every query. Every query now does extra work before the model even starts: embed the question (cheap, milliseconds), search the index (milliseconds), optionally rerank (tens of milliseconds for a small local cross-encoder, 100 ms and up for a hosted one on a long shortlist, and this is the hop you will feel), and the prompt is bigger because it carries the retrieved chunks. Indexing has its own one-time cost, embedding your entire corpus, plus storage for the vectors and re-embedding whenever docs change.
Measured against the alternatives, though, it's a bargain. Stuffing a long context re-pays to process the whole corpus on every single call; RAG pays to embed once, then sends only the few chunks a question needs. Do the arithmetic yourself rather than taking it on trust: a million-token corpus against five 300-token chunks is about 600 times the input tokens per question.
The honest counter-argument is prompt caching, which the last chapter spent itself on. A pasted corpus that never changes is a stable prefix, and a cache read costs about a tenth of normal input price, so caching closes most of that gap and the real line is not raw token price at all. It is freshness, scale and provenance: a cache does not help a corpus that changes, and it still sends the model everything rather than the part that answers. It cuts the other way too, and this is the detail people miss: put your retrieved chunks at the END of the prompt, because per-question text at the front destroys the stable prefix and you lose the cache you were counting on. And unlike fine-tuning, updating knowledge is just re-indexing a changed doc, not a retraining run. The honest framing: RAG adds latency and moving parts, and in return buys freshness, citability, scale, and a lower per-query bill. Judge it the way the cost page taught, by cost per resolved outcome across the whole pipeline, not by the token count of one call.
Retrieved text is untrusted input
RAG quietly widens your attack surface: you're now pasting text you didn't write, documents, and in some systems web pages or user uploads, straight into the model's instructions. The trust boundary from context engineering becomes load-bearing here. A malicious instruction hidden in a retrieved doc (white-on-white text, an HTML comment) gets chunked, retrieved, and can be obeyed, indirect prompt injection, a form of OWASP's top LLM risk. PoisonedRAG reports a 90% attack success rate from injecting five malicious texts per target question into a knowledge base of millions, which is a reminder that an index is only as trustworthy as what you let into it. Treat every retrieved passage as data, never as commands, and gate any irreversible action outside the model.
The second, quieter risk is access control. Your index is a pile of chunks stripped of the permissions their source documents carried. A naive shared index will cheerfully retrieve a chunk from a doc this user was never allowed to see, a data leak wearing the costume of a helpful answer. Retrieval has to enforce the same per-user or per-tenant permissions as the originals: filter by who's asking before you rank by relevance.
The tools you’ll actually reach for
A RAG stack has three layers, and each has a crowded market. Worth knowing what sits where before the names blur together.
| Layer | What it does | Names you’ll hear |
|---|---|---|
| Vector store / index | Holds the chunk embeddings and runs the nearest-neighbor search. | pgvector (a Postgres extension), Pinecone, Weaviate, Qdrant, Milvus, Chroma |
| Embedding model | Turns text into the meaning-vectors you index and search. | OpenAI text-embedding-3, Cohere Embed, Voyage, open models like BGE / E5, compared on MTEB |
| Orchestration | Wires ingest → chunk → embed → retrieve → rerank → prompt → generate. | LangChain, LlamaIndex (strong on ingestion + retrieval), Haystack |
And at the managed end, the big providers sell the whole pipeline behind one API, “knowledge base” products such as Amazon Bedrock Knowledge Bases, Google Vertex AI Search, and Azure AI Search. Starting by hand, pgvector plus an embedding call, is the best way to feel the moving parts; reach for the managed stack when scale or ops make building it yourself a distraction.
The pipeline, in code
Stripped of any framework, RAG is two short procedures: one you run offline to build the index, one you run per question. The shapes are worth seeing plainly.
Indexing: run once, and again on every doc change
- Chunk each doc on structure.
chunks = split(doc, size≈300, overlap≈40), prefer headings and paragraphs to blind character counts, so a thought stays whole. - Embed every chunk.
vectors = embed(chunks), one vector per chunk, from your chosen embedding model. - Upsert with metadata.
index.upsert(id, vector, { text, source, acl }), keep the source text (to cite) and the permissions (to filter) alongside each vector.
Answering: run per question
- Embed the question.
q = embed(question), with the same model you indexed with. - Retrieve top-k, permission-filtered.
hits = index.search(q, k=20, filter=user.acl), cast the wide net, but only over docs this user may see. - Rerank and keep a few.
top = rerank(question, hits)[:5], wide then narrow. - Assemble with the grounding instruction. Drop the chunks in as marked reference text and add: answer only from these, cite the passage, say you don't know if it's absent.
- Generate, then attach sources.
answer = llm(prompt), and hand the cited passages back to the reader so the answer is auditable.
How to do RAG well, on purpose
The habits that separate a tuned pipeline from a hopeful one
- Index for retrievability. Chunk on structure, keep each thought whole, add overlap only if your recall numbers say it helps, and store the source and permissions with every chunk.
- Retrieve hybrid, then rerank. Dense for meaning, keyword for exact terms, a reranker to lift the best few, retrieve wide, keep narrow.
- Write the grounding contract. Answer only from context, cite the passage, abstain when it's absent, make honesty the default, not a hope.
- Measure both halves. Recall and precision for retrieval, faithfulness and relevance for generation, on a golden set you re-run on every change.
- Route deliberately. RAG for large, living, must-cite knowledge; fine-tune for behavior; a pasted doc for the small and stable.
- Treat retrieved text as untrusted. Data, not commands; permission-filtered before ranking; irreversible actions gated outside the model.
- Keep the index fresh. Re-embed changed docs on write or on a schedule, a stale index fails silently, which is the worst way to fail.
Interview cheat-sheet: intern to principal
- What is RAG, and what problem does it solve?
- Retrieval-augmented generation. A model is frozen at its training cutoff and never saw your private data, so asked about your product it invents a plausible answer. RAG fixes that without retraining: at request time it searches a store of your documents, retrieves the few most relevant passages, puts them in the prompt, and has the model answer from them and cite them. It gives the model fresh, private, citable knowledge and cuts fabrication by grounding the answer in real source text.
- Walk me through the RAG pipeline end to end.
- Two phases. Offline indexing: load documents, split them into passage-sized chunks, embed each chunk into a meaning-vector, and store the vectors (plus source text and permissions) in a vector index. Online query: embed the incoming question with the same model, retrieve the top-k nearest chunks (often filtered by the user's permissions), optionally rerank the shortlist, assemble the best few into the prompt with an instruction to answer only from them and cite, then generate and return the answer with its sources.
- Why not just fine-tune the model on our docs, or paste them into a long context window?
- Fine-tuning bakes facts into weights: expensive to redo when docs change, unable to cite a source, and it still blends facts into fabrications, it's for teaching behavior, not a living knowledge base. Long context re-processes the whole corpus on every call (slow, costly, can't cite which part it used) and degrades as the window fills. RAG looks up only what each question needs. Route by the knowledge: fine-tune for behavior, paste for a small stable doc, RAG when it's large, changing, or must be cited.
- Why embeddings instead of keyword search, and when do you still want keywords?
- Customers rarely use the words your docs use, “you charged me twice” must match “duplicate billing reversal,” which shares no words. Embeddings score by meaning, so paraphrases match. But you still want keyword (sparse/BM25) search for exact tokens, a plan name, an error identifier, a proper noun, that meaning-search can smear over. Production systems run both and fuse them: hybrid search.
- How do you choose chunk size and overlap?
- By measuring, not by a magic number. Too small and a single rule tears across chunks so no chunk answers it whole; too large and each chunk dilutes its embedding and wastes context. Start by splitting on structure (headings, paragraphs) at a few hundred tokens, add small overlap only if recall improves, then tune against a golden set. The goal is the smallest chunk that keeps a complete thought intact.
- A RAG answer is wrong. How do you debug it?
- Split the pipeline. First ask whether the passage that answers it was inside what retrieval returned. If not, it's a retrieval failure, fix chunking, add hybrid search, raise k, or add reranking. If it was there and the answer still missed it, it's a generation failure, tighten the grounding instruction, add a faithfulness check, or use a stronger model. Localizing the fault before touching code is the move that saves days.
- How do you measure a RAG system?
- Score retrieval and generation separately. Retrieval: recall@k (did the needed chunk get fetched) and precision@k (how much of what came back was relevant). Generation: faithfulness (every claim supported by the retrieved text) and answer relevance (it addresses the question). RAGAS packages this split. Underneath it all is a golden set of question→answer pairs you re-run on every change, evaluation-driven iteration, not one-shot tuning.
- Models now have million-token windows. Is RAG obsolete?
- No, big windows moved the line, they didn't erase it. Pasting a whole corpus on every call is slower, far more expensive (you pay for all of it every time), can't cite which part it used, and accuracy sags well before the advertised limit. RAG stays cheaper, fresher, citable, and scalable for large living knowledge bases; long context wins for a small corpus you reason over whole. Mature systems route between them.
- What is reranking and why does it help?
- Two-stage retrieval. The first-stage retriever is tuned for recall and scores each doc quickly in isolation, so the truly best passage can land mid-pack. A reranker, slower, because it reads the question and each candidate together, re-scores the shortlist and lifts the right one to the top, so the same top-k now keeps it. Retrieve wide and cheap, then rerank narrow and precise. It fixes the common “right doc retrieved but ranked too low to survive the cut” miss.
- What are the security risks of RAG?
- Two big ones. Indirect prompt injection: retrieved documents are text you didn't write, and a hidden instruction inside one (white-on-white text, an HTML comment) can be chunked, retrieved, and obeyed, so treat retrieved text as data, never commands, and gate irreversible actions outside the model. And access control: the index strips documents of their permissions, so a naive shared index can retrieve chunks a user was never allowed to see. Filter retrieval by who's asking before ranking by relevance.
- The right chunk is retrieved but the model still answers wrong. What is happening and how do you fix it?
- That's a grounding failure, not a retrieval one, the passage was in the prompt and the model answered from its own prior anyway. It's more likely when the evidence is buried in the middle of a long context (models under-read the middle), when the grounding instruction is weak, or when too many distracting chunks dilute the signal. Fixes: reduce and rerank so the key passage sits at an edge, strengthen the “answer only from these passages” instruction, add a faithfulness check that flags unsupported claims, or use a stronger model.
By GOAT Engineer. Back to Concept Library. Privacy Policy · Contact.