liveBook · Manning

Retrieval-augmented generation

As explained in Grokking AI Applications

A generative AI technique that retrieves relevant external information and supplies it to a model as context for generation.

Retrieval-augmented generation (RAG) gives an LLM access to knowledge outside its pretrained, general-purpose understanding. Rather than attaching every document to every prompt, it finds a few relevant passages and supplies them as context for an answer. This supports assistants that need organization-specific, changeable, or explainable information, such as opening hours, procedures, and product details. section 1.4 section 4.0

Figure 4.1 A RAG-based flow includes three essential steps: document ingestion, document retrieval, and answer generation.

A RAG flow has three linked stages: prepare knowledge, retrieve the best context for a question, and generate an answer from it. section 4.1

A practical RAG system separates setup work from question-time work:

  • Ingest documents: read source files or other knowledge, convert them to text, split the text into chunks, create embeddings, and store them in a vector database. section 4.1 section 4.2
  • Retrieve context: turn a user question into a similarity search and select the most relevant chunks from the vector database. section 4.1 section 4.5
  • Generate an answer: provide the retrieved chunks to the LLM so it can answer using both its pretrained knowledge and the supplied documents. section 4.1 section 4.2

A restaurant assistant

A pizza restaurant can use a PDF containing its menu, prices, hours, and delivery details to power a chat assistant. During setup, the PDF becomes embedded chunks in a vector database. At runtime, a customer question retrieves relevant chunks, which the LLM uses to answer. The ingestion flow runs again only when the PDF changes; retrieval and generation run for each question. section 4.2

Retrieval quality shapes answer quality. Small chunks can omit needed information, while large chunks can weaken embeddings and overload the LLM’s context. Overlap and the number of retrieved results (top k) need tuning: too many results may confuse the model, while too few may leave out a critical passage. Sources can also include web pages, and a RAG tool can give an agent semantic access to a recipe collection or other document set. section 4.3 section 6.3

How Grokking AI Applications covers it

How deep it goes
Explains the full ingestion, retrieval, and generation workflow, then details chunking, embeddings, vector search, and tuning controls.
Examples
Demonstrates a PDF-backed pizza assistant and an agent that semantically searches an Italian recipe collection.
What it assumes
Introduces RAG from a practical LLM limitation without assuming prior AI engineering expertise.
What you can do after
Apply it via Langflow to build and tune document-backed LLM flows using ingestion and retrieve-and-answer subflows.
How it connects
Connects LLMs, embeddings, vector databases, semantic search, prompt context, agents, and external URLs.

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