The RAG Pipeline, Big Picture
Module 06 — The RAG Pipeline, Big Picture
Time to open the hood. This module gives you the full map of how a RAG system is built — every stage, named, in order. The next modules (07–10) zoom into each stage. Get the map first so the details have somewhere to live.
1. Two phases (recap, now with detail)
From Module 03: a RAG system has an indexing phase (prepare the library, done ahead of time) and a retrieval + generation phase (answer a question, done live). Let’s expand both into their real steps.
2. Phase A — Indexing (offline, runs in the background)
This turns a pile of raw documents into a fast, searchable library.
Raw documents
│
▼
[1] PARSE / EXTRACT → pull clean text out of PDFs, Word, HTML, slides, etc.
│
▼
[2] CLEAN → strip junk (nav bars, footers, boilerplate)
│
▼
[3] CHUNK → split each document into bite-sized passages
│
▼
[4] EMBED → turn each chunk into a list of numbers (a "vector")
│
▼
[5] STORE → save vectors + the text + metadata in a database
(vector index + keyword index + tags)
The output is your index (a.k.a. knowledge base): everything organized so that, given a question, you can quickly find the most relevant chunks. This runs once up front and then incrementally as documents are added, changed, or removed (Module 14).
We’ll cover parse/clean/chunk in Module 07 and embed/store in Module 08.
3. Phase B — Retrieval + Generation (online, runs per question)
This is what happens each time a user asks something.
User's question (the "query")
│
▼
[1] (optional) TRANSFORM QUERY → clean it up, expand, or rephrase for better search
│
▼
[2] EMBED THE QUERY → turn the question into a vector too
│
▼
[3] RETRIEVE TOP-K → find the K most relevant chunks
(using vectors AND keywords — "hybrid")
│
▼
[4] RERANK → re-score those candidates, keep the best few
│
▼
[5] ASSEMBLE THE PROMPT → put the best chunks + instructions + question together
│
▼
[6] GENERATE → the model writes a grounded answer
│
▼
[7] (optional) CITE / VERIFY → attach sources, check the answer is supported
- Query transform → Module 09 & 11.
- Embed + retrieve + rerank → Modules 08–09.
- Assemble + generate + cite → Module 10.
The phrase “top-K” just means “the K best matches,” where K is a number you choose (e.g. K=5). We’ll discuss picking K in Module 09.
4. The one insight that will save you the most time
Read this twice:
Most RAG quality problems are retrieval problems. And most retrieval problems are indexing problems — bad parsing or bad chunking. Generation is rarely the bottleneck.
Beginners obsess over the prompt and the model. Experts know that if the answer is wrong, it’s usually because the right chunk was never fetched — which usually traces back to messy text extraction or clumsy chunking upstream. So as we go, notice how much care the early stages (07–08) get. That’s where quality is won or lost.
A useful saying: “You can’t generate a good answer from text you never retrieved.”
5. A glossary of the pipeline words (so the next modules read easily)
- Index / knowledge base — your prepared, searchable collection of chunks.
- Chunk — a small passage of text (a paragraph or so) that you store and retrieve as a unit.
- Embedding / vector — a list of numbers representing a chunk’s meaning (Module 08).
- Retrieve — find the most relevant chunks for a query.
- Top-K — the K best-matching chunks.
- Rerank — a second, more careful scoring pass to reorder candidates.
- Metadata — extra tags stored with each chunk (source, date, author, section, permissions).
- Context — the chunks you place into the prompt for the model to read.
- Ground / grounded — basing the answer strictly on the provided context rather than the model’s memory.
6. How the rest of the tutorial maps to this picture
| Pipeline stage | Module |
|---|---|
| Parse, clean, chunk | 07 |
| Embed, store, vector search basics | 08 |
| Retrieve, hybrid search, rerank, choosing K | 09 |
| Assemble prompt, generate, cite | 10 |
| Smarter variations of all of the above | 11 |
| Measuring whether it works | 12 |
| Mistakes to avoid at each stage | 13 |
| Running it in the real world | 14 |
Check yourself
- List the five indexing steps and the main retrieval-generation steps in order.
- What does “top-K” mean?
- Finish the expert’s saying: “Most RAG quality problems are ___ problems, and most of those are ___ problems.”
- Why do experts spend so much attention on parsing and chunking?