24/38
Part 4 of 6 · Generation and latencyLearn and do

Precompute what you can, and give a new message 2 seconds

Most of the work can happen before the agent opens the ticket.

One ticket, over timeWhen the suggestion is computed
routed, then waiting in the queuewhile it waits: ready when the agent opens it
the customer sends a new messagewithin a 2-second target, with the first cited step on screen and the rest streaming in

Two moves take most of the latency off the agent's clock:

  1. Precompute. A ticket waits in a queue before an agent opens it. Compute the first suggestion then, so it's ready on arrival.
  2. Stream. Show the first cited step as soon as it's written. Order the output so each step streams with its citation.

That leaves the case you can't precompute: a new customer message mid-conversation.

Assume the target is the first cited step on screen within 2 seconds at p95, the time that 95 of every 100 requests finish within. Assume a mid-size cross-encoder costs about 3 ms per candidate on a GPU.

Slide the rerank count to 150, Anthropic's number, and watch the budget.

New customer message to first cited step, p95Interactive
Redact the new message30 ms
Rewrite query, extract filters300 ms
BM25 and dense search, in parallel60 ms
Fuse with RRF2.0 ms
Rerank candidates150 ms
Prefill the 6,000-token prompt450 ms
Stream the first step, about 40 tokens670 ms
Verify the first step40 ms
Total1.7 s of 2.0 s
budget 2.0 s
Fits, with 298 ms to spare

Rerank candidates: 3000 µs per item.

At 50 candidates the stages add up to 1,702 ms, with 298 ms to spare. At 150 the rerank takes 450 ms, and the total is 2,002, over by 2 ms.

The levers, cheapest first:

  1. Rerank fewer candidates.
  2. Use a smaller reranker.
  3. Shorten the prompt with fewer chunks and a trimmed conversation.
  4. Use a faster model for the first step.

Notice what's not on the list. The search itself, at 60 ms, is the smallest real stage.

In the editor, write total_ms(rerank_n) and max_rerank(budget_ms): the widget's budget as code. FIXED_MS holds the stages whose time doesn't depend on how many candidates you rerank.