Query Rewriting for Retrieval-Augmented Large Language Models

Xinbei Ma, Yeyun Gong, Pengcheng He, Hai Zhao, Nan DuanarXiv 2023

TL;DR

Instead of directly feeding raw user prompts into a retrieval system, this paper introduces the Rewrite-Retrieve-Read framework, which uses a small, trainable language model to rewrite queries before searching. By optimizing this rewriter via reinforcement learning based on the final performance of a frozen, black-box Large Language Model (LLM) reader, the method significantly boosts accuracy on knowledge-intensive tasks while saving computational resources.

What Problem Does This Paper Address?

Retrieval-Augmented Generation (RAG) has become the standard solution for mitigating LLM hallucinations and keeping model knowledge up to date. The traditional pipeline follows a simple Retrieve-then-Read approach: take the user's input, search a database or the web for relevant documents, concatenate them, and let the LLM read them to generate an answer.

However, this approach suffers from a fundamental flaw: the query gap. What a human asks is rarely optimized for what a search engine needs to find the right answer. For instance, complex multi-hop questions confuse search engines, leading to noisy or irrelevant context that can actually degrade the LLM's performance. Furthermore, because state-of-the-art LLMs (like ChatGPT) are typically closed-source, black-box APIs, we cannot easily fine-tune the reader or the retriever to align with each other.

Methods

To bridge this gap, the authors propose a three-step framework: Rewrite-Retrieve-Read.

Figure 1: Overview of our proposed pipeline. From left to right, we show (a) standard retrieve-then-read method, (b) LLM as a query rewriter for our rewrite-retrieve-read pipeline, and (c) our pipeline with a trainable rewriter.

Instead of relying on a massive LLM to do the rewriting (which is expensive and slow), they introduce a dual-stage training scheme for a small, dedicated rewriter model (initialized from a 770M parameter T5-Large model):

  1. Rewriter Warm-up (Distillation): They first prompt ChatGPT to generate search queries for the training set. They filter these queries, keeping only the ones that lead to a correct answer from the LLM reader, and use them to fine-tune the T5 rewriter using standard supervised learning.
  2. Reinforcement Learning (Optimization): Because human-prompted distillation is often sub-optimal, they further tune the T5 rewriter using Proximal Policy Optimization (PPO). The rewriter receives a reward based on the final output of the frozen LLM reader (factoring in Exact Match, F1 score, and whether the retrieved document actually contained the answer). A KL-divergence penalty ensures the rewriter doesn't drift too far from its initialization.

For the retrieval step, they leverage the Bing search engine API, extracting either the search snippets or parsing the full text of the URLs and filtering them using BM25.

Datasets

The framework was evaluated across two main task types:

  • Open-domain QA:
  • HotpotQA: Complex questions requiring multi-hop reasoning.
  • AmbigNQ: Questions that are inherently ambiguous and require disambiguation.
  • PopQA: A dataset focusing on long-tail, low-popularity knowledge where LLM parametric memory typically fails.
  • Multiple-choice QA:
  • MMLU (Massive Multi-task Language Understanding): Evaluated across four core categories: Humanities, STEM, Social Sciences, and Other.

Key Insights and Ideas

  • Raw Queries Can Hurt Performance: On complex datasets like HotpotQA, standard "Retrieve-then-Read" actually decreased ChatGPT's performance (Exact Match dropped from 32.36 to 30.47). This proves that raw multi-hop questions introduce more noise than signal when thrown directly into a search engine. Rewriting completely reverses this penalty.
  • Small Models Can Manage Big Models: A lightweight 770M parameter model can be successfully trained to act as a specialized "interface" or translator between a search engine and a frozen 175B+ parameter black-box LLM.
  • Learning to Say "Nothing": On datasets like PopQA, the RL-trained rewriter learned when not to retrieve anything (generating a "None" query) to avoid redundant or harmful context, showing a sophisticated adaptation to the reader's internal knowledge limits.
Figure 3: Examples for intuitive illustration. Q0 denotes original input, Q1 is from the LLM rewriter, and Q2 is from the trained T5 rewriter. Hit means retriever recall the answer, while Correct is for the reader output.

Key Results

The Rewrite-Retrieve-Read framework demonstrated consistent improvements across the board:

  • HotpotQA: The trainable rewriter achieved an EM score of 34.38, outperforming both the standard Retrieve-then-Read baseline (30.47) and a frozen ChatGPT rewriter (32.80).
  • AmbigNQ & PopQA: The trainable rewriter achieved 47.80 and 45.72 EM respectively, substantially outperforming the no-retrieval baselines.
  • MMLU: When using the open-source Vicuna-13B as a reader, the trainable rewriter improved average performance across all categories, proving that the framework scales to different reader architectures.

Additionally, the reinforcement learning phase proved crucial, showing clear upward performance trends across training iterations as the rewriter adapted to the frozen reader's quirks.

Validation scores rising across RL training iterations.

Limitations and Future Work

While effective, the authors note a few limitations:

  1. Task Specialization: The RL training process makes the small rewriter highly specialized to a specific downstream task, compromising its zero-shot generalization capabilities compared to a prompt-engineered LLM.
  2. Single-Turn Constraint: Unlike agentic frameworks (e.g., ReAct or DSP) that allow multiple rounds of interactive searching and reading, this framework is strictly single-turn. While more computationally efficient, it may struggle with highly iterative reasoning tasks.
  3. Web Search Volatility: Relying on commercial web search APIs introduces unpredictability (due to index changes) and subscription costs, making local neural dense retrievers an attractive alternative for future exploration.

Summary updated

BibTeX
@misc{ma2023query,
  author = {Xinbei Ma and Yeyun Gong and Pengcheng He and Hai Zhao and Nan Duan},
  title = {{Query Rewriting for Retrieval-Augmented Large Language Models}},
  year = {2023},
  eprint = {2305.14283},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.14283},
}
Figure