Courses / AI Engineering: LLMs, RAG and Agentic System Design / Chapter 7
Module 3 · Vector search and LLM applications · Chapter 7 of 24
Retrieval-augmented generation
Builds on Embeddings and vector databases and Working with model APIs. Next up: Fine-tuning language models.
Part 1 · Why retrieval
What a model does not know
A model knows only what it saw in training, so it cannot quote your latest policy. Retrieval-augmented generation (RAG) fetches the relevant passages at question time and puts them in the prompt.
The model's knowledge has three limits. It stops at a knowledge cutoff, so it knows nothing newer. It never saw your private data, such as a company's return policy or last week's price list. And when it does not know, it often produces a fluent guess. RAG is the standard fix: look the facts up in your own documents, and tell the model to answer from them.
The name comes from Lewis and co-authors in 2020, who combined a generator that holds knowledge in its weights with a retriever that searches an index of documents. The idea in production form is simpler. A RAG system has four steps. Ingest: split documents into chunks and index them, once and again when they change. Retrieve: find the chunks closest to the question. Augment: build a prompt that contains those chunks. Generate: have the model write the answer, ideally with citations to the chunks it used.
RAG gives you three things that training or prompting alone does not. Fresh knowledge: you change a document and the next answer changes, with no retraining. Private knowledge: the model can use data it never saw, without that data leaving your control. And citations: because the answer comes from named passages, a reader can check it. Citations turn "trust me" into "here is where this came from".