liveBook · Manning

Chapter 9: Question transformations

What you will learn in chapter 9 of AI Agents and Applications

The introduction explains why a poorly phrased user question can undermine RAG retrieval even when the data has been carefully prepared.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why a poorly phrased user question can undermine RAG retrieval even when the data has been carefully prepared.

Key terms: Retrieval-Augmented Generation (RAG), vector store, user’s question, retrieval performance

9.1 Rewrite-Retrieve-Read

This section introduces Rewrite-Retrieve-Read and explains why a rewritten search query can improve retrieval while the original question remains available for answer synthesis.

Key terms: Retrieve-and-Read, Rewrite-Retrieve-Read, rewriter, tailored search query, vector store, answer-synthesis prompt, original question

9.1.1 Retrieving content using the original user question

The section uses a search with the original user question to show that its results may be limited by the question’s wording.

Key terms: original user question, search

9.1.2 Setting up the query rewriter chain

This section sets up an LLM chain that rewrites a user question into a query better suited to ChromaDB semantic search.

Key terms: query rewriter chain, LLM, ChromaDB, semantic search

9.1.3 Retrieving content with the rewritten query

This section uses a rewritten query to retrieve vector-store content and compares its relevance with results from the original question.

Key terms: rewriter chain, search_query, vector store retriever, text chunks

9.1.4 Combining everything into a single RAG chain

This section combines query rewriting, vector retrieval, and answer generation into one RAG workflow while preserving the original question for the final prompt.

Key terms: RAG chain, query rewriting, vector retrieval, original question

9.2 Generating multiple queries

This section explains when to turn one user question into multiple vector-store queries and how their retrieved context supports a combined answer.

Key terms: Rewrite-Retrieve-Read, multiple explicit questions, vector store, retrieved context, answer synthesis, MultiQueryRetriever, prompt, LLM reference, retriever

9.2.1 Setting up the chain for generating multiple queries

This subsection sets up a chain that generates five alternative versions of a user question and returns them as a list.

Key terms: multiple queries, custom result parser, StrOutputParser, list of strings

9.2.2 Setting up a custom multi-query retriever

This subsection gives the basic setup and test sequence for a custom multi-query retriever.

Key terms: standard retriever, custom multi-query retriever, retrieved_docs

9.2.3 Using a standard MultiQueryRetriever instance

This subsection presents the standard MultiQueryRetriever as a straightforward alternative for multi-query generation and notes that question transformations do not always produce the desired results.

Key terms: MultiQueryRetriever, multi-query generation, retrieved_docs, rewriting the original question, multiple explicit questions

9.3 Step-back question

This section explains how a step-back question retrieves broader context alongside detailed context so a RAG application can produce a more comprehensive answer.

Key terms: step-back question, vector store, broader context, detailed question (Q_D), detailed context (C_D), abstract question (Q_A), abstract context (C_A)

9.3.1 Setting up the chain to generate a step-back question

This section explains how to prompt a chain to generate a broader step-back question and why that question can help a RAG system retrieve useful context.

Key terms: step-back question, broader context, RAG workflow, vector store, GPT-5, GPT-5-nano, GPT-5-mini

9.3.2 Incorporating step-back question generation into the RAG chain

The section explains that a step-back question can improve RAG retrieval by broadening the question to provide better context.

Key terms: step-back question, RAG, retrieval, embedding-focused methods

9.4 Hypothetical Document Embeddings (HyDE)

Introduces HyDE as a way to improve RAG retrieval by searching with an LLM-generated, answer-like document instead of the user’s question.

Key terms: Hypothetical Document Embeddings (HyDE), hypothetical documents, document chunk embeddings

9.4.1 Generating a hypothetical document for the user question

This subsection introduces generating a hypothetical answer document from a user question for use in RAG retrieval.

Key terms: HyDE, hypothetical document, RAG chain, vector store

9.4.2 Integrating the HyDE chain into the RAG chain

This subsection integrates a HyDE chain into a RAG workflow to enhance retrieval with a hypothetical document.

Key terms: HyDE chain, RAG chain, hypothetical document, retrieval process

9.5 Single-step and multi-step decomposition

This section distinguishes independent subquestions from dependent ones and explains how to answer a complex question through a sequence of queries whose answers feed later queries.

Key terms: single-step decomposition, independent questions, interdependent questions, multi-step decomposition, parameterized questions, vector store, SQL database

9.6 Summary

The section recaps ways to transform questions and retrieval inputs so a RAG system can find more relevant documents.

Where this is used later

Concepts explained in this chapter

← Chapter 8: Advanced indexing Chapter 10: Query generation, routing, and retrieval postprocessing →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.