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...
A Visual Guide to RAG and Knowledge Systems
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
Buying multiple copies for your team? See below for a discount!
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 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.
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.
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.
Front matter plus Chapters 3, 7 and 10.
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.
Sources and ingestion
Who may see what
Finding the right passage
Deciding and packing
Records and links
Keeping it right
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
Get a team discount on this book!
Up to 3 members
Up to 5 members
Up to 10 members
Up to 15 members
Up to 25 members
Bundles that include this book
About the Author
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
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
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
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
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.