Skip to content

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.

Offline: indexing (runs on a schedule)DocumentsPDF, HTML, ticketsParselayout, tables, OCRChunk+ page refs, metadataIndexBM25 + vectorsOnline: every questionQuestion“How do I claim…”Rewritestandalone queryRetrievetop k by scoreRe-rankcross-encoderGenerateanswer from contextCite / not foundverify groundingMeasure each stage separately: retrieval with recall@k / nDCG, answers with faithfulness
Most bad answers start upstream: a parsing, chunking or retrieval miss that generation can’t fix.

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.

Common misconception: “RAG is solved; just use a framework.” Frameworks give you the boxes, not the choices inside them. Most production RAG problems are parsing, chunking, retrieval and evaluation problems that no default setting fixes.

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.

Keyword vs meaning: retrieval playgroundPick a question or type your own, mark which documents are relevant, then slide between BM25 and dense retrieval.
recall@3 1.00MRR 1.00nDCG@3 1.001 relevant document marked
Rank (faded = not retrieved)Relevant?DocumentBM25 → dense → blended score
1Travel 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
2Salary 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
3Annual 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
4Holiday calendar
Public holidays for 2027 by office location. Optional holidays need manager approval.
BM25 0.00 · dense 0.00 · 0.00
5Laptop 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
6Password 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
7Work 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
8Parental 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
  1. “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?
  2. “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?
  3. “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?
  4. “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?
  5. Find one blend where every question gets recall@3 = 1. That’s why production systems use hybrid search.
  6. 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.

In production: Keep a file docs/baseline.md with today’s scores. In interviews, “recall@5 went from 0.58 to 0.86 and here is why” beats any list of tools.

Hands-on: coding window

The coding window and the full VS Code lab are available after you sign in.

Sign in to code

Labs

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

Further reading

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

1. Which half of RAG runs offline?
2. Why build and score a naive baseline first?
3. The question “can I get my money back?” fails against a chunk about “reimbursement”. Most likely cause?
4. What should the assistant say when the documents don’t cover a question?
5. Which modules does the diagnostic say everyone should do?

Interview questions

  1. Walk me through a RAG pipeline end to end. Where does it usually break first?
  2. How would you measure whether a change to your RAG system helped?
  3. When would you not use RAG at all?
  4. A user says the assistant gave a confident wrong answer. How do you debug it?
  5. 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).