Skip to Content
Recodocs

12 · Route and cache requests

Decide when the Facilities Helpdesk can reuse an answer, when it needs a fresh lookup and which outcome to measure.

7 min read
Part 4
Operate and release
Model
Qwen2.5-1.5B-Instruct
Data
Synthetic facilities helpdesk
Hardware
Tesla T4 and CPU, in Google Colab
Open in Colab

The same question comes in again

The North Yard operator asks for fan F-250’s maximum temperature. The desk has the previous answer, 101 °C. The latest manual is now on the console. Decide whether you can send the previous answer or need a fresh read. If you send an old temperature limit, the crew may use it as today’s limit.

Industrial ventilation fan representing F-250
North Yard · operator · F-250

“What is the maximum temperature for F-250?”

Previous response · 101 °C · manual-F-250-r3
Snapshot r3

manual-F-250-r3

Maximum operating temperature: 101 C.

Snapshot r4-index

manual-F-250-r4

Maximum operating temperature: 99 C.

Check the reuse decision

On r3, the same operator and question can reuse 101 °C from manual-F-250-r3. On r4-index, reread the manual and return 99 °C from manual-F-250-r4.

The guest request is denied before the cache is checked.

Synthetic Facilities Helpdesk. Augapfel’s factory fan photograph illustrates F-250 and is cropped here. CC BY 2.0.

Change one fact. Keep the operator, tenant, fan and question fixed. Change the active source snapshot.

Active snapshotWhat should the desk do?
r3Reuse the answer tied to the current r3 manual.
r4-indexRead the updated manual, then return its limit and citation.

The typed route verified more requests and cut model calls

Identical queues of 40 requests. Paired change is relative to Always model.

1

Strict outcomes with family uncertainty

Verified requests · delta in pp with 95% paired interval

a
Route policyVerifiedΔ and interval
Always model8/40Reference
Cheap first28/40+50 [+16.7, +80]
Cold cache28/40+50 [+16.7, +80]
Warm cache28/40+50 [+16.7, +80]

Model calls

Calls per full replay

b
Route policyCalls
Always model32
Cheap first12
Cold cache12
Warm cache12
Source: verified Lesson 12 notebook, Tesla T4 with host CPU for guards, typed reads and cache.

Decide which questions need generation

Each arm starts with the same access check. The Always model arm sends every eligible question to Qwen. Cheap first gives the host a chance to perform a typed lookup or ask for clarification. If an eligible ticket asks for a supporting system as well as an inspection date, the typed route declines it and the model gets the prompt. F-250’s temperature question needs just the limit and the current manual ID, so a typed lookup can return both directly.

These confidence values are scores assigned by rules. A missing referent gets a clarification at 1.00, an explicit temperature lookup can qualify at 0.99, and an explicit inspection lookup can qualify at 0.94. The cutoffs were compared on the lower-numbered development family in each slice before replaying the other family.

# Admit a typed outcome only at the chosen threshold.
confidence, proposal = cheap_answer(case)
if proposal is not None and confidence >= cutoff:
    outcome, route = proposal, "typed"
    if key is not None:
        cache[key] = outcome

A cutoff of 0.94 accepted 12 of 20 eligible tuning requests. All 12 passed strict grading. The higher cutoffs also verified every proposal they admitted, with fewer cases covered. FrugalGPT similarly checks whether to accept a result or escalate to another model. RouteLLM’s thresholds vary across benchmark tasks and training sets, so measure the escalation policy on the requests it will handle. FrugalGPT, §§4–5 · RouteLLM, §5

The lowest checked cutoff admitted the most verified typed proposals

Tuning families only · all proposals at each cutoff passed strict grading

2
CutoffAdmitted / eligibleVerified / admittedPrecision
0.9412/2012/12100%
0.998/208/8100%
1.004/204/4100%
Source: verified Lesson 12 notebook, Tesla T4 with host CPU for guards, typed reads and cache.

The cold cache starts empty on the same queue. The warm cache starts with entries from the cold pass, then sees the identical queue. Both can serve an earlier typed outcome. Coverage measures the fraction of eligible requests handled by typed work or reuse:

coverage=Ntyped+NhitNeligible.\mathrm{coverage}=\frac{N_{\mathrm{typed}}+N_{\mathrm{hit}}}{N_{\mathrm{eligible}}}.

All three typed policies covered 20/32 eligible requests. Cold reuse handled six of the 40 total requests. Warm reuse handled 20. The denominator for hit rate includes guards, so it differs from the coverage denominator. A cold start is worth measuring separately when the saved work depends on state already being present. Amazon API Gateway documents that rebuilding a flushed cache can briefly raise origin traffic and latency. Amazon API Gateway cache settings

