Guides · Models & ML
Model registry
Keep each model’s serving version in a row. Promote or roll back with one write and no deploy.
- In the schema
- —
What you’ll build#
You will track each model’s active serving version in the same database that holds its features, with four guarantees.
- One place to look
- A single slot row names the serving, previous and shadow versions for each model.
- No deploy to switch
- Promoting a version takes one write, and the new version scores the very next request.
- A way back
- Rolling back takes one write too and never leaves a slot without a serving version.
- Traceable predictions
- Every prediction records the model version that produced it, so you can trace any regression straight back to a promotion.
Before you start#
This guide builds on Model serving, whose schema already declares these two types. Only the service key may modify Model and Slot rows. Any signed-in caller may read both types, since the query that scores a claim runs as the requesting caller.
type Model { required name: str; required version: str; constraint exclusive on ((.name, .version));} type Slot { required name: str { constraint exclusive; }; required serving: Model; previous: Model; shadow: Model;}Keep versions in slots#
The query that loads a model’s features also reads its active version. The handler passes that version to your model server and records it alongside the prediction, so no version is hard-coded in the handler.
Single-query feature and version read
scoreClaim reads the claim’s features alongside Slot.serving.version and Slot.shadow.version in one statement, so prediction logging never drifts from the version that scored the request.
select Claim { # … the claim's features … model := assert_single((select Slot filter .name = 'claims-risk')).serving.version, shadow := assert_single((select Slot filter .name = 'claims-risk')).shadow.version,}filter .id = <uuid>$claimselect Slot { name, serving: { version }, previous: { version }, shadow: { version },}Because one statement reads both the features and the version, a request is never scored by one version while logged under another’s name.
Add a version#
Each version is a row. The first version under a model name opens the slot, and later versions start in shadow, where your handler scores requests alongside the serving version without showing shadow results to users.
insert Model { name := <str>$name, version := <str>$version,}insert Slot { name := <str>$name, serving := assert_exists((select Model filter .name = <str>$name and .version = <str>$version)),}update Slotfilter .name = <str>$nameset { shadow := assert_exists((select Model filter .name = <str>$name and .version = <str>$version)),}A missing version cannot enter a slot. The statement fails and leaves the slot unchanged. See Evals for how shadow predictions are recorded.
Promote in one write#
Promoting moves serving to the new version and preserves the old version in previous. The promotion runs as one atomic statement, so the slot never serves zero versions or two at once.
Atomic slot promotion after CI evals
promoteModel shifts serving to the candidate and preserves the prior version in previous in one statement, or previews the before-and-after diff with --dry-run.
update Slotfilter .name = <str>$nameset { previous := .serving, serving := assert_exists((select Model filter .name = <str>$name and .version = <str>$version)), shadow := {},}Roll back in one write#
Rolling back swaps serving and previous atomically. Both assignments read the slot’s prior values and exchange the two versions in place. If previous is empty, the statement fails and leaves the slot unchanged.
update Slotfilter .name = <str>$nameset { serving := assert_exists(.previous), previous := .serving,}Running rollback a second time undoes a mistaken rollback and restores the original serving version.
Check promote and roll back#
# 1. What serves now.napalm call notes slots # 2. Promote, and look again: serving moved, previous holds the old version.napalm call notes promoteModel --name claims-risk --version v5napalm call notes slots # 3. Roll back, and the two have changed places.napalm call notes rollBackModel --name claims-risknapalm call notes slots # 4. What a promotion would change, without making it.napalm call notes promoteModel --name claims-risk --version v5 --dry-runAfter step 2, calling scoreClaim records a prediction with model set to v5. After step 3, the next prediction records v4 again. Neither switch requires a deploy.