Sub topic 7
From question to search queries
This chapter covers the step between a user's question and the retrieval of pages: query rewriting. It assumes you know how search engines crawl and index pages, can read basic HTML and HTTP, and have a general idea of what a large language model (LLM) is. It also assumes the retrieve-then-generate pipeline from the earlier chapters.
Why the question is not the search query
A user types a question into an answer engine. The engine does not usually pass that text to its search index unchanged. A conversational question is often a poor search query. It can be long, it can depend on earlier turns in the chat, and it can bundle several needs into one sentence.
So the language model (or a smaller helper model) first turns the question into one or more search queries. This is called query rewriting. The model then sends those queries to the web index and works with whatever comes back.
Consider this question:
> What changed in how it handles redirects?
Without the earlier conversation, "it" has no referent. If the user was asking about a web framework in previous turns, the rewritten query might be Express 5 redirect behavior changes. The engine has filled in the missing context.
You do not see this step in the final answer. Some products show the queries they ran, often as a "searching for..." line or a list of searches. Where that display exists, it is the most direct evidence of what the engine looked for.
What rewriting typically does
Engines differ in detail, and none publishes a full specification. The following operations are commonly described or observable.
- Context resolution. Pronouns and vague references are replaced with the entities they point to from earlier turns.
- Keyword compression. A full sentence becomes a short keyword-style query that suits an index built for search.
- Decomposition. A compound question is split into parts, and each part gets its own search.
- Query expansion. The engine adds synonyms, alternative phrasings, or related terms to widen recall.
- Time anchoring. For questions about recent events, the engine may add a year or a word such as "latest".
- Deciding whether to search at all. For some questions the model answers from its training data and does not search. A request for current prices usually triggers a search. A request to explain a basic concept may not.
Fan-out: one question, several searches
Many engines issue several searches for one question. This is often called query fan-out. The searches can run in parallel, or they can run in sequence, where the results of one search shape the next.
Take this question: "Is Product A or Product B better for a small team, and what does each cost?" An engine might run searches like these:
Product A pricing small teamProduct B pricing small teamProduct A vs Product B comparisonProduct A reviews small business
Each search returns its own ranked list. The engine then merges these lists into one candidate set, which the next stages rank and extract from. Chapter-level detail on that merge belongs to the retrieval and ranking chapter. The point here is that your page is competing in several searches, not one.
The diagram below shows the flow.
Iterative and agentic searching
Some modes go further than one round of rewriting. In a research-style mode, the model reads the first results, notices gaps, and writes new queries. It may repeat this several times before it writes the answer. Perplexity's deeper research modes and similar features in other products work this way.
In practice this means the later queries depend on what the earlier results contained. A page that appears in round one can shape which queries run in round two. A page that never appears in round one might still appear later if the follow-up query is specific enough to match it.
How the three engines relate to this step
All three products rewrite queries, but the downstream source differs, as the previous chapter described.
| Engine | What happens to the rewritten query | Practical consequence |
|---|---|---|
| ChatGPT search | Sent to search providers and OpenAI's own crawled index | Pages need to be reachable by the search crawler and rank for the rewritten query |
| Perplexity | Sent to Perplexity's own index and retrieval system | Pages need to be in that index and match the rewritten query |
| Copilot | Sent to Bing's index | Standard Bing indexing and ranking apply |
The table simplifies. Providers change their architecture, and the public documentation is limited. Treat it as a model for reasoning, and verify behavior with your own tests.
What you can and cannot influence
You cannot see or edit the rewriting step. You can still write pages that match the kinds of queries it produces.
- Match the specific phrasing of real sub-questions. Rewritten queries are often narrower than the user's original question. A page titled "Pricing" may lose to a page headed "Product A pricing for teams under 10 people".
- Use the exact names of things. Product names, version numbers, error messages, and standard terms in the page text give lexical retrieval something to match.
- Cover the sub-questions of a topic on one page or a clearly linked set. If a typical question decomposes into pricing, setup, and limits, a page that addresses all three can match more of the fan-out searches.
- State dates and versions plainly. Time-anchored queries ("2026", "latest version") match pages that show their date.
- Answer the question early. The later extraction stage favors passages that stand on their own, so a direct statement near the relevant heading helps.
These are tendencies, not guarantees. The same user question can produce different rewrites on different runs.
Seeing the rewritten queries
You can collect evidence about rewriting without any special access.
- Ask a question in the product and look for a visible list of searches. Record it.
- Repeat the same question several times, and compare the lists.
- Ask follow-up questions that use pronouns, and check how the engine resolves them.
- Compare the queries with your page's title, headings, and first paragraphs.
The following script helps you compare a rewritten query against a page's text. It counts how many query terms appear in a page's title and headings. It is a rough check, not a model of any engine's ranking.
import re
import sys
from html.parser import HTMLParser
from urllib.request import Request, urlopen
class HeadingParser(HTMLParser):
def __init__(self):
super().__init__()
self.in_target = False
self.parts = []
def handle_starttag(self, tag, attrs):
if tag in ("title", "h1", "h2", "h3"):
self.in_target = True
def handle_endtag(self, tag):
if tag in ("title", "h1", "h2", "h3"):
self.in_target = False
def handle_data(self, data):
if self.in_target:
self.parts.append(data)
def term_coverage(url, query):
req = Request(url, headers={"User-Agent": "query-coverage-check/1.0"})
html = urlopen(req, timeout=15).read().decode("utf-8", errors="replace")
parser = HeadingParser()
parser.feed(html)
text = " ".join(parser.parts).lower()
terms = set(re.findall(r"[a-z0-9]+", query.lower()))
found = {t for t in terms if t in text}
return found, terms - found
if __name__ == "__main__":
page_url, search_query = sys.argv[1], sys.argv[2]
found, missing = term_coverage(page_url, search_query)
print("In title/headings:", sorted(found))
print("Missing:", sorted(missing))Run it as python coverage.py https://www.example.com/guide "product a pricing small team". Missing terms point to wording your headings do not use. Whether to add them depends on whether the page genuinely covers that topic.
Common errors
- Assuming the user's wording is the search query. The engine searches its rewrite, so optimizing only for the literal question misses it.
- Writing for one query instead of a cluster. Fan-out means several related queries compete for the same answer.
- Treating one test run as the truth. Rewrites vary between runs. Test several times and look for patterns.
- Stuffing keywords. Adding terms that the page does not support can hurt readability and does not make a passage better to quote.
- Ignoring chat context. In a multi-turn chat, your page may be retrieved for a query that never mentions your topic's name directly, because the engine resolved it from earlier turns.
Exercise
A user asks, "How do I fix that error in the new version?" after a long chat about a Python library called FastRoute that mentioned the error RouteConflictError and version 3.0. Write two search queries the engine might produce, and name which rewriting operations each one shows.
Show answer
One plausible query is FastRoute 3.0 RouteConflictError fix. It shows context resolution ("that error" becomes RouteConflictError, "new version" becomes 3.0) and keyword compression. A second is FastRoute 3.0 route conflict migration changes. It shows query expansion or decomposition, because it searches for the cause as well as the fix. Exact wording will vary between runs.
Exercise
Why can a page rank well for a broad topic and still not be retrieved for a fan-out search on the same question?
Show answer
Each fan-out query is narrower and worded differently from the original question, and the engine ranks pages for that specific query. A page that covers the topic broadly but lacks the specific terms, product names, or sub-topic the rewritten query uses may not match it.