LATENT LIBRARY AI ENGINEERING Building WithRetrieval A Practical Guide to RAG Systems LATENT LIBRARY EDITORIAL

Building With Retrieval

A Practical Guide to RAG Systems

Latent Library Editorial

IntroductionIntroduction

Language models know a great deal, but not your things: your product manuals, your HR policies, last week's meeting notes, the contract signed this morning. They also cannot reliably tell you where a fact came from, and they sometimes invent details with total confidence.

Retrieval-augmented generation (RAG) addresses all three problems with a simple idea: before the model answers, search a trusted collection of documents for relevant passages and put them in front of the model, with instructions to answer from them and cite them. The model supplies language and reasoning; the documents supply the facts.

The idea is simple. Making it work well is not. Poor chunking splits the answer across fragments; weak search returns plausible but wrong passages; vague prompts let the model drift back to guessing; and without evaluation, nobody knows whether a change made things better or worse.

This book is a practical guide to building RAG systems that are accurate, trustworthy and maintainable. It is organised along the pipeline:

A glossary, exercises and ready-to-use templates close the book.

Examples use language-neutral pseudocode, so you can apply them with whichever framework or database you prefer.

Chapter 1Why Retrieval?

Three ways to give a model knowledge

ApproachHow it worksGood forWeak at
Put it in the promptPaste the documents directlySmall, fixed sets of documentsLarge collections; cost per request
Retrieval (RAG)Search a collection; insert only relevant passagesLarge, changing knowledge; citationsQuestions needing the whole collection at once
Fine-tuningFurther train the model on examplesStyle, format, specialised behaviourPrecise, changing facts; citing sources

A common misconception is that fine-tuning is the way to "teach a model our documents". In practice, fine-tuning is better at teaching how to respond (tone, format, domain conventions) than what is true, and updating facts would require retraining. Retrieval is usually the right default for knowledge, and the two can be combined.

When RAG fits well

When to think twice

The basic pipeline

Indexing (ahead of time):
  documents -> clean -> split into chunks -> embed each chunk -> store in index

Answering (per question):
  question -> (rewrite) -> search index -> (rerank) -> top passages
           -> prompt with passages + instructions -> model -> answer with citations

You have reached the end of the free sample.
The full book continues with 15 more chapters, plus everything else in its 83 pages.

Get the full book