Lesson 1: The pipeline

Eight stages, one diagram. Know what each stage is for and what breaks when it is skipped.

~12 minutes. Start of the course. Reference: pipeline cheat sheet.

The problem RAG solves

A language model knows what it was trained on: public text, frozen at a cutoff. It does not know the listing that went live an hour ago, a client's visit history, or the clause on page 31 of a signed contract. RAG bolts a second memory on: at question time, retrieve the relevant pieces from an index of that private, current data and hand them to the model as context. Lewis et al. named the pattern in 2020: parametric memory (the model) plus non-parametric memory (a retrieved index).[1]

Running example for the whole course: a real-estate platform where agents ask questions over listings, CRM records (contacts, requests, visits) and documents (contracts, energy certificates, brochures).

The diagram

offline, per document change:   INGEST -> CHUNK -> EMBED -> INDEX
online, per question:           QUERY -> RETRIEVE -> RERANK -> GENERATE

The offline half runs whenever data changes; the online half runs per question, in a few hundred milliseconds. Every stage exists because skipping it produces a specific, recognisable failure - the cheat sheet lists all eight. Two examples: skip chunking and you index 40-page contracts whole, so retrieval returns documents nobody can fit in a prompt; skip rerank and the right chunk sits at rank 18 where the generator never uses it.

Trace one question

"What did the buyer of Kortrijksesteenweg 12 agree about the completion date?"

  1. Query: detect an exact token (the address) and an intent (contract clause).
  2. Retrieve: search the index; the sale contract's chunks for that address come back.
  3. Rerank: the chunk containing the completion clause rises to the top.
  4. Generate: the model answers from that chunk, citing it - or says "not found" if retrieval came back empty.

Everything the answer can possibly contain was decided before generation. That is the central discipline of RAG: the generator can only be as good as what retrieval hands it.

When RAG, when more

A single retrieve-then-generate pass is a workflow: predictable, cheap, debuggable. Reach for an agentic loop (the model deciding to search again, reformulate, or drill into a document) only when single-pass quality measurably falls short - Anthropic's guidance on workflows versus agents applies directly.[2] This course builds the single loop well first.

Retrieval practice

Do these from memory, before scrolling up.

Your win: you can draw the eight stages from memory and, for any bad answer, say which half of the diagram - offline or online - you would inspect first.

Primary source

Read the abstract and section 2 of Lewis et al. 2020 - ten minutes, and the vocabulary of every later paper comes from it. All sources are annotated in RESOURCES.md.

Anything unclear? Ask your teaching agent - it wrote this lesson and can go deeper on any point.