BuildSpark AI
Dismiss

BuildSpark AI: practical AI concepts for builders. New here? Start with Tokens.

Home · Retrieval & Grounding · 05 · Query rewriting

Concept card · Retrieval & Grounding

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.

Last checked 2026-10-18 Free card 4 min

Ask about Query rewriting

What changed

Oct 18: First card. The picture turns a follow-up into a question you could search with no earlier message. Sources are LlamaIndex's chat engine guide and Azure AI Search's query rewrite guide. Azure marks that feature preview.

1 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.

Illustration. One follow-up, then the same turn written so it can be searched alone. The hits are written for this picture.

Search textWhat about weekends?

MissWeekday support is open from 09:00 to 17:00. Saturday mail waits until Monday.

MissThe refund window is 14 days.

The picture searches the follow-up as typed. It does not name support hours, so both chunks miss.

2 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.

3 How to apply · 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?

Questions

What is query rewriting?
Query rewriting turns a follow-up question into a search query that stands on its own.
Is Azure's query rewrite the same as a follow-up rewrite?
No. LlamaIndex's condense-question mode rewrites a chat turn into a query for the index. Azure's preview feature sends the search text to a generative model and retrieves with the original query plus alternatives.
Can a rewrite drop a product code?
Azure's guide says the rewritten queries might not contain all of the exact terms the original query had.