Skip to the page

Guides · Models & ML

Model registry

Track model checkpoints and active serving slots as typed records so you can promote or roll back versions in one write.

In the schema
—

What you’ll build#

You will track each model’s active serving version in the same database that holds its features across four guarantees:

Single source of truth
One Slot row records the serving, previous and shadow versions for each model.
Zero-deploy switches
Promoting a version updates one row so the very next request scores against the new model.
Atomic rollbacks
Rolling back swaps serving and previous in one statement without leaving the slot empty.
Traceable predictions
Every prediction row logs the exact version that scored it so regressions trace straight 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.

dbschema/default.gel
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;}

Track 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 slot reads

Feature queries read the active and shadow versions in the same snapshot.

Select serving.version and shadow.version from Slot directly inside your feature query:

dbschema/queries/scoreClaim.edgeql
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>$claim

Deploy a companion slots query to inspect every model slot from the CLI or your internal dashboard:

dbschema/queries/slots.edgeql
select 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.

Register a new version#

Register each trained model checkpoint or endpoint tag as a Model row before assigning it to a slot:

dbschema/queries/addModel.edgeql
insert Model {  name := <str>$name,  version := <str>$version,}

The initial version under a model name creates the Slot row with openSlot:

dbschema/queries/openSlot.edgeql
insert Slot {  name := <str>$name,  serving := assert_exists((select Model filter .name = <str>$name and .version = <str>$version)),}

Subsequent candidates enter Slot.shadow through shadowModel to score live requests asynchronously without exposing shadow verdicts to users:

dbschema/queries/shadowModel.edgeql
update Slotfilter .name = <str>$nameset {  shadow := assert_exists((select Model filter .name = <str>$name and .version = <str>$version)),}

Referencing an unregistered version fails the statement and leaves the slot unchanged. Evals covers shadow scoring in detail.

Promote in one write#

Promotion executes as one atomic update on Slot, so concurrent traffic never observes an empty slot or two active versions at once.

Atomic slot promotion

Promoting assigns the candidate to serving and preserves the prior version.

promoteModel copies the current serving link into previous, points serving at the candidate and clears shadow:

dbschema/queries/promoteModel.edgeql
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:

dbschema/queries/rollBackModel.edgeql
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#

Your terminal
# 1. Inspect the active, previous and shadow versions for every slot.napalm call notes slots # 2. Promote v5 to serving and preserve v4 in previous.napalm call notes promoteModel --name claims-risk --version v5napalm call notes slots # 3. Roll back to swap serving and previous in one statement.napalm call notes rollBackModel --name claims-risknapalm call notes slots # 4. Preview a promotion diff inside a rolled-back dry run.napalm call notes promoteModel --name claims-risk --version v5 --dry-run

After step 2, calling scoreClaim records a prediction under v5, and after step 3, the next prediction records v4 again without redeploying your handler.

Type a word or two to search every docs page.