From a demo to a service
A single successful chat shows that the path can work once. A service must also handle slow requests, incompatible versions and several users arriving at once.
Open this chapter with experiments and audio
Define a request that can be tested
Specify the inputs, outputs and limits of the service. A document assistant might accept a question and a collection identifier, then return an answer, cited passage IDs and the model revision. The application should decide which collections a user may access before sending content to a model. Set a maximum input size and a maximum generation budget so an unusually long request cannot monopolize the queue.
The boundary between the API and the model matters. An HTTP success status tells you the server returned a valid response. It says nothing about whether a cited source supports the answer. Store enough metadata to trace a response to a model version, a prompt template and a document revision. Decide separately which prompt text is necessary to store and for how long.
Read a timeline from one request
Suppose the request arrives at time zero. Retrieval finishes at 0.20 s. The first generated token arrives at 0.80 s, and token 21 arrives at 1.80 s. Time to first token is 0.80 s. Across the 20 intervals after that token the model produced 20 additional tokens in 1 second. The decode rate is 20 tokens per second, while the whole request still took 1.80 s.
Averages can conceal slow requests. If most requests are short but a few are unusually long, inspect a high percentile as well. Always state which percentile definition you use, whether requests waited in a queue and whether model loading is included. Different definitions can make two dashboards disagree even when they record the same events.
from math import ceil
first_token, last_token, total_tokens = 0.8, 1.8, 21
print("Decode:", (total_tokens - 1) / (last_token - first_token), "tokens/s")
samples = sorted([0.4, 0.6, 0.7, 0.8, 3.1])
print("Mean:", sum(samples)/len(samples))
print("P95, nearest rank:", samples[ceil(0.95*len(samples))-1])Release a model with a fixed comparison
Keep a small evaluation set with expected evidence, outcomes and edge cases. Include a question whose answer is absent from the documents. Run the old and new versions against identical inputs. Compare grounded answers, unsupported claims, refusal when evidence is missing, response time and resource use. Check more examples than the one used while tuning the prompt.
A versioned release includes the runtime, model, configuration, prompt and index revision. A container packages dependencies, but external weights and documents still need versioning. If a release regresses, being able to restore the previous complete combination is more useful than having the old application code alone.
Make a failed request understandable
Record the stage that failed and a request identifier. Distinguish retrieval returning no evidence, a model timeout and a user cancelling a request. The user-facing response can then explain what actually happened. Bounded retries may help with a temporary connection failure. A repeated operation that sends a message or writes data needs a way to avoid duplicate effects.
For a service that quotes documents, search permissions, source labeling and limits on external actions belong in the application. Treat retrieved text as material to answer from. Give components only the data they need for the current request and avoid putting full private conversations into routine performance logs.
Can a service return HTTP 200 and still fail its evaluation?
Yes. A well-formed response may quote the wrong source or give a false answer. Test transport and task quality separately.
An average score can hide the very failure you care about
Two support assistants answer the same 100 saved requests. Ninety are ordinary questions and ten concern returns with an exception. A gets 81 ordinary cases and 8 exceptions right, scoring 89%. B gets 87 ordinary cases and 3 exceptions right, scoring 90%. The overall ranking favors B, while accuracy on the exception falls from 80% to 30%. Ten examples make the exception estimate uncertain. Inspect the changed cases and expand that slice before deciding.
Keep prompts, model revisions, retrieval corpus, allowed tools and grading rules with each run. Use a programmatic check for an order ID or numerical unit. For an ambiguous explanation, write criteria, have independent readers apply them and inspect disagreements. A model grader can lower review cost, but it also needs calibration on human-labeled examples. If the same model or checks supplied training rewards, reserve independent checks that were unavailable during development.
Suppose exceptions count four times as much. How does the choice change?
There are 90 + 4 × 10 = 130 weighted cases. A scores (81 + 4 × 8)/130 ≈ 86.9%. B scores (87 + 4 × 3)/130 ≈ 76.2%. The weights encode a decision about consequences. Publish them alongside the ordinary counts so a reader can contest them.
Revisit what the denominator of an evaluation measure counts →
Sources · Liang et al., 2022