Warming the cache replaced typed reads one for one

Counts of observed routes · warm replay began with the cold pass’s cache

3
PolicyGuardTypedHitModelHit rate
Always model800320%
Cheap first8200120%
Cold cache81461215%
Warm cache80201250%
Source: verified Lesson 12 notebook, Tesla T4 with host CPU for guards, typed reads and cache.

Give a cached answer the same scope as the original

Caching reuses an answer to equivalent work, not any answer that sounds similar. The asset, access and freshness conditions must still apply to the new request.

The same words can ask a different question after a manual changes, or come from a different operator. The key includes the tenant, role, trusted source snapshot, resolved asset, remembered revision and the versions of the prompt and policy. Only eligible requests can reach that key.

# Decide access before an entry can be used.
outcome = access_guard(case)
key = cache_key(case) if outcome is None and cache is not None else None
if key is not None and key in cache:
    outcome, route = cache[key], "cache_hit"
# Trusted context determines whether two answers are interchangeable.
return AnswerKey(
    case["tenant"], case["role"], source_snapshot(case),
    reference_asset(case) or "", case.get("previous_version", ""),
    PROMPT_VERSION, POLICY_VERSION, canonical(case["question"]),
)

Cloudflare AI Gateway uses provider, endpoint, model, provider authentication and request body in its default exact-response cache key. The helpdesk adds its own trusted fields because the validity of a manual citation depends on local data and access. Complete-response reuse also differs from caching an exact prompt prefix. The Claude API can reuse prefix processing and still generate the output tokens. Cloudflare AI Gateway caching · Claude API prompt caching

The timed replay changes a snapshot key while holding its source facts fixed. In the separate F-250 probe below, r4 actually changes the limit. The guard also sees the exact r4 question from a guest, after an operator has already filled the cache.

The revision missed the cache. The guard denied the guest.

Separate F-250 probe · same question on every row

4
RequestSnapshotChecked cacheRouteResult
fan-1r3YesTyped101 °C
fan-2r3YesHit101 °C
fan-3r4-indexYesTyped99 °C
fan-4r4-indexYesHit99 °C
fan-5r4-indexNoGuardDeny
Separately, in the timed replay, the 2 changed-snapshot requests missed at cold start and hit at warm start. Each arm denied all 2 tenant-boundary requests before cache lookup.
Source: the saved F-250 revision probe, separate from the replay scorecard.

fan-2 · operator · r3 · What is the maximum temperature for F-250?

Expected
{"decision":"answer","value":"101","evidence":["manual-F-250-r3"]}
Observed
{"decision":"answer","value":"101","evidence":["manual-F-250-r3"]}

Cache hit on the unchanged trusted key.

fan-3 · operator · r4-index · What is the maximum temperature for F-250?

Expected
{"decision":"answer","value":"99","evidence":["manual-F-250-r4"]}
Observed
{"decision":"answer","value":"99","evidence":["manual-F-250-r4"]}

The new snapshot produced a cache miss and a typed lookup returned the updated evidence.

fan-5 · guest · r4-index · What is the maximum temperature for F-250?

Expected
{"decision":"deny","value":"","evidence":[]}
Observed
{"decision":"deny","value":"","evidence":[]}

The access guard denied the guest before cache lookup.

replay-000 · What is the maximum temperature for P-201?

