RAG

Your RAG Problem Is Probably a Chunking Problem

Before you swap the embedding model or add a reranker, go and read the chunks your retriever actually returned. The answer is usually right there.

When a RAG system gives a bad answer, the instinct is to reach for the generation side. Better prompt, bigger model, add a reranker, try a different embedding.

Nearly every time I have debugged one, including a medical document pipeline where the answers had to be exactly right, the fault was upstream. The retriever returned chunks that could not have produced a correct answer, and the model did the best it could with them.

So the first debugging step is always the same: print the retrieved chunks and read them. Not the scores. The text.

Four things show up repeatedly.

The answer was split across a boundary. Fixed-size chunking cuts a table in half, or separates a heading from the paragraph it governs. Each half retrieves poorly because neither is semantically complete on its own.

The chunk has no context. "It should not exceed 40 mg." What should not? The chunk was perfectly retrievable and completely useless, because the subject was three paragraphs up. Prefixing each chunk with its document title and section heading costs almost nothing and fixes a surprising share of these.

Tables were flattened into noise. PDF extraction turns a clean table into a run of numbers with no structure. It embeds badly, retrieves badly, and reads badly to the model. Tables need to be detected and serialised deliberately, as markdown, or as one row per chunk with the header repeated.

The right chunk was retrieved and buried. It came back at rank eight, outside what you passed to the model. This is the one case where a reranker genuinely helps, but you only know that by looking.

The diagnostic that settles it in ten minutes: take twenty questions you know the answers to, retrieve for each, and manually mark whether the correct information was present anywhere in the retrieved set.

If it was present and the answer was still wrong, you have a generation problem. If it was not present, no amount of prompt engineering will save you, and every hour spent on the generation side is wasted.

That number, retrieval recall on a small hand-labelled set, is the most useful metric in a RAG system and almost nobody computes it.