Skip to Content
RAG from First Principles
book

RAG from First Principles

by Jia Huang
May 2026
Intermediate
492 pages
12h 5m
English
Packt Publishing

Overview

A rigorous, code-first guide to RAG engineering by a bestselling AI author. Master data ingestion, chunking, embeddings, vector storage, hybrid retrieval, reranking, and evaluation from the ground up. Free with your book: DRM-free PDF version + access to Packt's next-gen Reader*

Key Features

  • Engineer RAG systems layer by layer, from ingestion to evaluation
  • Master hybrid retrieval, reranking, and index optimization strategies
  • Learn through a dialogue-driven, code-first teaching style used by 10,000+ of students

Book Description

Most developers can spin up a RAG pipeline in an afternoon using LangChain or LlamaIndex. Far fewer understand why retrieval fails or how to fix it. This book is for those who want to go deeper.

RAG From First Principles dismantles the retrieval-augmented generation stack layer by layer, explaining how documents are ingested and parsed, why chunking strategy directly impacts answer quality, how embedding models encode meaning, what happens inside a vector database, and how sparse and dense retrieval interact in a hybrid system. Written by Jia Huang, a research engineer and bestselling AI author, it brings both research depth and production experience to one of AI's most critical engineering disciplines.

Structured as a progressive dialogue between a seasoned engineer and two students, the book surfaces the questions practitioners actually ask. Each chapter builds on the last, covering topics from data import and chunking to embedding selection, index design, hybrid search, and post-retrieval processing, before moving on to response generation, evaluation, and advanced paradigms including GraphRAG, Agentic RAG, and Modular RAG.

By the end, you'll have the architectural understanding to optimize, debug, and extend your RAG systems with confidence.

*Email sign-up and proof of purchase required

What you will learn

  • Parse and ingest diverse document types like PDFs, tables, images, web pages, and structured data
  • Apply the right chunking strategy for your content type and retrieval goals
  • Select, compare, and fine-tune embedding models for your domain
  • Design vector indexes and choose the right similarity metrics for production use
  • Improve result quality with reranking methods including RRF, cross-encoders, and ColBERT
  • Integrate retrieval results into generation pipelines using prompt engineering and Self-RAG

Who this book is for

This book is for AI engineers, ML practitioners, and software developers building LLM-powered applications who want a deeper understanding of how retrieval actually works, not just how to call a framework. It is ideal for readers who have built a basic RAG pipeline and now want architectural clarity, optimization strategies. Technical leads and architects designing production AI systems will find its systematic treatment of indexing, hybrid search, reranking, and evaluation particularly valuable. Familiarity with Python and foundational LLM concepts is assumed.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning LangChain

Learning LangChain

Mayo Oshin, Nuno Campos
An Illustrated Guide to AI Agents

An Illustrated Guide to AI Agents

Maarten Grootendorst, Jay Alammar
AI Engineering

AI Engineering

Chip Huyen
AI Engineering

AI Engineering

Chip Huyen

Publisher Resources

ISBN: 9781835888667