This repository contains the code for the O'Reilly book Hands-On RAG for Production, by Ofer Mendelevitch and Forrest Sheng Bao.
Retrieval-augmented generation is easy to prototype and hard to ship. The book walks through every phase of building a RAG application — parsing, chunking, embeddings, and vector search, through to agentic RAG, multimodal RAG, and GraphRAG — and is honest about the trade-offs at each step. This repository is the code: 35 notebooks you can run locally or in Google Colab.
- Book site — https://ofermend.github.io/hands-on-rag/
- O'Reilly — read online
- Amazon — print and Kindle
- Bookshop.org — supports independent bookstores
- ISBN 979-8-3416-2171-8
Every notebook has an "Open in Colab" badge at the top, so you can run it without
installing anything. To run locally, install the chapter's requirements.txt first.
| Chapter | Notebooks | Folder |
|---|---|---|
| 1. Introduction to Retrieval-Augmented Generation (RAG) A first end-to-end RAG pipeline |
sample-rag.ipynb · Colab — End-to-end RAG with LangChain: load, split, embed, store, query | chapter1/ |
| 2. The Base RAG Stack Parsing, chunking, embeddings, vector search, generation |
parse-pdf.ipynb · Colab — PDF text extraction with PyMuPDF parse-docx.ipynb · Colab — DOCX parsing with python-docx parse-in-llm.ipynb · Colab — Using an LLM to parse documents embedding.ipynb · Colab — Sentence embeddings and similarity pgvector-simple.ipynb · Colab — Vector search in PostgreSQL with pgvector sqlite-vec.ipynb · Colab — Vector search with the SQLite-vec extension generative-llms.ipynb · Colab — Generation with Claude |
chapter2/ |
| 3. Scaling Your RAG Stack Parsing at scale, reranking, guardrails, hallucinations |
split-pdf.ipynb · Colab — Splitting large PDFs by page count before parsing parse-tables.ipynb · Colab — Extracting tables from PDFs with Docling reranking.ipynb · Colab — Reranking retrieved results guardrails.ipynb · Colab — Input and output guardrails hallucinations.ipynb · Colab — Detecting and handling hallucinations |
chapter3/ |
| 4. Deploying RAG to Production Caching for latency and cost, redaction for sensitive data |
caching.ipynb · Colab — Exact-match and semantic caching with Redis redaction.ipynb · Colab — Redacting sensitive data |
chapter4/ |
| 5. The RAG Platform Using a managed RAG platform instead of assembling one |
vectara-ingest.ipynb · Colab — Ingesting documents into Vectara vectara-list-docs.ipynb · Colab — Listing and managing indexed documents vectara-query.ipynb · Colab — Querying Vectara |
chapter5/ |
| 6. Evaluating Your RAG Application LLM-as-a-judge and retrieval metrics |
llm-as-a-judge.ipynb · Colab — Scoring RAG answers with an LLM judge metrics.ipynb · Colab — Retrieval and generation evaluation metrics umbrela.ipynb · Colab — UMBRELA 0-3 passage relevance scoring |
chapter6/ |
| 7. From RAG to AI Agents Tool calling, single agents, multi-agent systems |
tool-calling.ipynb · Colab — LLM tool/function calling react-agent-langchain.ipynb · Colab — ReAct agent with LangChain function-agent-llamaindex.ipynb · Colab — Function-calling agent with LlamaIndex vectara-agent.ipynb · Colab — RAG agent with Vectara crewai-multi-agent.ipynb · Colab — Multi-agent system with CrewAI |
chapter7/ |
| 8. Multimodal RAG Tables, images, and audio |
multi-page-tables.ipynb · Colab — Stitching tables that span page breaks simple-table-chunking.ipynb · Colab — Table-to-text conversion and chunking pitfalls image-rag-langchain.ipynb · Colab — Image RAG with LangChain and Docling image-retrieval-siglip.ipynb · Colab — Image retrieval with SigLIP audio-transcribe.ipynb · Colab — Audio transcription and indexing |
chapter8/ |
| 9. Knowledge-Enhanced RAG Knowledge graphs and GraphRAG |
create-graph.ipynb · Colab — Building a knowledge graph from movie data graph-query.ipynb · Colab — Querying the knowledge graph with Cypher graphrag-create.ipynb · Colab — Building an index with Microsoft GraphRAG graphrag-query.ipynb · Colab — Querying with Microsoft GraphRAG |
chapter9/ |
| 10. The Future of RAG | No code | — |
Set the keys as environment variables before starting Jupyter. Chapters that need a local service won't run in Colab as-is — use those locally.
| Chapter | API keys | Local services |
|---|---|---|
| 1 | OPENAI_API_KEY |
— |
| 2 | ANTHROPIC_API_KEY |
PostgreSQL with the pgvector extension, for pgvector-simple.ipynb |
| 3 | OPENAI_API_KEY |
— |
| 4 | OPENAI_API_KEY |
Docker — caching.ipynb starts and stops a Redis container itself |
| 5 | VECTARA_API_KEY |
— |
| 6 | OPENAI_API_KEY |
— |
| 7 | OPENAI_API_KEY, ANTHROPIC_API_KEY, VECTARA_API_KEY |
— |
| 8 | OPENAI_API_KEY |
— |
| 9 | OPENAI_API_KEY, NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD |
Neo4j, local or in Docker |
The notebooks call paid APIs, so running them costs money. Chapter 9's GraphRAG indexing makes the most LLM calls of any example here — check your usage before re-running it.
Python 3.10+.
git clone https://github.com/ofermend/hands-on-rag.git
cd hands-on-rag
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activateEach chapter has its own requirements.txt — install the one for the chapter you're
running rather than everything at once:
pip install -r chapter1/requirements.txt
export OPENAI_API_KEY="your-key-here"
jupyter labThe requirements.txt at the repo root holds the dependencies shared across chapters.
@book{mendelevitch2026handsonrag,
author = {Mendelevitch, Ofer and Bao, Forrest Sheng},
title = {Hands-On RAG for Production: Design, Develop, and Deploy
Production-Ready RAG Applications},
publisher = {O'Reilly Media},
year = {2026},
isbn = {979-8-3416-2171-8}
}Issues and pull requests are welcome. If a notebook fails, open an issue with the chapter and notebook name, the error message, and your Python version and OS.
Apache License 2.0 — see LICENSE. Free to use, modify, and distribute for personal and commercial purposes.
