Skip to main content
Module 1: RAG Foundations

The RAG pipeline, stage by stage

The seven stages from raw documents to a grounded answer.

A RAG system is a pipeline. Knowing the stages — and that each is a place quality can be won or lost — is the map for the whole course.

1. Ingestion / parsing. Load and clean your source documents (PDFs, HTML, database rows, code). This is underrated: if your PDF parser mangles tables or drops headings, everything downstream suffers. Garbage in, garbage retrieved.

2. Chunking. Split documents into retrievable units, usually a few hundred tokens each. How you split matters enormously (Module 2) — chop badly and you sever the context that makes a passage meaningful.

3. Embedding. Convert each chunk into a vector — a list of numbers that encodes its meaning — using an embedding model. Similar meanings produce nearby vectors.

4. Indexing. Store those vectors in a vector database with an approximate-nearest-neighbor index (usually HNSW) plus metadata. Often you build a keyword (BM25) index alongside — you'll want both.

5. Retrieval. At query time, embed the question and find the most similar chunks (and/or keyword-match them). This is the "R" in RAG.

6. Reranking. Take the retrieved candidates and rescore them with a more precise model, keeping only the best few. This two-stage "retrieve wide, rerank tight" pattern is one of the biggest quality levers (Module 2).

7. Generation. Put the top chunks in the prompt and have the model answer — ideally citing which chunk each claim came from.

The classic hybrid version, in Anthropic's own steps: chunk → build both keyword (BM25) and semantic indexes → get top matches from each → fuse and dedupe → add the top-K to the prompt.

Two things to internalize now. First, retrieval quality is where most RAG systems live or die — a perfect model can't answer from chunks you failed to fetch. Second, the pipeline is tunable at every stage, which is why evaluation (Module 3) matters: you'll be changing chunk sizes, swapping embedding models, and adding rerankers, and you need to measure whether each change actually helped. Keep this pipeline in your head; every lesson slots into one of these stages.

Try it

Draw the seven stages for a concrete corpus (say, your product docs). At each stage, note one thing that could go wrong and degrade the final answer.

Stay in the loop

Enjoying the free lessons? Get an email when we publish new courses and updates — no spam, unsubscribe anytime.

Discussion (0)

Ask a question or share what worked for you. Comments are reviewed before they appear.

Log in to join the discussion and ask questions about this lesson.

No comments yet. Be the first to start the discussion!