Guides · Models & ML
Evals
Check a new model version against the serving version. Score a golden set in CI, shadow live traffic and turn misses into cases.
- CLI
napalm call- In the schema
ext::napalm::Job
What you’ll build#
You will verify that a candidate model version matches or beats the active serving version before promotion across four stages.
- A golden set
- Saved
EvalCaserows holding exact input features and expected verdicts. - A gate in CI
- A harness scores a candidate, records every
EvalResultand fails the build on any lost case. - A shadow
- The candidate scores live requests beside the serving version without exposing candidate verdicts to users.
- A growing set
- Any wrong answer in production promotes directly into
EvalCasewith the exact features sent.
Before you start#
This guide builds on Model serving, whose schema declares EvalCase, EvalResult and Prediction and whose handler records each prediction alongside its input features. You need the same service key and a script that calls a named model version.
| Stage | Runs | Tells you |
|---|---|---|
| Golden set | The candidate scores every case in CI. | Tells youWhether the candidate still gets every known case right. |
| Shadow | A background job scores each live prediction again with the candidate. | Tells youHow the candidate performs on real production traffic. |
| Serve | The Slot moves serving to the candidate. | Tells youEvery prediction records the model version that produced it. |
Score the golden set#
Three deployed queries read the golden set, record a candidate’s verdicts and compare two model versions. Recording an entire run executes as one atomic statement, replacing any prior results for that candidate version.
select EvalCase { id, name, features, expected }order by .namefor result in json_array_unpack(<json>$results) union ( insert EvalResult { eval_case := <EvalCase><uuid>result['case'], model := <str>$model, verdict := <str>result['verdict'], latency_ms := <int32>result['latency_ms'], } unless conflict on ((.eval_case, .model)) else ( update EvalResult set { verdict := <str>result['verdict'], latency_ms := <int32>result['latency_ms'], } ))with mine := (select EvalResult filter .model = <str>$candidate), theirs := (select EvalResult filter .model = <str>$serving),select { total := count(mine), passed := count(mine filter .passed), serving_passed := count(theirs filter .passed), mean_ms := (math::mean(mine.latency_ms) if count(mine) > 0 else 0.0), regressions := ( select mine { name := .eval_case.name, verdict, expected := .eval_case.expected } filter not .passed and .eval_case in (select theirs filter .passed).eval_case ),}Compare and fail the build#
Compare a candidate directly against the active serving version rather than a static pass-rate threshold. Any case that serving passes and the candidate loses fails the CI gate and prints the regressed EvalCase by name.
Pairwise regression gate and live shadow scoring
evalCompare diffs candidate EvalResult rows against the serving version in CI to block regressions, while shadowScore evaluates Slot.shadow asynchronously on live Prediction.features.
# evals/golden.pyimport osimport sysimport time import httpx from model import score # your model call: score(version, features) -> verdict candidate, serving = sys.argv[1], sys.argv[2]headers = {"Authorization": f"Bearer {os.environ['NAPALM_KEY']}"} with httpx.Client(base_url="https://notes.napalmdata.com", headers=headers, timeout=60) as napalm: def call(name: str, **variables): return napalm.post(f"/query/{name}", json={"variables": variables}).raise_for_status().json()["data"] results = [] for case in call("evalCases"): started = time.monotonic() verdict = score(candidate, case["features"]) results.append({ "case": case["id"], "verdict": verdict, "latency_ms": round((time.monotonic() - started) * 1000), }) call("recordEvalResults", model=candidate, results=results) [compared] = call("evalCompare", candidate=candidate, serving=serving) for lost in compared["regressions"]: print(f"lost {lost['name']}: said {lost['verdict']}, expected {lost['expected']}")print(f"{candidate}: {compared['passed']} of {compared['total']}; {serving}: {compared['serving_passed']}") # Fail on any case the serving version gets right and this one doesn't, or on a lower score overall.sys.exit(1 if compared["regressions"] or compared["passed"] < compared["serving_passed"] else 0)# .github/workflows/evals.yml- name: Score the golden set env: NAPALM_KEY: ${{ secrets.NAPALM_KEY }} run: python evals/golden.py v5 v4Shadow a version on live traffic#
A golden set covers only the cases you already anticipated. Setting a candidate on Slot.shadow queues a background job alongside every live prediction so the candidate scores real requests asynchronously without adding caller latency.
Candidate shadow slot
Setting a candidate version on Slot.shadow schedules parallel evaluation on live requests without exposing unverified verdicts to callers.
Asynchronous shadow job
A background ext::napalm::Job invokes shadowScore after the served answer returns, keeping candidate latency and failures off the caller path.
Hidden shadow prediction
recordShadow writes a hidden Prediction row linked via shadow_of using the frozen Prediction.features snapshot.
select Prediction { id, features, claim: { id }, candidate := <str>$model,}filter .id = <uuid>$prediction and not exists .shadow_of// app/actions/[action]/route.ts, beside scoreClaimasync shadowScore(call) { type Served = { id: string; features: Record<string, unknown>; claim: { id: string }; candidate: string } const [served] = call.rows as Served[] const model = served.candidate const scored = await fetch(`${process.env.MODEL_URL}/v1/predict`, { method: 'POST', headers: { Authorization: `Bearer ${process.env.MODEL_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ model, features: served.features }), }) if (!scored.ok) throw new Error(`The model answered ${scored.status}`) const { score, verdict } = (await scored.json()) as { score: number; verdict: string } const napalm = await call.db() const recorded = await napalm.fetch('https://notes.napalmdata.com/query/recordShadow', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ variables: { prediction: served.id, claim: served.claim.id, model, features: served.features, score, verdict }, }), }) if (!recorded.ok) throw new Error(`The shadow answer wasn't recorded: ${recorded.status}`) return { verdict }},insert Prediction { claim := <Claim><uuid>$claim, model := <str>$model, status := PredictionStatus.Completed, features := <json>$features, score := <float64>$score, verdict := <str>$verdict, shadow_of := <Prediction><uuid>$prediction,}- Nobody waits
- The shadow job runs after the caller receives the served answer, so a slow or failing candidate costs users nothing.
- Hidden from callers
- Each shadow
Predictionlinks to the served prediction viashadow_of, and the claimant’s read policy excludes rows carrying that link. - Exact input parity
- The candidate scores the frozen
Prediction.featuressnapshot stored on the served prediction rather than re-reading mutable rows.
with shadows := (select Prediction filter .model = <str>$model and exists .shadow_of)select { compared := count(shadows), agreed := count(shadows filter .verdict ?= .shadow_of.verdict),}When the two versions disagree, inspect the diverging predictions, since disagreement often highlights cases where the candidate improved over the serving model.
Turn a miss into a case#
Whenever a served prediction proves wrong in production, promote it into EvalCase with the corrected verdict. Copying Prediction.features verbatim locks in the exact inputs the model saw.
insert EvalCase { name := <str>$name, features := assert_exists((select Prediction filter .id = <uuid>$prediction).features), expected := <str>$expected,}A golden set that never grows drifts away from real requests. Add cases from production as a habit, and retire cases whose right answer has changed.
Check the evals#
# 1. A model that gets every case right passes.python evals/golden.py v4 v4; echo "exit $?" # 2. Break one case's expected verdict, score a candidate, and the build fails with the case named.python evals/golden.py v5 v4; echo "exit $?" # 3. After some live traffic with a shadow set: how often it agreed.napalm call notes shadowAgreement --model v5The first run exits 0. The second prints the lost case and exits 1. The third reports the number of shadow predictions compared and the number that agreed. When the candidate passes, promote the candidate.