Retrieval-augmented generation (RAG) gives a language model an open book. Before the model answers, a retriever searches a collection of documents for passages relevant to the question and places them in the prompt. The model then writes its answer from that text rather than from memory alone.
The name comes from a 2020 paper by Lewis and colleagues. They paired a pre-trained sequence-to-sequence generator with a dense vector index of Wikipedia and a neural retriever, describing it as combining parametric memory (knowledge stored in the weights) with non-parametric memory (an index you can read and replace). Their models set the state of the art on three open-domain question-answering tasks. (Paper summary.)
How a RAG pipeline works
The diagram shows the path at question time. Ahead of time, documents are split into chunks, each chunk is turned into an embedding, and the vectors are stored in a vector database. Then, for each question:
- The question is embedded with the same model.
- The database returns the chunks whose vectors are nearest, a stand-in for semantic similarity.
- The chunks and the question go into the prompt together.
- The model answers, ideally saying which chunk each claim came from.
Some systems add keyword search alongside the vector search, or a reranking step that rescores candidates before they reach the prompt.
Why use it
- Fresh knowledge without retraining. Update the documents and the answers change. The weights never do.
- Private data. A company’s own documents can be searched at question time without being trained into a model.
- Checkable answers. Retrieved passages give provenance, which the 2020 paper flagged as an open problem for models that keep knowledge only in their weights. Grounding answers in sources also tends to reduce hallucination, though it doesn’t remove it.
The catch
RAG is only as good as its retrieval. If the right passage isn’t found, the model answers from memory or from a near-miss chunk, and sounds just as sure. Chunking is a real design choice: split too finely and context is lost, too coarsely and irrelevant text crowds the prompt. Retrieved text also uses up the context window, and every token costs money, so more passages isn’t automatically better. And the model can still misread or ignore a good source, which is why retrieval and answers are worth evaluating separately.