How do you handle retrieval in a multi-turn conversation?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
The core problem: the latest user message is not a self-contained query. After "How do I set up SSO?" → answer → "Does that work with Okta?", embedding "Does that work with Okta?" retrieves generic Okta chunks, losing the SSO thread entirely. Pronouns, ellipsis ("what about pricing?"), and topic switches all break naive per-turn retrieval.
Full worked answer with diagram
The core problem: the latest user message is not a self-contained query. After "How do I set up SSO?" → answer → "Does that work with Okta?", embedding "Does that work with Okta?" retrieves generic Okta chunks, losing the SSO thread entirely. Pronouns, ellipsis ("what about pricing?"), and topic switches all break naive per-turn retrieval.
The standard fix is history-aware query rewriting (also called query condensation): a fast LLM call takes recent conversation turns plus the new message and produces a standalone search query - "Does Okta work with [product] SSO setup?" - which then feeds the normal retrieval pipeline. Details that matter in production: use a small/fast model (this sits on the critical path - budget ~100-300ms); give it the last handful of turns, not the whole history; and instruct it to pass through queries that are already standalone unchanged, because rewriting can actively damage a clean query. A cheaper fallback - concatenating the last user turns into the query - works surprisingly often but fails on topic switches, where stale context pollutes retrieval.
Second decision: when to retrieve at all. Follow-ups like "can you shorten that?" or "explain it more simply" need no new retrieval - the material is already in context. A retrieve/no-retrieve classifier (or letting the model decide via a search tool, the agentic pattern) saves latency and avoids stuffing redundant chunks.
Third: context management across turns. Retrieved chunks accumulate; naively keeping every turn's retrievals blows the token budget and buries the model in stale evidence. Options: keep only the current turn's retrievals plus the running conversation, dedupe chunks already cited, or maintain a working set with recency-based eviction. Also track which chunks previous answers were grounded in, so follow-up questions about "that document" can resolve.
In agentic products this whole problem increasingly collapses into tool use: the model sees the conversation and writes its own search queries, which handles rewriting implicitly - at the cost of an extra model round-trip.
Worth sketching. Two gates, rewrite-or-not and retrieve-or-not, are what separate a chat demo from a product, and both are cheap to draw.
flowchart TD
T["New turn plus the<br/>last few turns"] --> C{"Already a<br/>standalone query?"}
C -->|"yes"| K["Pass through unchanged"]
C -->|"no"| RW["Condense into<br/>a standalone query"]
K --> N{"Needs new evidence?"}
RW --> N
N -->|"no: shorten that"| G["Answer from the<br/>context already held"]
N -->|"yes"| R["Retrieve, dedupe against<br/>chunks already cited"]
R --> G
What a good answer covers
- The core problem: the latest user message is not a self-contained query
- After "How do I set up SSO?" → answer → "Does that work with Okta?", embedding "Does that work with…
- Pronouns, ellipsis ("what about pricing?"), and topic switches all break naive per-turn retrieval
- The standard fix is history-aware query rewriting (also called query condensation)
- Details that matter in production
Key terms: history-aware query rewriting · when to retrieve at all · context management across turns
In the glossary: Query rewriting
Interviewer follow-ups to expect
How do you evaluate rewriting quality offline - what does the golden set look like for multi-turn?
What goes wrong when the user abruptly changes topic?
When does the agentic "model writes its own queries" pattern beat explicit rewriting?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep