Large language models are powerful, but they forget, hallucinate and know nothing about your private documents. This book explains, step by step, how Retrieval Augmented Generation fixes that by pairing a model with a search over your own data. You will learn embeddings, chunking, vector search, prompt assembly and evaluation, then build and improve a working RAG pipeline in code. Case studies and exercises show how real teams take RAG from prototype to production.
Level: beginner · 11 chapters · about 6 h · Free · Created by Sandip Das
What you will learn
Explain what Retrieval Augmented Generation is, why it exists and when to use it instead of fine-tuning or plain prompting
Describe how embeddings and vector similarity search let a system find relevant text
Prepare documents for retrieval by loading, cleaning and chunking them sensibly
Build a working end-to-end RAG pipeline in Python with an embedding model, a vector store and an LLM
Improve retrieval quality with techniques such as hybrid search, metadata filtering and re-ranking
Evaluate a RAG system's retrieval and answer quality and troubleshoot common failures like hallucination and missed context
Plan the move from prototype to production, covering cost, latency, security and keeping data fresh
Contents
Part 1. Part I: Foundations
The LLM ideas a beginner needs before RAG makes sense, and what RAG is, why it exists and when to choose it.
What Language Models Can and Cannot Do(25 min)· free preview Introduces tokens, context windows, prompting and hallucination in plain terms, and shows why models forget, guess and know nothing about private data. Covers how long contexts degrade and why curating context matters.
Retrieval Augmented Generation: The Big Picture(30 min) Explains where RAG came from, the difference between parametric and non-parametric memory, and the indexing, retrieval, augmentation and generation stages, with a diagram of the full flow. Compares RAG with plain prompting and fine-tuning.
Part 2. Part II: The Building Blocks of Retrieval
How text becomes searchable: embeddings, document preparation and chunking, and vector stores.
Embeddings and Semantic Similarity(30 min) Explains embeddings as lists of numbers whose distances reflect relatedness, symmetric versus asymmetric search, how to generate embeddings with hosted or local models, and how to choose a model using benchmark leaderboards.
Preparing Documents: Loading, Cleaning and Chunking(35 min) Covers extracting text from PDFs and other formats, repairing reading order, cleaning text, and the main chunking strategies (fixed-size with overlap, recursive, sentence-based, structure-aware, semantic), plus enriching chunks with titles and context.
Vector Stores and Vector Search(30 min) Explains nearest-neighbour search, exact versus approximate indexes and distance metrics, then compares a library (FAISS), an embedded database (Chroma) and a Postgres extension (pgvector) with short code examples.
Part 3. Part III: Building a RAG Pipeline
Turning retrieved text into grounded answers and assembling a complete working pipeline in Python.
Prompt Assembly and Grounded Answers(30 min) Shows how to structure a RAG prompt with a system message, context block and question, how ordering of chunks affects accuracy, and how to make answers grounded and auditable with citations, quotes and permission to say 'I don't know'.
Building Your First RAG Pipeline in Python(40 min) A step-by-step worked project: load and chunk documents, embed them, store them in a vector store, retrieve for a question, assemble the prompt and call an LLM, using code that works with either a hosted API or a local OpenAI-compatible server.
Part 4. Part IV: Improving and Evaluating RAG
Techniques that raise retrieval quality and methods to measure and troubleshoot a RAG system.
Better Retrieval: Hybrid Search, Filters, Re-ranking and Query Rewriting(35 min) Adds keyword search alongside vectors with reciprocal rank fusion, metadata filtering for hard constraints, two-stage retrieval with cross-encoder re-rankers, and query rewriting techniques such as HyDE, each added to the pipeline from the previous part.
Evaluating and Troubleshooting a RAG System(35 min) Builds a small test set and measures retrieval with precision@K, recall@K and MRR, and generation with faithfulness and relevance metrics, including LLM-as-a-judge and its biases. Ends with a troubleshooting guide for hallucination, missed context and lost-in-the-middle failures.
Part 5. Part V: Production and Beyond
Taking RAG from prototype to production, and a first look at agentic and graph-based RAG through real case studies.
From Prototype to Production(35 min) Covers cost and latency control including prompt caching, keeping the index fresh as documents change, document-level access control, defending against prompt injection and vector-store weaknesses, and monitoring a live system.
Beyond Basic RAG: Agentic and Graph RAG in Real Applications(35 min) Introduces agentic RAG, where retrieval is a tool in a reasoning loop, and GraphRAG, which builds a knowledge graph for whole-corpus questions, then studies real deployments in customer support to show how teams chose and adapted these designs.