Leanpub Header

Skip to main content

Retrieval-Augmented Generation (The Course)

An Engineer's Guide to Building RAG Systems with Your Own Data

The instructor has published 100% of this course.Last updated on 2026-10-30

This course has interactive examples that teach software developers how to implement Retrieval-Augmented Generation applications that are production-ready, effective, and safe.

Minimum price

$129

$179

You pay

Author earns

$

Also available for 1 course credit with a Learner Membership

PDF
EPUB
WEB
About

About

About the Course

Most teams trying to ship a RAG system stall at the prototype stage. The notebook works, the demo wins the meeting, the system never reaches users at scale. The gap between "this works on my laptop" and "this runs reliably in production" is wide and full of engineering challenges. This course is about that gap.

It's written for engineers who need to ship something real. Not for researchers writing benchmarks, not for managers picking vendors. For the person at the keyboard who needs to make decisions about chunking strategy, vector store choice, evaluation methodology, and production operations, and who's tired of vendor-shaped blog posts and examples that don't survive a deploy.

Each chapter pairs concept with implementation. Real code on a real corpus, runnable end to end. The seven failure points of a RAG pipeline are introduced in chapter 1 and traced through every subsequent chapter, so you learn to recognize *where* things break, not just patch them when they do.

The course

Why standalone LLMs fail on private data, what RAG actually is, and the building blocks underneath: embeddings, chunking strategies, vector storage (FAISS vs pgvector vs Qdrant with measured benchmarks), and a complete ingestion pipeline that handles the messiness of real documents.

Wiring retrieval into generation. Sparse vs dense retrieval, BM25, hybrid search with reciprocal rank fusion, reranking with cross-encoders, query transformation patterns (multi-query, sub-question decomposition, HyDE). Every chapter measures the improvement instead of just describing it.

Evaluation done right (separate retrieval and generation metrics, RAGAS, ablation testing). Hardening the pipeline (observability, semantic caching, citation systems, embedding staleness, cost optimization, load testing). Advanced retrieval patterns (GraphRAG, Corrective RAG, Self-RAG) with honest takes on when each earns its keep. Then agentic RAG with realistic guardrails for production.

By the end you'll be able to

  • Choose a chunking strategy on retrieval evidence, not intuition
  • Pick FAISS, pgvector, or Qdrant based on your actual constraints
  • Build a RAG pipeline that handles real PDFs with OCR artifacts, encoding issues, and dirty markdown
  • Evaluate retrieval quality separately from generation quality, and prove your changes help
  • Add reranking, hybrid search, and query transformation when (and only when) they earn it
  • Catch the seven failure points before they reach production
  • Scale, monitor, and cost-optimize a RAG system that survives a deploy

Share this course

Instructor

About the Instructor

Jeroen Herczeg

Jeroen Herczeg is a senior software engineer who builds AI systems for production.

He has 20 years of engineering experience across software platforms, distributed systems, microservices, Kubernetes, and product teams. His current work focuses on retrieval-augmented generation, AI agent orchestration, and practical AI engineering.

Most recently, he built the orchestrator agent for the Google + BBC AI Agents demo at IBC2025, winner of the Broadcast Tech Innovation Award. His interest in AI goes back to 2017, when he completed Udacity’s Artificial Intelligence Nanodegree. Today, that work has evolved into a focus on production RAG systems and AI agent orchestration.

He writes about practical AI engineering at herczeg.be/blog and lives in Belgium.

Material

Course Material

  • 1 Preface

  • 1.1 Who I am

  • 1.2 Who it is for

  • 1.3 How to read it

  • 2 The problem RAG solves

  • 2.1 What an LLM can and cannot do

  • Exercise 1

  • 2.2 Limitations of a standalone LLM

  • Exercise 2

  • 2.3 The RAG mental model

  • Exercise 3

  • 2.4 The RAG pipeline end-to-end

  • Exercise 4

  • 2.5 RAG vs. fine-tuning vs. long-context prompting

  • Exercise 5

  • 2.6 The seven failure points

  • Exercise 6

  • 2.7 Common misconceptions

  • Exercise 7

  • 2.8 Seeing the difference: standalone LLM vs. RAG

  • 2.9 Summary

  • Exercise 8

  • Quiz 1

    3 attempts allowed

  • 3 Embeddings

  • 3.1 From words to vectors

  • Exercise 9

  • 3.2 The bi-encoder architecture

  • Exercise 10

  • 3.3 Generating embeddings locally

  • Exercise 11

  • 3.4 Generating embeddings via API

  • Exercise 12

  • 3.5 Cosine similarity and distance metrics

  • Exercise 13

  • 3.6 Visualizing embedding space with UMAP

  • Exercise 14

  • 3.7 Choosing an embedding model

  • 3.7.1 Tier 1: Hard constraints

  • 3.7.2 Tier 2: Retrieval quality

  • 3.7.3 Tier 3: Production costs

  • Exercise 15

  • 3.8 Similarity search from scratch

  • Exercise 16

  • 3.9 Summary

  • Exercise 17

  • Quiz 2

    3 attempts allowed

  • 4 Chunking strategies

  • 4.1 The chunk size tradeoff

  • Exercise 18

  • 4.2 Fixed-size chunking

  • Exercise 19

  • 4.3 Recursive character splitting

  • Exercise 20

  • 4.4 Semantic chunking

  • Exercise 21

  • 4.5 Document-structure-aware chunking

  • Exercise 22

  • 4.6 Contextual chunking

  • Exercise 23

  • 4.7 Comparing strategies: A retrieval test

  • Exercise 24

  • 4.8 Summary

  • Exercise 25

  • Quiz 3

    3 attempts allowed

  • 5 Vector storage and indexing

  • Exercise 26

  • 5.1 Exact vs. approximate nearest neighbor

  • Exercise 27

  • 5.2 The speed-accuracy-memory tradeoff

  • Exercise 28

  • 5.3 Choosing a vector store

  • Exercise 29

  • 5.4 How HNSW works

  • Exercise 30

  • 5.5 Building a FAISS index from scratch

  • Exercise 31

  • 5.6 pgvector: Vectors in PostgreSQL

  • Exercise 32

  • 5.7 Qdrant: A purpose-built vector database

  • Exercise 33

  • 5.8 Tuning index parameters

  • Exercise 34

  • 5.9 Putting it all together: the comparison benchmark

  • Exercise 35

  • 5.10 Summary

  • Exercise 36

  • Quiz 4

    3 attempts allowed

  • 6 Building the ingestion pipeline

  • 6.1 The ingestion flow

  • Exercise 37

  • 6.2 Parsing real-world documents

  • Exercise 38

  • 6.3 Text cleaning and normalization

  • Exercise 39

  • 6.4 The full pipeline: Parse, clean, chunk, embed, store

  • Exercise 40

  • 6.5 Metadata extraction and storage

  • Exercise 41

  • 6.6 Idempotent re-ingestion

  • Exercise 42

  • 6.7 Running the complete pipeline

  • Exercise 43

  • 6.8 Summary

  • Exercise 44

  • Quiz 5

    3 attempts allowed

  • 7 Hybrid retrieval

  • Exercise 45

  • 7.1 Keyword retrieval and the BM25 mental model

  • Exercise 46

  • 7.2 Adding a search vector to the chunks table

  • Exercise 47

  • 7.3 Side by side: each retriever fails the other’s queries

  • Exercise 48

  • 7.4 Hybrid retrieval as candidate generation

  • Exercise 49

  • 7.5 Filters as candidate-set scoping

  • Exercise 50

  • 7.6 Putting it together: hybrid retrieval over the corpus

  • Exercise 51

  • 7.7 Summary

  • Exercise 52

  • Quiz 6

    3 attempts allowed

  • 8 Your first RAG pipeline

  • 8.1 Selecting context from the candidate pool

  • Exercise 53

  • 8.2 Building the prompt

  • Exercise 54

  • 8.3 The complete pipeline

  • 8.4 Five queries: where the pipeline succeeds and fails

  • Exercise 55

  • 8.5 The failure catalog

  • Exercise 56

  • 8.6 What this pipeline cannot do yet

  • Exercise 57

  • 8.7 Summary

  • Exercise 58

  • Quiz 7

    3 attempts allowed

  • 9 Reranking

  • Exercise 59

  • 9.1 Why first-stage retrieval optimizes for recall

  • Exercise 60

  • 9.2 Bi-encoder versus cross-encoder

  • Exercise 61

  • 9.3 Adding a local reranker with bge-reranker-v2-m3

  • Exercise 62

  • 9.4 Choosing K and N

  • Exercise 63

  • 9.5 Latency and the cost of cross-encoders

  • Exercise 64

  • 9.6 Did reranking actually improve answers?

  • Exercise 65

  • 9.7 When reranking is not worth it

  • Exercise 66

  • 9.8 The pipeline so far

  • 9.9 Summary

  • Exercise 67

  • Quiz 8

    3 attempts allowed

  • 10 Query transformation

  • Exercise 68

  • 10.1 Where query transformation belongs

  • 10.2 Query rewriting

  • Exercise 69

  • 10.3 HyDE: search with a hypothetical answer

  • Exercise 70

  • 10.4 Multi-query expansion

  • Exercise 71

  • 10.5 Decomposition

  • Exercise 72

  • 10.6 When transformation hurts

  • Exercise 73

  • 10.7 A technique hierarchy

  • Exercise 74

  • 10.8 Summary

  • Exercise 75

  • Quiz 9

    3 attempts allowed

  • 11 Evaluating RAG systems

  • Exercise 76

  • 11.1 Two evaluation surfaces

  • Exercise 77

  • 11.2 Building an evaluation set

  • Exercise 78

  • 11.3 Retrieval metrics

  • Exercise 79

  • 11.4 Generation metrics

  • Exercise 80

  • 11.5 The ablation table

  • 11.5.1 Reading an ablation without overfitting to it

  • Exercise 81

  • 11.6 Regression tracking

  • Exercise 82

  • 11.7 What evaluation will not tell you

  • Exercise 83

  • 11.8 Summary

  • Exercise 84

  • Quiz 10

    3 attempts allowed

  • 12 Hardening for production

  • Exercise 85

  • 12.1 Stage-level observability

  • Exercise 86

  • 12.2 Tracing across stages

  • Exercise 87

  • 12.3 Failure modes and graceful degradation

  • Exercise 88

  • 12.4 Configuration and secrets

  • Exercise 89

  • 12.5 Model versioning and the silent-rebuild trap

  • Exercise 90

  • 12.6 Security boundaries in RAG systems

  • Exercise 91

  • 12.7 Deploying changes safely

  • Exercise 92

  • 12.8 The production baseline

  • Exercise 93

  • 12.9 Summary

  • Exercise 94

  • Quiz 11

    3 attempts allowed

  • 13 Advanced retrieval patterns

  • Exercise 95

  • 13.1 Parent-document retrieval

  • Exercise 96

  • 13.2 Contextual retrieval

  • Exercise 97

  • 13.3 Graph-based retrieval

  • Exercise 98

  • 13.4 ColBERT and late interaction

  • Exercise 99

  • 13.5 The complexity test

  • Exercise 100

  • 13.6 Summary

  • Exercise 101

  • Quiz 12

    3 attempts allowed

  • 14 Agentic RAG

  • 14.1 Retrieval as a tool call

  • Exercise 102

  • 14.2 Multi-step reasoning loops

  • Exercise 103

  • 14.3 Bounding agentic loops

  • Exercise 104

  • 14.4 Observability for agents

  • Exercise 105

  • 14.5 When agentic RAG is worth it

  • Exercise 106

  • 14.6 Summary

  • Exercise 107

  • Quiz 13

    3 attempts allowed

  • 15 Closing

  • 15.1 What stays true

  • Exercise 108

  • 15.2 What does not work

  • 15.3 What to do next

  • Quiz 14

    3 attempts allowed

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub