liveBook · Manning

Retrieval-augmented generation

As explained in Software Testing with Generative AI

Retrieval-augmented generation is a generation technique that retrieves relevant external information and supplies it to a language model as context.

Retrieval-augmented generation (RAG) improves a language model’s response by retrieving relevant material from an external corpus and adding it to the prompt. It supplies focused context without baking that context into the model itself. section 10.2 section 10.3

RAG addresses two practical problems: context-free prompts produce generic responses, while adding every available document can exceed the model’s context window. Relevance-based selection keeps the prompt focused and makes external data easier to update separately from the model. section 11.1 section 11.4

A basic RAG workflow proceeds as follows:

  • Create or ingest a corpus containing relevant documents, such as user stories, HTML pages, schemas, monitoring data, or wiki entries. section 10.2.1 section 11.2.1
  • Accept a user query describing the task, such as requesting test ideas for deleting bookings. section 11.1
  • Use a similarity algorithm or retrieval tool to identify the document or documents most relevant to the query. section 11.1 section 11.4
  • Combine the query, retrieved context, and task instructions into a prompt, then send it to the language model. section 11.1 section 11.2
  • Parse and inspect the response rather than treating retrieved context or generated recommendations as automatically correct. section 10.2.4 section 11.4

Generating API testing risks

A tester enters: “I want test ideas for the payload portion of the PUT branding endpoint.” The retriever selects the matching user story, including the endpoint, acceptance criteria, optional cookie token, and JSON schema. A prompt asks the model to recommend risks from that story and query. The resulting suggestions include missing parameters, invalid data types, malformed or schema-incompatible JSON, an absent optional token, and an incorrect endpoint. These suggestions remain hypotheses for human review, not completed tests. section 11.2.2 section 1.2.1

Retrieval quality limits response quality. An inaccurate similarity match can supply misleading context; broad queries or multiple data sources make selection harder. Vector databases can store vectors for relevancy searches and retrieve multiple relevant files, but they do not remove the need for verification. section 11.4

Figure 11.1 A visualization of how a basic RAG system works

Use the workflow visualization to trace the query, relevance search, retrieved document, combined prompt, and generated response. section 11.1

RAG is often a smaller practical step than fine-tuning because it extends prompting rather than changing model parameters. The approaches can be combined, but doing so increases production cost, complexity, and debugging difficulty. section 10.2.3 section 10.2.4

How Software Testing with Generative AI covers it

How deep it goes
Explains retrieval, prompt assembly, corpus ingestion, similarity matching, vector databases, implementation, and failure modes.
Examples
Demonstrates page-object generation, user-story retrieval, booking tests, and PUT branding payload-risk recommendations.
What it assumes
Assumes prompt-engineering familiarity while teaching corpus ingestion, relevance retrieval, context injection, and basic framework construction.
What you can do after
Build it from scratch using a document corpus, similarity search, prompt construction, an LLM API, and response parsing.
How it connects
Connects prompt engineering, language models, context windows, fine-tuning, similarity algorithms, and vector databases.

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 Software Testing with Generative AI. The section links point to the parts of the book it draws on.