Resolve references in a dialogue while carrying only the constraints that still apply to the current search turn.
Conversational retrieval: rewrite the follow-up without changing its scope
Make the current turn searchable
Conversational retrieval turns a context-dependent follow-up into a standalone search request. After 'What is the P-47 limit in revision r4?', 'What about the old one?' may refer to the same pump and a prior revision. A rewrite should capture that relation without inventing a date or unit. Keep the raw user text, the selected antecedent and the resolved query in the trace. Query routing should use the resolved intent only after checking that the reference is unambiguous.
Carry constraints with expiration
Tenant identity and authorization come from the active session, never from an earlier answer string. Topic, entity and date constraints may carry forward for one turn, but they can also be overridden. 'Now compare P-48' replaces P-47; 'in the south plant' changes place but must not grant access to south-plant records. Track each constraint's origin, confidence and scope, then apply explicit user changes before searching. Conversation caches need the resulting permission and constraint identity in their keys.
Ask when reference resolution is unsafe
'What about that one?' may point to two passages from the previous answer. Picking one silently can produce a well-cited answer to the wrong question. Clarify when multiple antecedents remain plausible, or search both only if a comparison was requested and permissions allow both. Do not use the last retrieved passage as the default referent merely because it was ranked first. A bounded clarification step is cheaper than a confident but irrelevant retrieval. Abstention also applies to unresolved dialogue state.
Prevent answer contamination
The previous assistant answer may be wrong, incomplete or injected. Rewrites should rely on authenticated conversation metadata and user turns, then retrieve fresh source evidence. Do not copy a previous answer's unsupported number into the next query as though it were a fact. When the user asks 'why did that change?', retrieve both applicable revisions and compare their cited text. Temporal retrieval preserves the two evidence sets rather than blending old and new values.
Judge turn-by-turn retrieval
Evaluate follow-ups with pronouns, topic switches, corrections, permission changes, long gaps and contradictory prior answers. Score resolved entity and constraints before measuring passage recall and final support. A system can retrieve the correct passage for a wrong rewrite by luck; that should not hide the rewrite defect. Store the conversation turn ID and corpus generation in the trace. When a user revokes or changes scope, previously cached passages must not reappear in later turns.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class SearchTurn:
entity: str | None
revision: str | None
tenant: str
def resolve_follow_up(previous: SearchTurn, current_text: str,
active_tenant: str) -> SearchTurn:
text = current_text.casefold()
if "p-48" in text:
entity = "P-48"
elif "p-47" in text:
entity = "P-47"
elif "old one" in text and previous.entity:
entity = previous.entity
else:
raise ValueError("ambiguous entity; ask for clarification")
revision = "previous" if "old one" in text else None
return SearchTurn(entity, revision, active_tenant)
last_turn = SearchTurn("P-47", "r4", "north")
assert resolve_follow_up(last_turn, "What about the old one?", "north") == SearchTurn(
"P-47", "previous", "north")
assert resolve_follow_up(last_turn, "Now compare P-48", "north") == SearchTurn(
"P-48", None, "north")Performance and operating cost
The example resolves one turn in O(L) time for text length L and O(1) additional state. A production resolver may inspect a bounded window of T turns, increasing work with that window and with each retrieval retry. Avoid feeding the entire dialogue into every search when only an explicit entity and recent correction are needed. Record and evaluate clarification frequency as part of latency and success.
Common Mistakes
- Carrying an old entity after the user explicitly switched topics.
- Treating a prior assistant answer as a verified source for the next query.
- Taking tenant access from dialogue text instead of the active session.
- Resolving an ambiguous pronoun to the first-ranked passage without asking.
Validation drill
Write 59 multi-turn queries with corrections, topic changes and ambiguous references. Record rewrite accuracy, authorized passage recall and final support, and require clarification for turns with no unique antecedent.
