Skip to content

Learn · Guide

What Is RAG?

Grounding a language model in retrieved documents instead of asking it to remember everything.

The problem RAG solves

A language model has two memory problems. Its training data has a cutoff, so it does not know recent events, and it cannot see your private documents. It also tends to produce confident answers when it lacks facts. Retrieval-augmented generation, or RAG, addresses this by searching external material at query time and giving the model the relevant passages as evidence. The model is asked to answer from that evidence rather than from memory alone.

The three stages

First, index your documents: split them into chunks, embed each chunk, and store the vectors with the original text. Second, retrieve: when a question arrives, embed it and find the nearest chunks, often combining keyword search for exact terms. Third, generate: build a prompt that includes the question and the retrieved passages, then instruct the model to answer only from them and cite the source. Each stage can be improved independently, which is why RAG is a system design rather than a single model feature.

Chunking matters more than people expect

If chunks are too large, retrieval finds a document but the prompt wastes space on unrelated paragraphs. If chunks are too small, the answer is split across pieces and no single chunk contains enough context. A common starting point is a few hundred words with a small overlap, plus headings attached to each chunk so the model knows where it came from. Tables and code blocks often need special handling because naive splitting destroys their meaning.

Grounding reduces but does not eliminate errors

RAG makes answers more current and more traceable, but the model can still misread a passage, combine two sources incorrectly, or ignore the evidence when a question is phrased in a familiar way. If retrieval misses the right document, the model may produce an answer that sounds grounded but is not. That is why production systems measure retrieval quality separately from answer quality. A wrong passage in the prompt is a wrong answer waiting to happen.

How to evaluate it

Keep a set of real questions with known correct source documents. Check whether retrieval finds those documents, then check whether the generated answer is supported by them. Track both numbers. If retrieval fails, improve chunking, metadata filters, or embeddings. If retrieval succeeds but answers are wrong, improve the prompt, require citations, or use a model better at following evidence. This split turns a vague quality problem into two actionable engineering problems.