Leanpub Header

Skip to main content

AI Engineering Visualized, Volume 3: RAG & Knowledge Systems

A Visual Guide to RAG and Knowledge Systems

AI Engineering Visualized, Volume 3: RAG & Knowledge Systems
This book is 100% completeLast updated on 2026-11-11

RAG answers you can trace to a source: ingestion, permissions, hybrid search, reranking, evals and regression gates, drawn and built in Python.

Minimum price

$19.99

$29.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
About

About

About the Book

The best match was true once. Now it's wrong.

Asha asks whether order #2001 can still be refunded. The best match in the assistant's new search index is an old ticket saying the parcel is still on its way. That ticket was true when it closed. Now it's stale: the order record says #2001 was delivered. A better search would still find that ticket. The code around the search decides which sources may answer, and this book builds that code.

For a retrieval feature whose answers you now have to trust. The sources are manuals with tables, an order database, past tickets and rules that change by region. Volume 1 built the Northwind Goods support assistant with a small hybrid search over one policy page and nine handbook passages. Volume 2 put a harness around it so it could act. Volume 3 gives it real knowledge and makes every answer traceable to a source.

One assistant, carried forward. Chapter by chapter you build the knowledge system behind the model:

  • a contract and an access path for every source, and an ingestion pipeline with stable ids, provenance and safe reruns
  • documents with tables and scans, cut into chunks that know where they apply
  • permissions from the session, checked at search and at every later step, with poisoned pages treated as a signal and never as the boundary
  • embeddings and vector indexes, hybrid search with an exact-match lane, reranking, and queries that are rewritten, routed and decomposed
  • a clear rule for which source wins when two disagree, when to abstain, and an evidence pack the model can cite
  • safe, scoped SQL over records, and multi-hop retrieval over a knowledge graph
  • index updates, deletes and rebuilds, retrieval metrics and faithfulness judges, and test sets with a regression gate

A capstone appendix then sends one ticket through every stage on one corpus.

Visual first. Every idea is one of 35 named mental models, such as The Ingestion Conveyor, Small to Find, Big to Read, The Two-Stage Funnel, The Evidence Pack, The Stale Index or The Regression Gate. Each one has a hand-drawn doodle, a plain definition, a failure you can trigger and the fix.

Real code, no API key. The examples are short Python excerpts from the free companion repository (MIT licence), built from plain stages on the Python standard library with no framework. By default they run on a stubbed model, with no API key, no network and no cost. You can point a chapter at a real local model with Ollama if you like. Each Model experiment reports one real llama3.2 run with its settings and log, not a rate; runs not made yet are marked [TO MEASURE].

Chapters 3, 7 and 10 are in the free sample.

What you'll learn

  • Give every source a contract, and decide when to retrieve a document and when to look up a record
  • Ingest documents with stable ids and provenance, so reruns don't duplicate or orphan chunks
  • Keep table rows as records, spot-check parsers and send a page image when the layout carries the meaning
  • Cut chunks at headings and rows, search small chunks and hand the model the parent section
  • Enforce who may see what, from the session, at search, expansion, rerank, cache and citation
  • Choose an embedding model on your own golden set, and fuse keyword and vector search
  • Rerank a wide net down to five, and size the net from a recall curve
  • Rewrite and route queries without losing products, negations, dates or limits
  • Settle conflicts between sources by applicability and authority, and abstain when no source should answer
  • Pack evidence within a budget and validate every citation
  • Turn questions into allow-listed, parameterized SQL, and walk a knowledge graph where an unknown edge escalates
  • Update, delete and rebuild an index safely, and catch a stale one
  • Measure every RAG stage, judge faithfulness and block regressions with a gate

Who it's for

Developers who have built a retrieval feature and now have to trust its answers. You should be comfortable reading Python. Volume 1, or the same ground (tokens, embeddings, search, chunking, a RAG pipeline, grounded answers, evals), comes first. Volume 2 helps lightly: the code starts from its final code, and each piece it reuses is recapped in one line. You don't need a machine learning background. You need Python 3.10 or newer and git.

Who it's not for

If you want a tour of RAG frameworks or vector databases, this isn't that book. It builds plain stages so that every guarantee is code you can read and test. Further Reading points to the real tools.

Free sample

Front matter plus Chapters 3, 7 and 10.

Complete

All 16 chapters and the capstone appendix are written and illustrated in this edition (281 pages in the screen PDF). Buy once and get every future revision free.

Table of contents

Sources and ingestion

  • 1. The Knowledge Map: Source Contracts and Access Paths
  • 2. Ingestion Pipelines: Stable IDs, Provenance and Re-Runs
  • 3. Documents With Layout: Tables, Scans and Images
  • 4. Structure-Aware Chunking and Applicability Metadata

Who may see what

  • 5. Knowledge Access: Permissions, Tenants and Poisoned Documents

Finding the right passage

  • 6. Embedding Models and Vector Indexes
  • 7. Hybrid Search: Keywords Plus Meaning
  • 8. Reranking: The Second Opinion
  • 9. Query Understanding: Rewrite, Route and Decompose

Deciding and packing

  • 10. When Sources Disagree: Authority, Applicability and Abstain
  • 11. Context Assembly: Packing Evidence for the Model

Records and links

  • 12. Structured Knowledge: Query Specs, Scope and Safe SQL
  • 13. Knowledge Graphs and Multi-Hop Retrieval

Keeping it right

  • 14. Index Lifecycle: Updates, Deletes, Rebuilds and Drift
  • 15. Evaluating RAG: Retrieval Metrics and Faithfulness Judges
  • 16. RAG Test Sets and Regression Gates

Appendix: Capstone, One Ticket Through Every Stage

Plus: Further Reading, Transfer Exercises, a Decision Guide, an Experiment Ledger, Quick Reference, a Solutions Index, Quiz Answers, a Glossary and a Mental-Model Index.

Part of the AI Engineering Visualized series: Volume 1: Foundations, Volume 2: Agents, Volume 3: RAG & Knowledge Systems and Volume 4: Production AI. Get all four in the Volumes 1–4 bundle.

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $37.00
    Suggested price
    $60.00
  • Up to 5 members

    Minimum price
    $59.00
    Suggested price
    $96.00
  • Up to 10 members

    Minimum price
    $104
    Suggested price
    $168
  • Up to 15 members

    Minimum price
    $149
    Suggested price
    $240
  • Up to 25 members

    Minimum price
    $224
    Suggested price
    $360

Bundle

Bundles that include this book

Author

About the Author

Prateek Singh

Prateek Singh is the solo technical founder of Ganak AI Labs (https://ganak.ai), an Indian AI SaaS startup that also runs AI workshops for builders. Its product, Cloudeval AI (https://cloudeval.ai), runs pre-deployment reviews for Azure, plus AWS CloudFormation (beta), with evidence-backed reports, through the web, a CLI, GitHub and MCP. Before AI, Prateek worked as an infrastructure and cloud developer and was an active PowerShell community writer. Books and courses

Find me

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

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