liveBook · Manning

Retrieval-augmented generation

As explained in AI Agents in Action

Retrieval augmented generation is a language-model pattern that retrieves relevant external information and incorporates it into generated responses.

Retrieval-augmented generation (RAG) enhances a language model’s prompt with relevant context retrieved from external documents or other stored information. It supports document chat, question answering, reference lookup, and agent knowledge. section 8.1 section 8.2

A typical RAG workflow has two phases:

  • Load documents, split them into context chunks, convert the chunks into vector embeddings, and store them in a vector database. section 8.2
  • Embed a user query, search for similar stored chunks, and insert the retrieved content into the prompt as additional context. section 8.2
  • Send the augmented prompt to the language model, which uses the retrieved context to help formulate an answer. section 8.2

Querying a document collection

A document-chat application can index a PDF or text file, then answer a question by retrieving semantically similar passages. In a LangChain exercise, token-based chunks are stored in Chroma and similarity search retrieves a nursery-rhyme passage even when the query uses different wording, such as asking why the girls are crying. section 8.4.2

Figure 8.2 The two phases of RAG: first, documents must be loaded, transformed, embedded, and stored, and, second, they can be queried using augmented generation.
figure

Use this diagram to distinguish document indexing from query-time augmented generation. section 8.2

How AI Agents in Action covers it

How deep it goes
Explains indexing, chunking, embeddings, vector storage, similarity search, and generation, while deferring more advanced retrieval patterns.
Examples
Demonstrates PDF and text-document chat, LangChain chunking, Chroma retrieval, nursery-rhyme queries, and Nexus knowledge stores.
What it assumes
Assumes basic prompt and agent concepts, while introducing retrieval, document indexing, embeddings, vector databases, and memory from foundational distinctions.
What you can do after
Build RAG workflows that index documents, retrieve semantically similar passages, and connect knowledge stores to supported agents.
How it connects
Connects document indexing, vector embeddings, similarity search, prompt engineering, agent knowledge, and agent memory.

Also explained in

Compare how 32 books explain retrieval-augmented generation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action. The section links point to the parts of the book it draws on.