Query Rewriting in Conversational Systems
Relevance to the query is not the only thing that can decide a document's position.
Why the First Ranking Is Not Always Final
Imagine asking a system a question about your inbox, your company's sales records, or a fast-moving news feed. The system does not read everything it owns. It first pulls out a set of documents that look promising, and it puts them in an order. That first ordering comes from the retriever. It is often good enough to start with, but it is not always good enough to use directly.
There are two common reasons the first ordering falls short. Sometimes the list is far longer than anything you can hand to a language model. Sometimes the top of the list is not the most useful text for the question at hand. A step called reranking takes the retriever's ordering and revises it. This article follows the reasoning behind that step, then shows how a related technique, query rewriting, prepares the question before retrieval even begins.
Following a Question Through Two Stages
Trace what happens to a question as it moves through the system. Start with a whole collection of documents. The query goes first to a retriever. The retriever is cheap to run but not very precise, so it can scan a large collection quickly and collect candidate documents. The output of this first stage is a candidate list. It is much smaller than the collection, and its ordering is only rough.
Now follow the candidate list into the second stage. A more precise mechanism examines only those candidates and reorders them. This mechanism is more expensive per document, which is exactly why it is applied to a short list instead of the whole collection. The state of the data changes at each stage: the collection becomes a candidate list, and the candidate list becomes a reordered, shorter list that is ready to be used.
Why Cheap Retrieval and Precise Reranking Are Split
The two-stage design separates two jobs that pull in opposite directions. Covering a large collection needs speed. Ordering a handful of documents with care needs precision. Rather than forcing one mechanism to do both, the design lets each stage do the job it suits. The retriever handles breadth and the reranker handles care.
Reranking is especially valuable when you need to reduce the number of retrieved documents. That reduction might be driven by the size of the model's context window, or by a wish to reduce the number of input tokens you pay to process. In both cases the reranker is a filter-and-order step. It turns a broad but rough list into a narrow and carefully ordered one.
Ranking by Relevance Versus Ranking by Recency
Relevance to the query is not the only thing that can decide a document's position. Documents can also be reranked by time, with more recent material given higher weight. This matters when the answer changes over time. A document that was highly relevant last month may be less useful today than a slightly less matching document from this morning.
What do you think happens?
A document that matched the query strongly last month and a weaker match from this morning are both retrieved. If the ranking uses recency, which one moves to the top?
Reveal answer
The weaker match from this morning
Recency gives higher weight to newer data, so the newer document is nudged upward even though it matched less strongly.
Recency matters most in time-sensitive uses. The source names three kinds of application: news aggregation, a chatbot that answers questions about your emails, and stock market analysis. In each case the newest information is often the most actionable, so a time-based weighting nudges it upward. This weighting is a deliberate adjustment applied on top of whatever the retriever has already judged. For a question whose answer does not change over time, relevance alone may be the better guide.
Order Inside a Model's Context Window
Reranking for a search results page and reranking for a language model are related, but they care about different things. On a search results page, rank is the whole point. The first result and the fifth result are different experiences, and rank position is crucial. When documents are placed inside a model's context, the exact position of each item matters less. What matters first is whether the document is included at all.
Order does not stop mattering once a document is inside the context. The order of documents still affects how well a model can process them. Models may understand documents placed at the beginning and at the end of the context better than those in the middle. Once a document is included, the effect of its exact placement is smaller than the effect of rank in a search list. Inclusion is the larger decision; arrangement is the refinement.
The map above shows one arrangement of three included passages. The beginning and end positions are the ones the model tends to use well, so the strongest passages are placed there and the weaker passage sits in the middle. The arrangement does not change which passages are included. It only refines how the model reads them.
Rewriting the Question Before Retrieval
Query rewriting, also called query reformulation, query normalization, and sometimes query expansion, means changing or restating a query so that it retrieves better results. The need for it becomes obvious in a conversation. Consider a user who first asks when John Doe last bought something from the business. The assistant answers that John last bought a Fruity Fedora hat two weeks before the date given. The user then asks, 'How about Emily Doe?'
Read on its own, that second question is incomplete. It does not say what is being asked about Emily. A system that sends those exact words to a retriever has very little to work with. The meaning lives in the earlier turn of the conversation. Query rewriting carries that meaning forward.
Rewriting an incomplete follow-up
The earlier turn asked about John Doe's last purchase. The follow-up says: How about Emily Doe? Rewrite the follow-up as a question that can be retrieved on its own.
- 1Find the missing topic
The follow-up names a person but not what is being asked. The earlier turn supplies the missing topic: purchase history with the business.
- 2Keep the new subject
The new subject is Emily Doe, which replaces John Doe in the earlier question.
- 3Combine topic and subject
Joining the carried-over topic and the new subject gives one complete question that does not depend on the conversation to be understood.
What did Emily Doe last buy from the business, and when? (One illustrative rewrite; the requirement is that the standalone query captures what the follow-up was really asking.)
The exact wording of a rewrite is only an illustration. What the technique requires is that the standalone query captures the intent of the follow-up. Once the query is complete, retrieval has a real target, and the rest of the pipeline can work on documents that actually match what the user meant.
Common Mistakes When Reading This Pipeline
Common mistake Treating the reranker as a replacement for the retriever
Why it failsThe reranker only examines the candidates it is given. It filters and orders a list that the retriever has already produced.
Do this insteadThink of the reranker as a filter-and-order step that narrows a broad but rough list.
Common mistake Assuming the newest document should always rank first
Why it failsRecency is a weighting for time-sensitive uses. For questions whose answers do not change over time, relevance alone may be the better guide.
Do this insteadDecide whether time matters for the question before adding recency weight.
Common mistake Believing that position inside the context is irrelevant once a document is included
Why it failsInclusion is the larger decision, but order still affects how well the model processes documents, especially at the beginning and end.
Do this insteadInclude the strongest documents first, then refine their placement.
Common mistake Sending a follow-up question to the retriever exactly as typed
Why it failsA follow-up such as 'How about Emily Doe?' depends on earlier turns, so the retriever has little to work with on its own.
Do this insteadRewrite the follow-up into a standalone query that carries over the missing topic from the conversation.
Common mistake Confusing query rewriting with reranking, which works on documents rather than on the question
Tracing a Pipeline on Your Own
A user asks a news assistant about a company's quarterly results, and then asks: 'What about its competitors?' Describe in two or three sentences what the query rewriter must do before retrieval, and then say whether recency weighting would be useful for the reranker in this case and why.
Hints
- Ask what the follow-up leaves unstated and where the missing topic lives.
- Consider whether the answer to a quarterly results question changes over time, as the source's time-sensitive examples suggest.
- Remember that recency is applied on top of relevance, not instead of it.
Key Takeaways
- Retrieval gives a fast but rough ordering, and reranking is a second pass that revises that ordering on a shorter candidate list.
- A cheap retriever handles a large collection, while a more precise and more expensive reranker orders only the candidates, which helps when the list must fit a context window or reduce input tokens.
- Recency weighting moves newer documents upward in time-sensitive uses such as news, email chat, and stock market analysis, applied on top of relevance.
- Inside a model's context, inclusion matters most, while placement at the beginning and end still affects how well the model uses each document.
- Query rewriting turns an incomplete follow-up into a standalone query by carrying the missing topic from earlier turns into the new question before retrieval begins.