An internal AI assistant had several answer paths behind it: one broad path that could handle most questions reasonably well, and a few specialist paths that were better for particular kinds of question. Before any answer could start, a routing step decided which path to use, and that step took 2–4 seconds on every request.
I designed and implemented the routing cascade that replaced it. About 70% of requests are now routed deterministically in under a millisecond. The rest go through a confidence check, and a specialist is chosen only when the evidence clearly points to one; otherwise the request takes the broad default.
Why this wasn’t a classification problem
The obvious framing is a classifier: read the question, pick one of the paths. Three things made that a poor fit.
The paths overlapped. Many questions could be answered well by more than one of them, so the “correct” label was often a matter of degree. Traffic was uneven: a few broad paths carried most requests and the specialist paths saw far fewer, so overall accuracy looked good even when specialist routing was poor. And the cost of mistakes wasn’t symmetric. Sending a question to the broad default when a specialist would have been slightly better costs a little quality. Sending it to the wrong specialist can produce a confident answer from the wrong source.
So the question changed from “which path is this?” to “is there enough evidence to leave the default?”
How a request is routed
incoming request
- 1
Deterministic checks
Normalize the text, then look for signals that settle the route on their own: exact identifiers, known patterns and phrasings.
→ Clear match: route immediately. This is the under-1 ms path for about 70% of requests.
- 2
Lexical and semantic evidence
Score the request against example questions for each route, using BM25 for exact terms and embeddings for questions phrased differently.
- 3
Confidence gate
Accept a specialist only if its score is high enough and clearly ahead of the next-best route.
Specialist route
Strong, well-separated evidence for one specialist.
Broad default
Anything ambiguous, close or weak.
The decisions that mattered
Cheap checks first. Most requests don’t need retrieval to be routed. Putting deterministic checks at the front means the common cases never pay for the expensive ones, and that is where the latency result comes from. It is also why routing doesn’t use an LLM call: a model in front of every answer would add back the delay the router exists to remove.
A specialist has to be earned. The default path is broad enough to answer ambiguous questions acceptably, so the router doesn’t need to be clever about every request. It needs to be right when it overrides the default. That means some questions a specialist could have handled still go to the default. I accepted that trade on purpose.
A clear lead, not just a high score. Two routes can both score well on the same question. When they are close, the router doesn’t really know, and picking the top one is a coin flip with extra steps. The gate looks at how far the best route is ahead of the next one, and falls back to the default when the gap is small.
How I measured it
Overall accuracy was the wrong number, because the dominant routes could hide failures on the smaller ones. I evaluated the router against an established system on representative data, using per-route precision, Macro F1 so the smaller routes counted as much as the large ones, confusion analysis to see which routes were being mistaken for which, and the rate of wrong-specialist routes specifically. Those results are what I used to tune the gate.
The latency figure above is for the routing step on the requests that take the deterministic path, not for the full answer.
What came after
Routing quality depends on the example questions behind each route, and gaps only show up as misrouted requests. I later built an improvement loop that runs outside the request path: an LLM reviews routed requests and proposes missing or weak examples, and a proposed set is kept only if routing does better on the test scenarios. The short version is a mini story.