Overview
Retrieval-augmented generation (RAG) retrieves relevant passages from an external knowledge base at query time and passes them to the model with the question, so the answer rests on retrieved evidence instead of the model’s memorized training data. The pipeline has three stages: index (chunk and embed documents), retrieve (embed the query, fetch the top-k chunks, often combined with keyword search and a reranker), and generate (answer from the chunks and cite them).
Use RAG when answers depend on private, fast-changing, or very large corpora, or must cite sources. Do not use it to change tone or output format; that is prompting or fine-tuning. When the whole corpus fits the context-window at acceptable cost, long context with prompt caching can be simpler than a retrieval stack.
Most RAG failures are retrieval failures: the right chunk was never fetched. Evaluate retrieval (recall at k, mean reciprocal rank) separately from answer faithfulness, using a golden-set that stores expected source chunks. RAG reduces hallucination but does not remove it, and irrelevant chunks can mislead the model.
Example
A support bot retrieves the five most relevant help articles for a question, passes them as context, and answers with inline citations to article IDs so the user can open the source.
Related
- rag: architecture and pipeline rules.
- rag-chunking: how to split documents.
- rag-retrieval: the retrieval stage.
- rag-citations: making answers auditable.
- rag-eval: scoring retrieval and answers.
- embedding: the vectors behind retrieval.