The Sunday Letter
The Sunday Letter · No. 17 · LLMs

Check the chunks before you fix the prompt

When a RAG answer is wrong, most teams reword the prompt. The fault is often earlier: in how the documents were cut. Here is how to tell the two apart, and what to fix first.

The 60-second version
  • A RAG answer can only go wrong in two places: the right text never reached the model, or it did and the model misused it.
  • Look at the chunks that were actually sent before you touch the prompt.
  • Cut documents where the author cut them, by heading, so a rule and its exception stay together.
  • Adding a one-line note of context to each chunk, plus a reranker, cut missed chunks from 5.7% to 1.9% in Anthropic’s tests.
  • Fetch widely, then keep the best: a reranker can only reorder what search gives it.

A customer asks whether they can return a pair of earbuds they opened because one side stopped working. Your assistant says no: hygiene products cannot be returned once the seal is opened. The policy actually says yes. Damaged or faulty items can always be returned, including hygiene products.

The usual reaction is to open the prompt and add a line such as pay attention to exceptions. The answer gets better on this question and worse on three others, and nobody knows why.

Two places to look

A RAG system answers in two steps. Search picks a few chunks of your documents, and the model writes an answer from them. So a wrong answer has only two possible causes. Either the right chunk never reached the model, which is a retrieval problem, or it reached the model and the model misused it, which is a generation problem.

Before you change the prompt, look at the chunks that were actually sent.

In the earbuds case, the model was shown the hygiene rule and never saw the exception. No prompt can fix that. The fault is in how the policy was cut.

Cut where the author cut

Cut the same five-section return policy into 120-character chunks and the hygiene section falls apart. One chunk says hygiene items cannot be returned once the seal is opened. The next says The rule does not apply if the item arrives damaged or faulty, which means nothing on its own, because it never says which rule. If search returns only the first chunk, the model refuses a return the policy allows.

Cut it into 1,000-character chunks and the opposite happens: one chunk holds four unrelated sections, so its embedding is an average of four topics and sits close to none of them.

Cut it by heading and each section stays whole, because the author already grouped related sentences under each heading. That is usually the best first cut. Split any section that is still too long at paragraphs, then sentences, with a little overlap so a sentence cut in half survives whole in one of the two chunks.

Give each chunk its context

Even a well-cut chunk can lose its meaning once it leaves the document. A line deep in a contract that says the limit is 48 hours doesn't say what the limit is for. The fix is to have a small model read the whole document with each chunk and write one or two sentences saying where the chunk belongs, then store that note in front of the chunk.

Anthropic, which named this contextual retrieval, measured how often the right chunk was missing from the top 20 search results. With plain chunks it was missing 5.7% of the time. With the notes added to both the embeddings and the keyword search, 2.9%. With a reranker on top, 1.9%: two thirds of the misses gone.

Fetch widely, then keep the best

A reranker reads the question and each chunk together, so it can see that a paragraph about unopened earbuds does not answer a question about opened ones. Embeddings can't, because each text was turned into numbers on its own. But a reranker is slow, so it can't read everything.

So work in stages. Let fast search fetch around 50 chunks, aiming for recall, then let the reranker keep the best 5, aiming for precision. If you ask search for 5 directly, any chunk it ranks 9th is gone for good, because the reranker can only reorder what it is given.

What to do this week

Take ten questions your assistant answered wrongly. For each one, print the chunks it was sent. Mark each failure as retrieval (the right text wasn't there) or generation (it was there and the model ignored it). Fix the retrieval ones in ingestion: the cut, the context notes, how many chunks you fetch. Only then touch the prompt.

Figures as reported by Anthropic (2024) and used in Ship Real AI, Module 7.

Get the next letter.

A new essay arrives every Sunday.