advanced28 min studyLesson 669 in Engineering

Query routing and reranker budgets

Allocate retrieval branches and candidate depth within an explicit latency model while measuring routing errors and tail behavior.

On this page

What you’ll understand

  • Compose serial and parallel stages without adding unrelated latency quantiles.
  • Calculate an integer candidate cap under a declared reranking cost model.
  • Evaluate routing quality and fallback behavior by query class.

A query containing an exact identifier may benefit from a lexical route, while a paraphrased question can need a dense branch and a richer reranker. Running every branch and reranking every candidate spends latency and compute that may not improve every query. Routing is therefore a policy over quality and resource use, not a free optimization. This lesson connects the candidate-and-reranker architecture in DPR and BERT reranking with explicitly hypothetical latency arithmetic.

Draw the request’s dependency path

Include query processing, routing, each retrieval branch, fusion, reranking, and any later response work. If two branches execute in parallel and fusion waits for both, their contribution is the slower branch’s completion, not the sum of their isolated durations. Shared resources can still make both slower under load. A branch that is optional at a deadline needs an explicit fallback and quality measurement. Canceling a client wait does not automatically stop every already submitted backend operation or release its compute immediately.

Routing features can include query length, identifier patterns, language, and validated uncertainty signals, but the policy must be evaluated on its actual mistakes. A cheap route that misses relevant evidence on a minority query class can look attractive in an aggregate latency average. Keep candidate recall, final relevance quality, and latency outcomes by route and query class. When a route changes the candidate distribution, a reranker threshold or fusion weight tuned on another distribution may need fresh validation rather than being carried over unchanged.

T≈Troute+max⁡(Tlex,Tdense)+Tfusion+Trerank(K)+TotherT\approx T_{\mathrm{route}}+\max(T_{\mathrm{lex}},T_{\mathrm{dense}})+T_{\mathrm{fusion}}+T_{\mathrm{rerank}}(K)+T_{\mathrm{other}}
This declared dependency model assumes lexical and dense branches run in parallel and later stages are serial. All durations share units, and K is candidate count. It is not a formula for adding separately measured p99 values or a claim that shared-resource contention is absent in deployment.↔ Scroll wide equations horizontally.

Candidate depth consumes a measured cost budget

A simple local reranker model uses a fixed setup cost plus a per-candidate term. It can help choose a preliminary cap, but batching, token lengths, padding, device occupancy, and queueing can make the real cost nonlinear. Fit and validate the model over representative operating conditions, and reserve slack for effects it does not capture. Candidate depth cannot exceed the eligible pool, and a cap of zero needs a defined skip-rerank result rather than an accidental empty response.

Tail-latency evaluation requires an arrival model and a load condition. Component percentiles cannot generally be added to obtain the end-to-end percentile, especially when queueing and shared contention correlate them. Measure complete request latency and its quality outcome, including timeouts and fallback results. A routing policy that simply drops difficult requests can improve latency among survivors while worsening user success. Report denominator and failure accounting so the apparent service improvement is not a consequence of excluding its expensive errors.

Kmax⁡=min⁡ ⁣(C,max⁡ ⁣(0,⌊D−S−Fa⌋)),a>0K_{\max}=\min\!\left(C,\max\!\left(0,\left\lfloor\frac{D-S-F}{a}\right\rfloor\right)\right),\qquad a>0
For a deterministic planning model, D is the deadline, S reserved slack, F all modeled fixed costs including reranker setup, a time per candidate, and C a nonnegative integer count of eligible candidates. This cap assumes F ≤ D − S. If F > D − S, even K = 0 exceeds the reserved budget and no nonnegative cap is feasible; a fallback must change the fixed work and the budget must be recalculated. The cap is not an end-to-end tail-latency guarantee or a measured hardware capacity.↔ Scroll wide equations horizontally.

Validate the route as part of the retrieval system

Compare a fixed baseline with the proposed routing policy on held-out traffic and labeled query classes. Log selected branches, candidate counts, token lengths, actual durations, and which relevant documents were absent before reranking. Keep a fallback that has a defined relevance and latency contract, and test whether its activation frequency shifts over time. Routing errors, retrieval misses, and reranker mistakes call for different corrections. Increasing reranker depth cannot recover a relevant document excluded by every selected branch.

The queue lab isolates one sustained-capacity effect. Reset, set arrival rate to 3 and service rate to 2, predict the backlog at one second, then Step twice: five units. Compare a fresh Reset with both arrival rate at 2 and service rate at 3 before two Steps: three units. This initial-four fluid queue has no query classes, branch routing, token-dependent batches, deadlines, or measured tail latency. It cannot certify a reranking service’s operating point.

Plan a candidate cap with explicit slack

Use a hypothetical 120-ms request budget and 10-ms reserve. Routing costs 5 ms; parallel retrieval branches cost 20 and 30; fusion costs 5; other serial response work costs 20. Reranking costs 10 ms setup plus 2 ms per candidate. At least 100 eligible candidates exist.

  1. The slower parallel branch contributes 30 ms. Fixed modeled costs total 5 + 30 + 5 + 20 + 10 = 70 ms, including reranker setup.

  2. After fixed costs and the 10-ms reserve, 120 − 70 − 10 = 40 ms remains for per-candidate work. The cap is floor(40/2) = 20 candidates.

  3. Planned execution is 70 + 20 × 2 = 110 ms, leaving the declared 10-ms reserve. This assumes the supplied deterministic costs; actual queueing, sequence lengths, and shared contention require measurement.

The result

The candidate cap follows a stated dependency and cost model, without claiming an observed p99 guarantee.

Explore the model

Interactive lab

Interactive lab · queue

Admission pressure on a limiting reranking resource

Reset, set λ = 3 and μ = 2, predict Q at one second, then Step twice: Q = 5. Compare a fresh Reset with both λ = 2 and μ = 3 before two Steps: Q = 3. This initial-four fluid model does not route queries or represent token costs, deadlines, or measured latency percentiles.

Admission pressure on a limiting reranking resourceFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 s

Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA rate imbalance can create backlog even when a per-request cost estimate looks acceptable.

Check your understanding

Two retrieval branches have separately measured p99 latencies of 20 and 30 ms. What is justified when they run concurrently before fusion?

Try it yourself

Use a 90-ms hypothetical budget with 10-ms reserve. Routing costs 5 ms, parallel retrieval takes 20 ms at its slower branch, fusion costs 5, other serial work costs 10, and reranker setup costs 10 plus 3 ms per candidate. There are 50 eligible candidates. Calculate the cap and planned elapsed time.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Include setup in fixed cost, reserve slack, then round the per-candidate allowance downward.

Compare with the solution

Fixed cost is 5 + 20 + 5 + 10 + 10 = 50 ms. Candidate allowance is 90 − 10 − 50 = 30 ms, so the cap is min(50,floor(30/3)) = 10. Planned elapsed time is 50 + 30 = 80 ms, leaving 10 ms reserve. These deterministic inputs do not establish a real service percentile or prove that ten candidates preserve relevance on every query class.

Take it with you

  • Compose request dependencies before budgeting candidate work.
  • A candidate cap depends on a validated cost model, eligible pool, and explicit fallback.
  • Routing quality and complete latency need class-specific evaluation under representative load.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.