Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
RAG from Scratch in Python: Build, Measure and Fix Retrieval
New

RAG from Scratch in Python: Build, Measure and Fix Retrieval

Build a RAG assistant in plain Python, then use a retrieval eval to find and fix why it answers wrong. Free and local.
Last updated 11/2026
English
English

What you'll learn

  • Build a working RAG pipeline in plain Python and numpy, with no framework
  • Measure retrieval with a golden set, hit rate@k and MRR
  • Choose a chunking strategy with data instead of guesses
  • Implement BM25, hybrid search (RRF), metadata filters and re-ranking, and test each one
  • Write a RAG prompt with citations and safe "I don't know" refusals
  • Run everything free and offline with Ollama and small open models

Course content

7 sections • 26 lectures • 1h 13m total length
  • What you'll build: a help-centre assistant that cites its sources2:54
  • Setup: Python, VS Code and Ollama2:41
  • Why RAG is confidently wrong2:54
  • How to get help1:17

Requirements

  • Basic Python: functions, lists, dictionaries and loops
  • A computer with Windows, macOS or Linux and 8 GB of RAM (no GPU, API key or credit card needed)
  • Python, VS Code and Ollama, installed step by step in lecture 1.2

Description

This course contains the use of artificial intelligence. The narration is an AI voice (Google Chirp 3 HD), and AI tools helped draft scripts and slides. Every line of code was written and run for real on screen against real local models, and every result you see is a real output, reviewed by the instructor.


Retrieval-augmented generation (RAG) is how you make an AI assistant answer from your own documents. It is also where most AI projects quietly go wrong: the assistant finds the wrong passage, or the right passage and still misreads it, and then answers with total confidence.


In this hands-on course you'll build a complete RAG assistant for a shop's help centre from an empty folder, in plain Python and numpy. No frameworks, no API keys, nothing to pay for: everything runs free on your laptop with Ollama and two small open models. Then you'll do what most tutorials skip: measure it, and fix it with evidence.


What makes this course different:

- Real screen-share coding in VS Code. Every number on screen comes from actually running the code.

- Honest results. On our data, hybrid search and LLM re-ranking made retrieval WORSE, and a simple metadata filter beat them both. You'll see exactly how the eval caught it.

- Short lectures (2-4 minutes), each ending with a recap: what we learned, keywords, and quick questions to test yourself.

- A real failure from the very first section: the assistant cites the right article and still gets the refund time wrong.


You will:

- Turn text into vectors by hand (bag of words), rank with cosine similarity, and see why word counts fail

- Switch to embeddings and watch "cracked plate" finally find the "damaged item" article

- Chunk long documents six ways and let the data pick the winner

- Build a golden set and a retrieval eval with hit rate@k and MRR in about 20 lines

- Implement BM25, hybrid search with reciprocal rank fusion, metadata filters and re-ranking, and keep only what beats the baseline

- Build the answer prompt with citations, test "lost in the middle" on your own model, and teach the assistant to say "I don't know"


Course files include all the code, the help-centre documents, the golden set, the setup checker and a cheat sheet PDF.

Who this course is for:

  • Developers building assistants or search over their own documents
  • Engineers whose RAG prototype gives confident wrong answers
  • QA and ML engineers who want numbers, not vibes, before shipping a RAG change