Expected
{"decision":"answer","value":"70","evidence":["manual-P-201-r3"]}
Always model · exact raw reply
```json { "decision": "The maximum temperature for P-201 is 70°C.", "value": null, "evidence": [ "inventory-P-201-r3",
Cold cache · typed result
{"decision":"answer","value":"70","evidence":["manual-P-201-r3"]}

The model reply ends without closing the JSON and names an inventory record where the grade requires a manual. The typed path returned the expected value and evidence.

Read the P-201 row alongside the F-250 rows. The model reply contains the temperature inside a sentence, sets the value to null and cites an inventory record in an incomplete JSON response. The strict grader requires the decision, exact value and source IDs together. The typed result supplies all three. The F-250 probe checks that reusing such a result still depends on the current snapshot and the current caller.

Measure less work against the same outcomes

The replay uses six equipment families with ordinary, repeated and changed-snapshot requests. Compare matching request IDs and resample whole families for confidence intervals. The gain in the replay comes from manual reads, inspection-date lookups and clarifications. Multi-source and follow-up cases had zero wins. Their remaining model work is where a new route would need to prove itself.

Lookup and clarification account for the gains

Cold cache versus Always model · same request ID on both sides

5
SliceWinsLossesTies
Manual701
Inspection701
Multiple sources006
Ambiguity600
Access006
Follow-up006
Source: verified Lesson 12 notebook, Tesla T4 with host CPU for guards, typed reads and cache.

Track tail latency and work per verified outcome separately. Request time starts before the access check and ends when the outcome is ready to grade. Model time includes tokenisation, generation and decode, with GPU work synchronised. For VV verified outcomes:

model ms per verified=∑itmodel,iV.\mathrm{model\ ms\ per\ verified} =\frac{\sum_i t_{\mathrm{model},i}}{V}.

This denominator includes verified clarifications and denials, since they are correct desk outcomes. The FinOps Foundation makes the same distinction between infrastructure consumption and an outcome such as a resolved case. Here the numerator is measured wall time for generation calls, with zero model time assigned to CPU-only paths. It does not measure the bill, throughput under concurrency or the cost of keeping a cache hot. FinOps Foundation, Unit Economics

Fewer generation calls cut model time per verified outcome

Replay timings in ms · bars have a separate scale in each panel

6

p95 request latency

Guard to returned outcome, before grading

a
Policyp95, ms
Always model2157
Cheap first1921
Cold cache1839
Warm cache1879

Model wall time per verified outcome

Sum of model-call ms / verified results

b
Policyms / verified
Always model6398
Cheap first751
Cold cache727
Warm cache751
Source: verified Lesson 12 notebook, Tesla T4 with host CPU for guards, typed reads and cache.

The recorded p95 fell from 2,157 ms with Always model to 1,921 ms with Cheap first. The three typed policies all made 12 model calls, and remaining latency differences between their sequential replays should not be read as a capacity result.

What to keep

PolicyVerifiedModel callsCache hitsp95
Always model8/403202,157 ms
Cheap first28/401201,921 ms
Cold exact cache28/401261,839 ms
Warm exact cache28/4012201,879 ms
  • Check access before reuse. Deny a guest even after an operator has filled the cache for the identical question.
  • Version the answer’s source. Give r4 a different snapshot key so the crew gets the new limit and its citation.
  • Escalate beyond tested coverage. Keep the source and grade visible for tickets the typed route cannot answer.
  • Track passes with every saving. Plot strict outcomes alongside calls, hit rate and p95.

Next to try, not tested here:

  • Replay the same requests with a lower duplicate rate and compare cold-start hit rate.
  • Introduce a separate cacheable, verified multi-source route and check citation freshness across two source revisions.
  • Replay overlapping arrivals to measure whether simultaneous misses change model calls and p95.

How it was built

ItemSetting
ModelQwen/Qwen2.5-1.5B-Instruct at 989aa7980e4cf806f80c7fef2b1adb7bc71aa306
RuntimeTesla T4 and host CPU. Python 3.13.16, PyTorch 2.14.1+cu130, Transformers 4.51.3, Accelerate 1.6.0
DecodeGreedy, up to 48 new tokens. One model warm-up before the measured arms.
Development partition24 tuning cases across six families. 24 replay cases from the six other development families.
Replay mix24 ordinary, 12 exact repeats, two snapshot changes and two tenant-boundary requests
OutcomeExact decision, value and evidence IDs. All guards run before typed reads, cache hits or generation.
CacheStores typed outcomes only. Scope includes trusted tenant, role, source snapshot, asset, remembered revision, prompt version, policy version and canonical question.
TimingRequest p95 across 40 rows per arm. Model-call wall milliseconds summed separately.

Time and cost. The executed notebook completed in 150.5 seconds on the Colab T4 runtime. That whole-notebook time includes setup and differs from the replay measures. The lab reports model time per verified result and does not record a serving bill.

Download the executed notebook · Scorecard · Replay rows · F-250 revision rows · Runtime receipt

Run it yourself

Start with the F-250 revision probe to inspect the key and the actual citation. Use the tuning cells to reproduce the cutoff table, then the paired replay cells for the route, quality and cost figures.

  1. Change FAN_REVISION["limit"] to 97. Predict the returned value and cited ID for the r4 request. Check both in the saved probe.
  2. Set repeat_variants=() in build_queue. Predict how the cold hit rate changes, then compare the replay composition, hit rate and model calls.
  3. Set the accepted cutoff to 1.00 after tuning. Predict which previously typed tickets escalate. Compare the affected rows, verified counts and p95.

In Lesson 13, Turn traces into regressions, turn recorded failures into checks that can run again before a change ships.

How is this page?

Last updated on