Pattern · Retrieval and RAG
Query rewriting
Turn what the user typed into a better search query: standalone, expanded, or split into parts.
Say it in the interview
Because users ask follow-ups, I would add a query-rewrite step that turns the last message and history into a standalone search query, and HyDE only for very short queries. I would log both versions in the trace so we can see when the rewrite caused a miss.
When to use it
- Follow-up questions that depend on chat history ("and for seniors?")
- Short or vague queries
- Questions that need several searches
How it works
- User message + chat history → Rewrite into a standalone query
- Rewrite into a standalone query → short query → HyDE: draft an answer, embed it
- Rewrite into a standalone query → Search
- HyDE: draft an answer, embed it → Search
Trade-offs
- Big gains on conversational search
- One extra model call per question
- A bad rewrite can drift from what the user meant
Pitfalls interviewers probe
- Rewriting every query, even clear ones
- Not logging the rewritten query, so failures cannot be debugged