---
title: "Query rewriting pattern for AI agents | Agentic Pattern Language"
description: "Have a model rewrite the user’s query, with the conversation so far, before searching with it. Sourced from Ma et al., ElevenLabs, and Elastic."
url: https://agenticpatternlanguage.com/patterns/query-rewriting/
---

25 [One call](https://agenticpatternlanguage.com/#one-call)

# Query rewriting

Have a model rewrite the user’s query, with the conversation so far, before searching with it.

Also called Rewrite-Retrieve-Read

Ma et al., ElevenLabs, Elastic, Microsoft

[How to read this](https://agenticpatternlanguage.com/notation/)

## Part of

* [Retrieval-augmented generation](https://agenticpatternlanguage.com/patterns/retrieval-augmented-generation/)

## The problem

The user’s words, often leaning on earlier turns, are not the query the retriever needs.

> there is inevitably a gap between the input text and the knowledge that is really needed to query.

Ma et al. [Query Rewriting for Retrieval-Augmented Large Language Models](https://arxiv.org/abs/2305.14283)

> Most user requests reference prior turns, so the system needs to collapse dialogue history into a precise, self-contained query.

ElevenLabs [How we engineered RAG to be 50% faster](https://elevenlabs.io/blog/engineering-rag) Sep 12, 2025

## Therefore

> In front of the retriever, a step of rewriting the input is added, filling the gap between the given input and retrieval need

Ma et al. [Query Rewriting for Retrieval-Augmented Large Language Models](https://arxiv.org/abs/2305.14283)

> Query rewriting … is the process of transforming a user's query into a more effective one, adding more terms and refining search results.

Microsoft [Rewrite queries with semantic ranker in Azure AI Search (preview)](https://learn.microsoft.com/en-us/azure/search/semantic-how-to-query-rewrite)

## In use

ElevenLabs

> In our system, we add a query rewriting step first, collapsing dialogue history into a precise, self-contained query before retrieval.

ElevenLabs [How we engineered RAG to be 50% faster](https://elevenlabs.io/blog/engineering-rag) Sep 12, 2025

Azure AI Search

> The Foundry IQ service sends the search query (or a variation of it) to a generative model that generates alternative queries.

Microsoft [Rewrite queries with semantic ranker in Azure AI Search (preview)](https://learn.microsoft.com/en-us/azure/search/semantic-how-to-query-rewrite)

## Where it breaks

A rewrite can drop the exact terms a search needed, and leaning on it too much can lower relevance.

> The rewritten queries might not contain all of the exact terms the original query had. This might impact search results if the query was highly specific and required exact matches for unique identifiers or product codes.

Microsoft [Rewrite queries with semantic ranker in Azure AI Search (preview)](https://learn.microsoft.com/en-us/azure/search/semantic-how-to-query-rewrite)

> We observed that overreliance on LLM output reduced relevance.

Elastic [Query rewriting strategies for LLMs and search engines to improve results](https://www.elastic.co/search-labs/blog/query-rewriting-llm-search-improve) Jan 30, 2026

## Sources

1. [Query Rewriting for Retrieval-Augmented Large Language Models](https://arxiv.org/abs/2305.14283) Xinbei Ma, Yeyun Gong, Pengcheng He, Hai Zhao, Nan Duan, Ma et al.
   > We present Rewrite-Retrieve-Read, a pipeline that improves the retrieval-augmented LLM from the perspective of query rewriting.
2. [How we engineered RAG to be 50% faster](https://elevenlabs.io/blog/engineering-rag) ElevenLabs, Sep 12, 2025
3. [Query rewriting strategies for LLMs and search engines to improve results](https://www.elastic.co/search-labs/blog/query-rewriting-llm-search-improve) Christina Nasika, Emilia Garcia Casademont, Elastic, Jan 30, 2026
4. [Rewrite queries with semantic ranker in Azure AI Search (preview)](https://learn.microsoft.com/en-us/azure/search/semantic-how-to-query-rewrite) Microsoft

Added Nov 14, 2026
