Query rewriting
Query rewriting transforms a question into a search-friendly form while preserving the user intent and known facts. It must not invent details.
Before you start: Review Reranking first. Python-like examples use variables, lists and functions.
Follow the mechanism
Original intent
Identify the actual user question.
Start with an everyday explanation
A librarian may turn “Why was it rejected?” into a clearer search after you identify the claim. Guessing the missing claim number would change the question.
See a concrete example
“What about its grace period?” can become “Grace period for policy POL-42” only if POL-42 is established in the current authorized context.
A claim to question
A rewrite must not assume the rejection reason before retrieving evidence.
Try before revealing the answer
Rewrite an ambiguous follow-up about a claim when two policies were discussed.
Show the worked answer
Ask which policy the user means, or retrieve separately with clear labels if the product permits. Do not silently choose one or insert an unverified lapse date.
Now explain the idea to someone else using your own example. If you cannot explain a stage, revisit it before moving on.
Engineering details and trade-offs
Resolve references from authorized conversation state. Preserve exact identifiers and distinguish known facts from hypotheses.
Compare rewritten retrieval with the original query. Keep traces and fallback behavior for harmful rewrites, extra latency and ambiguous inputs.
Reason through the example
“What about its grace period?” can become “Grace period for policy POL-42” only if POL-42 is established in the current authorized context.
Implement and test
Rewrite an ambiguous follow-up about a claim when two policies were discussed.
Inspect the reasoning and expected result
Ask which policy the user means, or retrieve separately with clear labels if the product permits. Do not silently choose one or insert an unverified lapse date.
What to measure
State the expected result before changing a control. Record your inputs, compare the observed result and explain one limit of this model. In a real implementation, test the failure case as well as the normal path.
Answer before reading the reference
How do you evaluate query rewriting?
A defensible answer
Use labeled original queries and compare retrieval recall, intent preservation and final answer quality. Include ambiguous references, exact IDs and adversarial text; account for the extra call cost.
Prepare the follow-up
How would you prevent a rewritten query from crossing tenant boundaries?
Show follow-up reasoning
Carry immutable user or tenant scope outside rewritten text, enforce it in retrieval and tool authorization and test malicious rewrites that mention other identifiers. A model-generated query cannot change the authenticated principal or grant access to a different record set.
Use the engineering explanation and worked task above to support your response. Identify which assumptions you would need to verify in production.
Choose a practice depth
- New to GenAI
- Define query rewriting with the everyday example and name its key limitation.
- Applied experience
- Explain the example, implementation choice and a measured failure case. Use the exercise as a small design review.
- Senior or systems depth
- Answer the follow-up, compare alternatives and justify an evaluation or rollout plan with operational constraints.
Self-review your answer
0/4 checks selected. This is self-assessment, not an interview score.
Your explanation and revision notes
Loading local notes…