liveBook · Manning

Retrieval-augmented generation

As explained in The AI Pocket Book

A method of augmenting an LLM prompt with retrieved external documents so the model can answer using information not in its training data.

Retrieval-augmented generation (RAG) gives an LLM relevant external documents at prompt time. Instead of relying only on training data, a wrapper searches a document database, adds matching content to the prompt, and lets the LLM use it when generating an answer. section 1.7

A practical use

A business chatbot can search internal documents before answering an employee’s question. An application can use the same pattern to analyze up-to-date webpages and identify the sources behind its response. section 1.7

The basic process is straightforward, but the difficult parts are retrieval and prompt size:

  • Search for documents relevant to the user’s prompt, often by extracting keywords and matching them against indexed content. section 1.7
  • Insert the retrieved documents into the prompt so the LLM can use their contents as additional context. section 1.7
  • Keep the added material within the model’s maximum prompt length; longer inputs can also increase usage costs. section 1.7
  • Do not treat RAG as magic: irrelevant retrieval produces weak context, and choosing effective retrieval techniques remains an active challenge. section 1.7

RAG changes the prompt rather than the model’s internal parameters. That makes it a distinct alternative to fine-tuning, while increasingly large context windows make it more effective for supplying substantial task-specific information. section 3.3

How The AI Pocket Book covers it

How deep it goes
Explains retrieval, prompt augmentation, retrieval quality, context limits, and cost, but not retrieval algorithm internals.
Examples
Uses internal-document chatbots, current webpages, keyword matching, source citation, and added prompt documents.
What it assumes
Assumes basic familiarity with LLMs and prompts while defining retrieval and prompt augmentation directly.
What you can do after
Build it from scratch by searching indexed documents, adding relevant content to prompts, and managing context limits.
How it connects
Connects document databases, prompting, context windows, LLMs, and fine-tuning.

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 The AI Pocket Book. The section links point to the parts of the book it draws on.