Courses / RAG Systems / Module 0
Module 0: Bridge: RAG baseline refresher and diagnostic
6 h · theory 2 · hands-on 2 · project 1 · revision 1
You will be able to
- Rebuild a minimal RAG pipeline from memory
- Call an LLM API and an embedding model from Python
- Score yourself on the diagnostic and pick your starting module
Capstone increment: Capstone repo with a naive baseline (/ask over a sample corpus) to beat in every later module.
Job-description skills: RAG, LLM APIs · Lab tools: python3.12, sentence-transformers, fastapi
1. The pipeline you already know
Retrieval-augmented generation answers a question in two halves. Offline, you parse documents, split them into chunks, embed each chunk and store it in an index. Online, you embed the question, retrieve the closest chunks and ask a model to answer from them, citing what it used.
This course takes each box apart and rebuilds it to production quality. Before that, you need a baseline you built yourself and a number to beat. A team that can’t say what its baseline scores can’t say whether any change helped.
2. Rebuild the baseline from memory
Write the naive pipeline without a framework: split on sentences, embed with a small open model, keep vectors in a NumPy array, take the top 3 by cosine similarity, and put them in a prompt that says to answer only from the context and to say “not found” otherwise.
It will work on easy questions and fail in instructive ways: paraphrases that share no words with the answer, answers split across two chunks, tables flattened into nonsense, and confident answers to questions the documents never cover. Each failure maps to a module in this course.
3. Feel the difference between keyword and meaning
Type questions into the playground and compare keyword scoring with embedding similarity. Look for a question where the two disagree; that disagreement is why Module 6 combines them.
| Rank (faded = not retrieved) | Relevant? | Document | BM25 → dense → blended score |
|---|---|---|---|
| 1 | Travel reimbursement Claim travel expenses with form HR-17 within 30 days. Attach receipts for flights, trains and hotels. | BM25 1.00 · dense 0.00 · 0.50 | |
| 2 | Salary and payslips Salary is credited on the last working day. Download payslips and Form 16 from the payroll portal. | BM25 0.44 · dense 0.00 · 0.22 | |
| 3 | Annual leave policy Employees get 24 days of annual leave. Apply for leave in the HR portal at least two weeks ahead. | BM25 0.00 · dense 0.00 · 0.00 | |
| 4 | Holiday calendar Public holidays for 2027 by office location. Optional holidays need manager approval. | BM25 0.00 · dense 0.00 · 0.00 | |
| 5 | Laptop and equipment Each employee receives a laptop. Report a lost or stolen device to IT security within 24 hours. | BM25 0.00 · dense 0.00 · 0.00 | |
| 6 | Password and MFA rules Use a password manager and turn on MFA. Never share one-time codes, even with IT. | BM25 0.00 · dense 0.00 · 0.00 | |
| 7 | Work from home Hybrid staff may work remotely up to three days a week. Home internet is reimbursed up to Rs 1,000 a month. | BM25 0.00 · dense 0.00 · 0.00 | |
| 8 | Parental leave Birth parents get 26 weeks of paid leave; other parents get 4 weeks. Tell HR 8 weeks before the leave starts. | BM25 0.00 · dense 0.00 · 0.00 |
Guided experiments
- “where is form HR-17”: slide to dense only. The travel document drops out and recall falls to 0. Why does BM25 find it instantly?
- “vacation days per year”: slide to BM25 only. It can only match the word “days”, so the holiday calendar is missed. Which word in the question does no document contain?
- “time off when we have a baby”: BM25 only retrieves nothing at all. Slide to dense only: both leave policies come back. What did the dense side “know” that BM25 didn’t?
- “my computer was stolen” at the middle setting: try k = 1, then k = 2. Recall@k and nDCG change while MRR stays at 1. What does each metric reward?
- Find one blend where every question gets recall@3 = 1. That’s why production systems use hybrid search.
- Type your own question and tick the relevant documents yourself. That is how a golden set is built.
4. Diagnostic: where should you start?
Score yourself honestly. If you can explain BM25 and compute recall@k and MRR by hand, skim Module 1. If you have parsed scanned PDFs with OCR and kept page numbers, skim Module 2. If you have chosen a chunk size from measurements rather than habit, skim Module 3. Everyone should do Modules 6, 8 and 9: hybrid search, evaluation and grounding are where most teams fall short.
Prerequisites from the GenAI & LLM course: calling a model API, structured output with Pydantic, embeddings and cosine similarity, and a basic RAG pipeline. If any of those is shaky, revisit that course’s Modules 2, 4, 5 and 6 first.
5. The capstone: a knowledge assistant you can defend
You will build an assistant that answers questions over company policies, manuals and tickets with inline citations and an explicit “not found” answer. It will use hybrid search with re-ranking, enforce per-document permissions, run evals in CI on every pull request and be deployed at a public URL.
The starter repo already has a FastAPI service with /health, an /ask endpoint that honestly returns not_found, and a retrieval eval endpoint. Every module replaces one piece and reports its score against the baseline.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 0.1: Rebuild the baseline
Replace the hashed bag-of-words with sentence-transformers (all-MiniLM-L6-v2 or bge-small-en-v1.5), index 20 sample policy pages and wire retrieval into the starter repo’s /ask endpoint with a prompt that cites chunk numbers.
Expected: POST /ask returns an answer with [n] citations for covered questions and not_found for an uncovered one.
Lab 0.2: Take the diagnostic
Answer the checkpoint quiz without notes, then write down which modules you will skim and which you will study in full, with one sentence of evidence for each skip.
Expected: A short study plan in progress/plan.md that you can show a mentor.
Lab 0.3: Capstone repo (capstone increment)
Push the starter repo to your GitHub, get CI green, and record the baseline’s recall@3 and MRR on a 10-question golden set in docs/baseline.md.
Expected: A public repo with a passing CI badge and a baseline you will beat in every later module.
Go deeper
Videos
- Learn RAG From Scratch – Python AI Tutorial from a LangChain Engineer · freeCodeCamp.org · ~153 min. Builds every RAG piece from scratch, including query translation, routing and indexing tricks this course goes deeper on.
- Building Production-Ready RAG Applications: Jerry Liu · AI Engineer · ~19 min. A short tour of why naive RAG fails in production and what to fix first, from the creator of LlamaIndex.
- Systematically Improving RAG applications · Jason Liu · ~11 min. The mindset of this course: measure retrieval, find the failure segments, fix them one at a time.
Further reading
- Paper Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks · Lewis et al., NeurIPS 2020. The paper that named RAG: a retriever and a generator trained to work together.
- Paper Seven Failure Points When Engineering a Retrieval Augmented Generation System · Barnett et al., 2024. A short list of the ways real RAG systems fail, from missing content to wrong format.
- Article Contextual retrieval · Anthropic. Prepending chunk-specific context before embedding and BM25, with measured drops in retrieval failures.
GitHub repositories
- langchain-ai/rag-from-scratch: The notebooks behind the freeCodeCamp video. Rebuild one notebook without LangChain to prove you understand it.
- run-llama/llama_index: docs/examples/low_level: building a RAG pipeline from primitives (ingestion, retriever, response synthesis).
- huggingface/sentence-transformers: The quickstart and the semantic search examples; you will use this library in Modules 1, 4 and 6.
- fastapi/fastapi: The tutorial sections on request bodies and dependencies; the capstone API is FastAPI.
Checkpoint quiz
Interview questions
- Walk me through a RAG pipeline end to end. Where does it usually break first?
- How would you measure whether a change to your RAG system helped?
- When would you not use RAG at all?
- A user says the assistant gave a confident wrong answer. How do you debug it?
- What is in your golden set, and how did you build it?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).