Route identifiers, policy questions and aggregate requests to the right evidence path without rewriting away the user's constraints.
Retrieval query routing: preserve exact constraints before search
Classify the request before reformulation
A question containing case ID AX-47 and an exact error string needs a literal lookup; a paraphrase of a policy may need semantic retrieval. A count of cases by week belongs to a governed query over structured data. Treat these as different jobs. Extract the requested output, exact tokens, tenant scope and time boundary first. A reformulator may add synonyms, but it cannot replace AX-47 with a more common case or turn a count into a prose summary. Candidate retrieval starts after this contract is fixed.
Keep routing observable
Record the selected path and the reason: exact ID, natural-language passage, structured aggregation, or mixed evidence. Run lexical and semantic search in parallel for mixed requests, then merge permitted candidates. A vector match can help find related language, but it cannot establish that a literal identifier was present. If a required identifier is absent from the result, reject that candidate even when its embedding score is high. A SQL query must use an approved metric definition; generated SQL is not a substitute for permission checks.
Handle ambiguous follow-ups
For ‘What changed after that?’, resolve ‘that’ from the current conversation only when a single permitted document identity is clear. Carry the resolved ID, revision and time window into the new query. If two incidents were discussed, ask which one the user means. Never copy a previous user's context or a past authorization decision into a new session. Conversation boundaries need the same rigor as document permissions.
Evaluate the router as a component
Create a labeled set with identifiers, paraphrases, mixed questions, unsupported aggregates and ambiguous follow-ups. Count wrong-route decisions separately from search misses. An exact-search route can fail because the identifier was parsed incorrectly; a semantic route can fail because its candidate pool omitted the answer. Store the original query beside the routed form so reviewers can see what changed. Include at least one question where no source is eligible and require the no-answer path.
Worked contract
def route_support_query(question: str, case_ids: set[str]) -> dict[str, object]:
import re
requested_ids = set(re.findall(r"\bAX-\d+\b", question.upper()))
unknown_ids = requested_ids - case_ids
if unknown_ids:
return {"route": "no_match", "ids": sorted(unknown_ids)}
if re.search(r"\b(count|how many|per week)\b", question.lower()):
return {"route": "aggregate", "ids": sorted(requested_ids)}
if requested_ids:
return {"route": "hybrid_exact_first", "ids": sorted(requested_ids)}
return {"route": "semantic", "ids": []}
known_cases = {"AX-47", "AX-63"}
assert route_support_query("Why did AX-47 retry?", known_cases)["route"] == "hybrid_exact_first"
assert route_support_query("Count AX-63 cases per week", known_cases)["route"] == "aggregate"
assert route_support_query("Explain AX-91", known_cases)["route"] == "no_match"Performance and operating cost
Routing costs O(q + m) time for query length q and m extracted IDs in this small example. The expensive work is downstream: two search legs, an aggregation or a clarification turn. Log wrong-route rates by query family and cap simultaneous searches; a cheap router that silently drops an exact constraint wastes the entire answer pipeline.
Common Mistakes
- Treating an embedding score as proof of an exact case-ID match.
- Rewriting a user-specified date or identifier without retaining the original constraint.
- Sending an aggregate question to passage search and inventing a count from snippets.
- Resolving an ambiguous follow-up from a different session.
Validation drill
Build 47 labeled queries: 12 exact IDs, 12 paraphrases, 11 mixed requests, six aggregates and six ambiguous follow-ups. Report route accuracy for each family and inspect every false route before changing a threshold.
Read next
- Hybrid retrieval: fuse exact terms and semantic candidates by rank
- Retrieval caches and conversation turns: recheck access every time
- Retrieval design: compare lexical, semantic and reranked candidates
- Retrieval positives: query intent, passage identity and revision
Continue this retrieval path
- Multi-hop retrieval: build evidence chains with bounded searches
- Query expansion: add recall terms without changing the user's question
