Measuring an AI assistant: quality, latency and cost in one table
So far I have built an assistant that answers questions about my own Go database. At every step I
could say “it got better.” This week I asked how I would find out that it got worse. A model
upgrade or a prompt tweak can quietly break answers that worked yesterday. So I built the part that
goes red: an evaluation harness and a regression gate. CI for a component that never gives the same
output twice.
What I built
golden set (50 questions, facts verified) ──▶ run ──▶ report: score · judge · p50/p95 · tokens · $
│
baseline report ──▶ gate ──▶ exit 0 / exit 1
- A golden set of 50 questions (21 “how”, 14 “where”, 15 “failure”), each with gold files and
the key facts a correct answer must state. - An LLM judge with a fixed rubric and structured output, plus Cohen’s kappa and a
hand-grading tool to measure how often it agrees with me. - A regression gate that fails on a score drop, newly failing questions, or cost growth.
- A model suite that runs several models under one shared budget.
The numbers I have so far:
| Score | p50 / p95 | Tokens | Cost | |
|---|---|---|---|---|
| No retrieval | 0.385 | 1.27 / 2.09 s | 9,113 | $0.019 |
| BM25 retrieval | 0.727 | 1.17 / 1.74 s | 60,876 | $0.030 |
That is 50 questions on gemini-3.5-flash-lite, scored by key-fact recall. Retrieval on its own, re-run
on all 50: BM25 recall@5 0.96, MRR 0.80. A GPT-2 embedding baseline gets 0.22 and 0.18.
The concepts that made it work
- Three metric families, measured apart. Retrieval, answers, and cost and latency fail for
different reasons. A model upgrade should not move recall@5 at all; if it does, something else
changed. - Quality, latency and cost in one row. Retrieval made the prompt about 7 times bigger, cost
$0.011 more for all 50 questions, and p95 latency went down. In one table that is a decision you
can see. In three dashboards it is three arguments. - A string match is a weak ruler. Of the 5 zero scores with retrieval, 4 were correct answers in
other words: “removes the temporary file” where the fact was.merge. My agent answered “October
15, 2026” where the fact was2026-10-15. A judge model can read meaning. It can also catch
“does NOT use X”, which contains the fact and is wrong. - Kappa, not accuracy. A judge that says “correct” to everything agrees 80% of the time with a
human who marks 80% correct, and its kappa is 0. Below about 0.6, a judge should gate nothing. - Compare per question, not only the mean. A flat mean can hide four breaks and four fixes.
The thing that bit me
My first prompt for the no-retrieval baseline mentioned <context> tags, even when no context was
sent. The model took that as an invitation. In 37 of 50 answers it invented code from my repository:
functions, constants, file names. Those invented answers scored higher on key facts than honest
ones: 0.50 against 0.32. Made-up identifiers and numbers matched the facts by luck.
Any fixed scorer can be gamed, and a model will game it without trying. The prompt fix was one
line. The lesson was bigger: a score is a claim, and it needs its own test. Growing the set from 20
to 50 questions then showed that one of my key facts was wrong. I expected the word random for the
election timeout, but the code says rand.Int63n. The fact came from my memory, not the code, so it
rewarded an answer for guessing rather than reading. Now a test opens every gold file and checks that
all 50 questions’ facts are really there.
Tradeoffs & the road not taken
- The judge ran, and it didn’t earn trust. On the retrieval run it scored the answers 0.82 against
0.695 for key facts, and it rescued answers that were right in other words. Then I measured it. A
Claude model graded 15 of the same answers blind, checking every claim against the code. Exact
agreement was 73%, but kappa was 0.39, under my 0.6 bar. Every disagreement was one step apart,
and once the judge passed an answer with a false claim in it. The judge is the same small model that
wrote the answers, because the larger ones timed out on my key, and a model grading itself is
lenient. So key-fact recall stays the gating score. My own hand grades come next, and they’re the
comparison that counts. - Absolute grades, not pairwise. “Is B better than A?” is more stable, but fixed grades let one
baseline serve every comparison. - Fixed thresholds, no error bars. The gate fails on a drop over 0.05, more than 2 newly failing
questions, or cost up more than 50%. On 50 questions a small drop can be noise. Bootstrap
confidence intervals are the honest next step. - Offline only. A golden set catches the cases I thought to write down. Production adds user
feedback and canary traffic for the rest.
The gate itself is proven. A test breaks the system prompt on purpose (“Answer in one word.”), and
the gate reports mean score 1.00 -> 0.00 and 6 newly failing questions, then exits 1. One more bug
lived in the suite: once the shared budget was spent, it passed a cap of 0 to the next run, and 0
meant “no cap”. A test pins that now.
Where this sits in the system
Last week the assistant learned to act: native tool calls solved 9 of 10 tasks against 4 of 10 for
text ReAct on the same model. This week gave the project a build that can fail. Next week the
assistant goes behind a service with fallback between providers, and this gate says whether the
answers survive a switch.
Part of a series building an engineering knowledge assistant on real models, measured at every
step.