# Query rewriting

> Query rewriting turns a follow-up question into a search query that stands on its own.

Turning a follow-up question into a search query that stands on its own.

Track: Retrieval & Grounding
Access: free
Card: https://buildsparkai.com/query-rewriting
Plain text: https://buildsparkai.com/query-rewriting.md
Last checked: 2026-10-18

## What it is

A support thread rarely repeats the subject. The next message is "What about weekends?" LlamaIndex's chat engine guide describes condense_question as looking at the chat history and rewriting the user message into a query for the index. Azure AI Search's query rewrite guide describes a different pass: the service sends the search text to a generative model and retrieves with the original query plus the alternatives. Microsoft marks that feature preview, and says preview features are not recommended for production. The picture is the follow-up case. It does not call either API.

## Why it matters

**Cost.** The rewrite is another model call before search. Azure's guide says the service sends the query to a generative model. LlamaIndex's condense-question mode also calls a model to rewrite, then queries the index. This card does not add a price for that call.

**Quality.** A follow-up that says "weekends" does not name the product or the policy. A standalone question can. Azure's guide says its rewrite can correct typos and expand a query with synonyms. This card does not claim every rewrite is a better query.

**Risk.** Azure's guide says the rewritten queries might not keep every exact term from the original, which matters when the query is a product code. A rewrite can also search for a subject the user did not ask about.

## Try today

Take the last two messages from a real support thread. Write the follow-up as a question someone could paste into search with no earlier message. If it still says "that" or "it," it is not ready.

## Common mistake

Searching the follow-up as typed. "What about weekends?" does not say which product, or that the subject is support hours.

## Self-check

The user asked when weekday support is open, then asked "What about weekends?" What should retrieval search?

A standalone question that names weekend support

## Practice and deep

Coming soon. One follow-up from the support-docs answer bot, rewritten so the hours doc can match, with the original wording kept beside it.

Coming soon. How LlamaIndex condenses a chat turn, and how Azure's preview rewrite adds alternatives. Azure says not to send the debug flag in production.

## Sources

- [LlamaIndex, Chat engine usage](https://developers.llamaindex.ai/python/framework/module_guides/deploying/chat_engines/usage_pattern/)
- [Azure AI Search, Query rewriting](https://learn.microsoft.com/en-us/azure/search/semantic-how-to-query-rewrite)

Opened 2026-10-18. Framework and vendor docs. Azure's page marks query rewriting as preview. This card does not add a rate or a usage count.
