How RAG Works
Retrieve, then generate.
A RAG system has two parts. First, we prepare our documents once, so they're easy to search. Then, every time a question arrives, we search, and generate an answer. Let's look at each part.

- Prepare once
- Search every time
- Then generate
Part one: indexing
Indexing happens ahead of time. We load our documents. We split them into small chunks. We turn each chunk into a list of numbers, called an embedding, that captures its meaning. And we store those, in an index, ready to search.
- Load
- Split
- Embed
- Store

Part two: answering
When a question comes in, we embed the question the same way. We search the index for the chunks closest in meaning. We put those chunks into a prompt, with the question. And the model writes the answer.
- Question
- Embed
- Search
- Prompt
- Answer
Summary
RAG has an indexing part, load, split, embed, and store, and an answering part, search, prompt, and generate. Next, setting up.
Key takeaways- Index ahead of time
- Search per question
- Generate from the chunks