Skip to content
Duoduo Mediaevidence to decision

Package 15 · Section 7.2

Latency Cost and Retrieval Route Optimization

Minimize cost and response time while preserving agreed evidence and decision quality.

Track
D · Inspection, optimization and operations
Level
Advanced
Version
v1.0
Status
Open · initial release
Explanation depthDepth

Learning objectives

  • Profile stage-level latency and spend.
  • Use model routing, batching, caching, dynamic retrieval and early exit.
  • Optimize against constraints rather than one metric.

In brief

The cheapest configuration per query is often not the cheapest per trusted answer. Optimization means measuring quality, latency and cost together, finding the efficient frontier and choosing a point that respects hard constraints.

Core concepts

15.1Where cost and latency come from

Cost accrues from embedding, retrieval, reranking, input tokens, output tokens and retries. Latency accrues from sequential calls, large contexts and long outputs. Measure both per stage.

Retries and fallbacks are hidden multipliers. Track them explicitly.

15.2Levers

Route easy queries to cheaper paths and models; cache stable answers and retrieval results; shrink context with better reranking; parallelize independent calls; cap output length.

Each lever has a quality risk. Caching can serve stale answers; smaller models can lose grounding.

15.3Pareto frontier

Plot configurations by quality and cost. Configurations that are worse on both are dominated and can be discarded. Choose among the remaining ones using the decision contract.

Hard constraints, such as groundedness above 0.95 on high-risk slices, are applied before choosing.

Worked example

Routing by query difficulty

Situation: All queries use a large model at $0.018 per query; 62 percent are simple lookups.

  1. 1Train a difficulty router on 1,000 labeled queries.
  2. 2Send simple queries to a small model with a smaller context.
  3. 3Measure: simple-slice correctness 0.93 vs 0.94; complex slice unchanged.
  4. 4Cost per query falls to $0.009; p95 latency falls from 4.1 s to 2.3 s.

Outcome: Cost per trusted answer falls 47 percent with all gates passing. A cheaper single-model setup was rejected because it failed the high-risk slice.

Decision rules

  • Measure cost per trusted answer, not cost per query.
  • Apply hard quality constraints before optimizing cost.
  • Discard dominated configurations.
  • Report cost and latency by stage.

Common pitfalls

  • Reporting mean latency, which hides tail delays.
  • Caching answers without invalidation on document change.
  • Optimizing average cost while a high-risk slice regresses.

Key vocabulary

Pareto frontier
The set of configurations not dominated on all objectives.
p95 latency
The response time under which 95 percent of requests complete.
Semantic cache
Reusing results for queries with equivalent meaning.
Model routing
Sending requests to different models based on predicted difficulty.

Tutorial outline

  1. 15.1P50, P95 and tail latency; concurrency and queueing.
  2. 15.2Token, embedding, index, tool and human-review costs.
  3. 15.3Quality-cost frontiers, constrained optimization and safe rollout.

Required artifacts

Profiler report, optimization experiments, frontier plot and rollout policy.

Evaluation evidence

Cost per trusted answer, quality by risk, tail latency, cache staleness and regression rate.