The capability
What retrieval-augmented generation is
As you already know from M3, when a model answers, all it has to go on is what it learned in training and the text you put in the request. It has never seen your company's parental leave policy or the fault codes in your robot manuals, so if you ask it about them it'll either say it doesn't know or, more often, write something that sounds right. Retrieval-augmented generation, or RAG for short, is how you get those documents in front of it. When a question comes in, your code searches your documents for the passages that have to do with it, puts those passages into the request next to the question, and asks the model to answer from them and say which passage each claim came from.
So a RAG system has two parts. One is a search system, which has to find the right few passages out of thousands of documents in a fraction of a second, for this particular person, from the current version of each document. If you're searching by meaning, that usually means turning every passage into an embedding, which is basically a list of numbers that captures what the passage is about, and storing those in a vector database that can find the embeddings closest to the question's. Searching by keyword works too, and section 11 shows why good systems run both. The other part is the model call that M4 and M5 already covered, except now it has a stricter job, because it has to answer from the passages it was given and say so when they don't contain the answer. Most of the engineering in this module is on the search side, because a model can't answer from a passage that never reached it.
The name comes from a 2020 paper by Lewis and colleagues at Facebook AI Research, which paired a BART generator with a neural retriever that searched Wikipedia split up into 100-word chunks, and trained the two of them together (Lewis et al., 2020). What people call RAG today is looser than that. The retriever and the model are usually separate products that nobody trains together, and the documents are your own.
This is what that shape looks like on one real run of the finished Orrin assistant, where an engineer in Toronto asks how pay works during parental leave.

RAG can't make the model know your documents in any lasting way. Nothing gets learned, so the next question starts from zero and you have to search again. It also can't fix documents that are out of date or that contradict each other, and the model will usually repeat whichever one the search ranked first. And it can't enforce who's allowed to read what, because the model will use whatever text reaches it. So you have to apply permissions in the search, before the model sees anything, and section 5 of Part 2 builds that.
Where it shows up
- An internal knowledge assistant that answers employees' questions about HR policies and engineering documents, which is the example in this module.
- A support agent that answers customers from the help center, like the flower company's agent in M6, whose
kb_passagestable is a small RAG index. - A coding agent that searches a repository and its docs before editing, like the one in M16 and M17.
- Memory lookup in M16, where the documents are facts the agent saved about past sessions.
The documents and the users change from one to the next, but all four have the same two halves, which are a search that has to find the right passage for this person and a model that has to answer only from what it was given.
Keep reading
The rest of this lesson is free with an account
Create a free account to read the remaining 15 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.
- 02The assistant that quoted a confidential brief to Maya
- 03Check whether the documents fit in the prompt before you build a search
- 04One pipeline builds the index, and another answers the question
- 05Turn every chunk and every question into a vector with one embedding model
- 06Compare vectors by their direction, and read the score as a ranking
- and 10 more
