CortexDB · docs

Changing embedding model or dimensions on an existing data dir

Operator runbook for the one migration CortexDB refuses to do by accident: moving a populated data dir from one embedding model/width to another. Design and evidence: docs/design/REEMBED_MIGRATION.md.

Use the online path first (0.16.0, a single node): POST /v1/admin/reembed builds the new indexes beside the live ones while the server serves, and the restart that configures the new model swaps them in. Vector recall never stops. The offline path below it (drop and refill) serves no vector recall over the dropped families — BM25 only until its refill completes; it stays the path for a cluster, a server with a segment store, and a dir the online path refuses for another reason.


Online: re-embed while serving (/v1/admin/reembed)

For a single node (not a cluster data node) with no segment store (CORTEX_ICE_URL unset); tenant-sharded vector indexes (CORTEX_VECTOR_TENANT_SHARDS) are copied shard by shard. Every call is the trusted operator's (the static CORTEX_API_KEY); a start, a cancel and a cleanup also need admin.compact. The full contract is docs/API_REFERENCE_V1.md §8.15.8.

  1. Plan. The dry run is the default and changes nothing:

    curl -s -X POST http://localhost:3141/v1/admin/reembed -H "Authorization: Bearer $CORTEX_API_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"to": {"provider": "local", "model": "potion-multilingual-128M"}}'
    

    to takes the names you would configure: provider as CORTEX_EMBEDDING_PROVIDER, model as CORTEX_EMBEDDING_MODEL (or CORTEX_LOCAL_EMBEDDING_MODEL for local), dims as CORTEX_EMBEDDING_DIMS. A remote model's key and URL come from the server's own environment or settings, never from the request: set them there first. local alone is potion-multilingual-128M on any server. The answer names the target's pin, the rows of each vector family, an estimate (inputs, tokens, cost_usd at the price book's rate for a remote model, the disk and memory the copies take) and every entry of blockers that would refuse a start: the dry run makes the start's checks short of loading the model (a remote key; a local model's files and, for a transformer, an ONNX Runtime library the server's user must not be able to write). restart_with is what step 4 configures.

  2. Start. The same body with "dry_run": false answers 202 with the job. Add "retain_old_index": true to keep the old indexes after the swap until step 6. The server keeps serving from its current indexes while a background worker embeds every row again with the target, on CORTEX_REEMBED_THREADS threads (default a quarter of the cores), pausing while memory is high or the disk guard reads warn or critical (paused says which). A remote target's calls land in the usage ledger under the role reembed.

  3. Watch. GET /v1/admin/reembed (or cortexdb_reembed_* on GET /metrics) until state is ready: the copies are complete, and they stay current with every write, forget, erasure and retention change from then on. Nothing has changed yet. You can stay here as long as you like, restart on the current configuration (the job resumes), or cancel (POST /v1/admin/reembed/cancel deletes the copies).

  4. Swap. Stop the server gracefully (SIGTERM, or the console's Restart server now, which stops the same way and exits 75 for the supervisor: the stop embeds the job's last writes and records the copies exact), set restart_with in its configuration (the unit or compose file, or the console's Settings, which accepts the change once the job is ready), and start it. Before storage opens the boot renames the copies into place, moves the pin and checks the result (REEMBED_SWAPPING, REEMBED_PIN_MOVED, REEMBED_VERIFIED in the log). It then serves on the new model.

  5. Check. GET /v1/admin/reembed: state is swapped and verify.ok is true. POST /v1/admin/index-audit {"vectors": true} reports missing_vectors_total: 0. After a crash rather than a graceful stop the job reads swapping, phase repairing, for a while: the swap embeds with the new model the rows the copy may have missed (REEMBED_REPAIR), then reads swapped. verify.missing counts vector-index rows (one per chunk), the log's REEMBED_REPAIRED counts events, each with all its chunks.

  6. Clean up, only after retain_old_index or a verify.ok of false (which keeps the old index whatever you asked): POST /v1/admin/reembed/cleanup deletes reembed/<job_id>/old/. Until then no new job starts, and an erasure's proof says the kept index is unproven (reembed_old_index).

What a restart does with a job:

JobStarted withWhat happens
readythe new modelThe swap (step 4)
building or readythe current modelThe job resumes; a ready job that stopped gracefully stays ready
buildingthe new modelExit 78 REEMBED_NOT_READY, nothing changed: restart on the current model and let it finish, or cancel
swappingthe new modelThe swap finishes from where it stopped
swapping, pin not yet movedthe current modelThe renames are undone; the job is ready again
swapping, pin movedthe current modelExit 78 REEMBED_SWAP_INCOMPLETE: start with the new model
swappedthe current (old) modelExit 78 EMBEDDING_PIN_MISMATCH: the dir is the new model's now

Going back. Before the swap, cancel. After it, run another job to the old model (the same procedure), or restore the cold backup taken before the swap. A 0.15.x binary ignores reembed/ and refuses a dir swapped to a local: model, a provider it does not know.

Backups. scripts/cold_backup.py leaves reembed/ out (a job's copies are rebuilt, never restored) and refuses to back up during a swap; cortexdb restore-check drops the job of a restored dir.

What it does not carry. The code plane's index (its own provider), the artifact semantic projection (it refills itself after a model change), and the vectors inside declared records in the source log, which nothing rewrites.

Its cost. CPU time for a local model, the provider's bill for a remote one (the dry run's cost_usd), and disk for a second set of vector indexes until the swap deletes the old one (estimate.disk_bytes). Measured on an AWS m7i.4xlarge (Xeon Platinum 8488C; the server on 12 of its 16 vCPUs, so the job on 3 threads), a copy of the LongMemEval-S store (467,123 events, 1,021,568 chunk-index rows, OpenAI text-embedding-3-small at 1,536 dims, 32 tenant shards, 6.8 GB) moved to potion-multilingual-128M int8:

Job, start to ready342 s (about 3,000 rows a second), no provider call, no row unresolved
Process memory4.6 GiB at the start, 7.4 GiB at the peak (the copy's graphs and RocksDB write buffers)
Disk beside the live indexes0.88 GB
Graceful stop0.55 s, the copy exact
The swapping restartready in 28 s (the renames and the pin in 26 ms; every check passed); the dir then 3.05 GB
In-call voice recall, with a granite job running on the same storep50 2.29 ms, p99 2.99 ms (2.21 and 2.62 ms with no job)

A transformer target embeds about ten times slower than a static one: granite-embedding-107m-multilingual ran at about 340 rows a second on the same 3 threads.


Which situation are you in?

This table is for a boot that already refused. If you mean to change the model, run the online path before you restart.

Symptom at startupWhat changedGo to
FATAL [EMBEDDING_PIN_MISMATCH]: embedding provider mismatch: data dir … is pinned to 'X' but the configured provider resolves to 'Y' (exit 78)provider/model/width (for a local model also its revision or precision; the message names each field that differs)below
FATAL [VOICE_PROFILE_CONFIG]: embedding provider mismatch: … under CORTEX_PROFILE=voicean API-embedded dir meets the in-process embedderMoving to the local provider
FATAL [LOCAL_EMBEDDING_CONFIG]: the local model …'s vectors moved: … (VOICE_PROFILE_CONFIG under the profile)the same local model, but a build that embeds differentlyWhen a local model's build moves its vectors
vector index dimension mismatch: on-disk index at … is N-dim but the configured embedding model is M-dimthe widthDimension change
Neither, but /v1/admin/index-audit reports embedding_repina provider switch was booted with ALLOW_REPIN aloneSame-width switch

Both startup messages are load-bearing and neither is a nuisance. Their main job is catching a lost API key silently demoting a real corpus to mock vectors. If you did not intend to change the embedding configuration, fix the configuration — do not reach for a flag.


Dimension change: drop and rebuild

Read the cost first. From the moment the rebuild drops the indexes until a refill completes, the store serves no vector recall over the dropped families — BM25 only, for as long as it takes to re-embed the corpus. Writes keep working; /v1/recall keeps answering, on lexical evidence alone. Plan the window, or use the online path where it applies.

CORTEX_EMBEDDING_REBUILD_VECTORS=1 authorizes one destructive rebuild. When the boot also changes the pin (CORTEX_EMBEDDING_ALLOW_REPIN=1, a new embedding space), every vector index that holds anything is deleted, whatever its width, and recreated empty at the configured width: a same-width index would otherwise score its old vectors against queries of the new space. Without a pin change, only the indexes whose on-disk width no longer matches the configured model are. There is no selective re-embed and there never will be — nothing in the store records which provider produced a given vector row, so there is no predicate to select on (design §4.1).

Procedure

  1. Back up the data dir. scripts/cold_backup.py with the server stopped. This step destroys vectors; the WAL is the authority and every vector is rederivable from it, but a backup turns a bad afternoon into a restore.

  2. Stop the server.

  3. Restart once with both flags:

    CORTEX_EMBEDDING_MODEL=text-embedding-3-large \
    CORTEX_EMBEDDING_DIMS=3072 \
    CORTEX_EMBEDDING_ALLOW_REPIN=1 \
    CORTEX_EMBEDDING_REBUILD_VECTORS=1 \
    ./cortexdb
    

    ALLOW_REPIN authorizes the pin change; REBUILD_VECTORS authorizes the deletion. Both are required, and each says something different.

  4. Read the banner. The drop announces itself before it happens:

    ================================================================================
      CORTEX_EMBEDDING_REBUILD_VECTORS=1 — DESTRUCTIVE VECTOR REBUILD
    ================================================================================
      DROPPING (every vector in these indexes is deleted): chunk (/data/vector, 1536-dim), …
      Recreating them EMPTY at 3072-dim for provider openai-http:text-embedding-3-large:3072.
      Vector recall will return NOTHING from these families until a refill
      completes — BM25 only, for as long as the corpus takes.
    

    If you do not see it, nothing was dropped — check whether the flag was already spent (below).

  5. Refill chunk vectors:

    curl -X POST localhost:3141/v1/admin/index-audit \
      -H 'content-type: application/json' -d '{"repair":true,"vectors":true}'
    

    Synchronous, one embedding batch per event, and idempotent and resumable: detection is "is a row present", so a re-run picks up exactly what is still missing and a crash mid-repair costs progress, not correctness. Re-run until missing_vectors_total is 0. On a large corpus this is a real invoice — it re-embeds every chunk.

  6. Re-derive the other families. See the next section. This is the step most likely to be skipped, and the audit will keep telling you about it until you do it or accept it.

  7. Confirm. A final {"repair":true,"vectors":true} call retires the rebuild record once every dropped family is populated again, and only then does the audit report "clean": true.

The flag is spent after one use

The first boot that honors the flag writes <data_dir>/embedding_rebuild.consumed. While that file exists, CORTEX_EMBEDDING_REBUILD_VECTORS=1 authorizes nothing — a later width change hits the ordinary refusal. This is deliberate: a flag left behind in a systemd unit or compose file must not lie in wait for the next config typo or upstream model rename. To authorize another rebuild, delete the marker file as a separate, deliberate act.

The flag is also spent when it finds nothing to drop, for the same reason.


Moving to the local provider (voice mode)

Voice mode (CORTEX_PROFILE=voice, VOICE_MODE.md) embeds in the server process, so a data dir that an API embedded meets a different embedding identity, and the boot refuses:

FATAL [VOICE_PROFILE_CONFIG]: embedding provider mismatch: data dir /data is pinned to
'openai-http:text-embedding-3-small:1536' but the configured provider resolves to
'local:potion-multilingual-128M@73908c3438cf:256:int8' (provider openai-http -> local, width
1536 -> 256 dims): another vector space, … Ways out: …

On a single node, the online path makes the move with no BM25-only window: a job to {"provider": "local", "model": "potion-multilingual-128M"} (the profile's default), then the restart with CORTEX_PROFILE=voice, which swaps the copies in. Otherwise the move is the drop and rebuild above, with the local model as the new configuration. Nothing is re-embedded silently. What differs from an API-to-API move:

Procedure (single node)

  1. Back up the data dir (scripts/cold_backup.py, server stopped).

  2. Stop the server.

  3. Restart once with the profile and both flags:

    CORTEX_PROFILE=voice \
    CORTEX_EMBEDDING_ALLOW_REPIN=1 \
    CORTEX_EMBEDDING_REBUILD_VECTORS=1 \
    ./cortexdb
    

    Without the profile, CORTEX_EMBEDDING_PROVIDER=local and CORTEX_LOCAL_EMBEDDING_MODEL=potion-multilingual-128M (or granite-embedding-107m-multilingual) do the same. In the Docker image the models are already in /opt/cortexdb/models, and in a release tarball in models/ beside the binary; CORTEX_EMBEDDING_URL, _MODEL and _DIMS, which the image sets for OpenAI, are ignored. The banner of step 4 above names the dropped indexes and the new identity (local:…), and the log records the model's canary (LOCAL_EMBEDDING_CANARY_RECORDED, below).

  4. Remove both flags from the unit or compose file. ALLOW_REPIN is for this one restart, and the rebuild flag is spent once it has run.

  5. Refill the chunk vectors: POST /v1/admin/index-audit {"repair":true,"vectors":true}, again until missing_vectors_total is 0 (the steps above, 5 to 7).

  6. Re-derive the entity, derived and summary families if the deployment uses them (below). Voice deployments usually run with enrichment off, and then those families are legitimately empty.

Moving back to an API provider is the same procedure with the API's configuration.

Between the two local models, and between precisions

A local model's pin is local:<model id>@<source revision, 12 hex>:<dims>:<precision>: another model, revision, width or precision is another identity, and the start refuses naming the fields that differ. The same procedure moves between them:

How the model's files were made and what runs them (a new ONNX Runtime, an int8 file made again, a move to another CPU) is not in the pin: that is the model's build, which the canary checks instead.

Clusters

A data node refuses CORTEX_EMBEDDING_ALLOW_REPIN and CORTEX_EMBEDDING_REBUILD_VECTORS in its [engine], and a scope move refuses two shards with different pins (EMBEDDING_MISMATCH). Move a cluster by copying: POST /v1/export from the old cluster and /v1/import/jsonl into a new one whose data nodes all carry [engine] profile = "voice"; every capture is embedded once, by its new shard's leader. Two copies exist until the old one is destroyed, so an erasure in that window must reach both.


When a local model's build moves its vectors

A local model's pin names its vector space, not its files. Beside the pin, the data dir keeps embedding_provider.local.json: twelve canary texts (short and long, six languages, emoji, special markers) with the vectors the dir's first pin made of them, and the build of the last start that served the dir (the SHA-256 of the model, tokenizer and ONNX Runtime files, the runtime, the CPU architecture and, for a transformer, the int8 features the CPU has). Every start of a local model embeds the canary texts again, before any store opens, and compares them, text by text, with the stored vectors:

Model kindAccepted at cosineWhy
static (potion-multilingual-128M)0.99999Its arithmetic is this server's own f32 code, the same on every CPU: a rebuild is bit for bit the same, and one token tokenized otherwise moves a short text by several percent
transformer (granite-embedding-107m-multilingual int8)0.995ONNX Runtime's int8 kernels differ by CPU: its Arm kernels (five Arm cores, emulated) against x86 with AMX measured 0.9975 at the lowest; another quantization of the same model measured 0.988, and AVX2's saturating products 0.46

Ways out of the refusal:

  1. Keep the dir's vectors: start the release that embedded the dir, or point CORTEX_LOCAL_EMBEDDING_DIR at a models directory holding its files (and CORTEX_LOCAL_EMBED_ORT_LIB at its ONNX Runtime library).
  2. Re-embed with this build: back the dir up, then restart once with CORTEX_EMBEDDING_ALLOW_REPIN=1 and CORTEX_EMBEDDING_REBUILD_VECTORS=1. The log says LOCAL_EMBEDDING_REEMBED, the canary is recorded again with this build's vectors, and every vector index is dropped (the banner of step 4). Remove both flags, then refill as in steps 5 to 7.

The record is written by the first start of a local model (LOCAL_EMBEDDING_CANARY_RECORDED), by a repin to a local model, and when the build changes; it is removed when the dir moves to a provider that is not local. A record that does not parse refuses the start: restore it from a backup of the dir, or delete it to take this start's model as the dir's, only when this start's files and runtime are the ones that embedded the dir.

On a cluster each data node checks its own record, written at its own first start: the check holds a node to its own past, not to the other replicas, so two data nodes of a shard on different CPU architectures are not compared with each other. A data node refuses the repin flags, so a node whose build moved starts again on the release whose build embedded its shard, or the cluster moves by export and import.


What the refill does and does not cover

There are four vector families, each with its own dimension guard, and /v1/admin/index-audit rebuilds exactly one of them.

FamilyDirectoryRefilled by the audit?How it comes back
chunkvector / vector_shardspartlyindex-audit {"repair":true,"vectors":true} rebuilds EVENT chunks; enrichment rebuilds the fact/triple/summary rows that share this index
entityentity_vectornore-run enrichment (CORTEX_ENRICHMENT_DELAY_SECONDS) over the corpus
derivedderived_vectorsnore-run the fact/layer builds — see the warning below
summarysummary_vectors / summary_vector_shardsnore-run the rollup pass per scope with summaries enabled; summary_vector_reconcile re-embeds each fresh persisted summary

The audit's repair re-derives an event's chunks from the WAL and re-embeds them. It never writes the other three families, so a clean chunk audit is not evidence that they are back.

The online path drops nothing: it copies all four families, and the fp16 layer_vectors rows, before the swap, so nothing needs re-deriving after it.

The chunk row is partly, not yes, and the distinction has teeth. Enrichment writes fact, triple and summary vectors into the SAME chunk index, and repair re-derives event chunks only. A measured store went 43 rows -> 15 across a drop and a complete repair — one per event — and the audit then reported missing_vectors_total: 0, because nothing in the store records that the other 28 rows ever existed. Re-run enrichment to rebuild them; fact dedup means doing so duplicates nothing. Treat a clean chunk audit as "every event has its chunk vector", which is what it actually proves, and not as "this index is whole". Since v0.9.12 the audit reports all four on every call (vector_families), and a family that is empty while the store still holds the rows that should have populated it is reported as empty_but_expected — the audit will not answer "clean": true over it.

The derived family cannot self-heal after a width change. The bounded online backfill replays the persisted fp16 layer-vector rows into the derived index; after a width change those rows are the OLD width and every one of them is skipped (they are not inserted at the wrong width — that would seed the new index with unusable rows). Fact and belief embeddings come back only by re-running the fact/layer builds, which re-embed from the fact text.

If your deployment does not use entity resolution, derived layers or rollup summaries — enrichment is off by default, and so are derived embeddings and rollup summaries — those families are legitimately empty and the audit says so (expected_at_least: 0, empty_but_expected: false). The rebuild record still names any family whose directory was dropped; delete <data_dir>/vector_rebuild_pending.json to accept the store as it is.


Same-width switch: the silent one

Changing provider or model without changing the width trips no index guard at all. With CORTEX_EMBEDDING_ALLOW_REPIN=1 alone the store boots, the vector index opens, BM25 answers, recall returns results — and every one of them is scored in the old embedding space against queries embedded in the new one. Nothing re-indexes.

There is no automatic detection: no vector row records which provider produced it, and the repin has already overwritten the only provider identity in the store. What there is instead:

To re-embed, run the procedure above with both flags: a repin with CORTEX_EMBEDDING_REBUILD_VECTORS=1 drops every vector index whatever its width. After a repin booted without it, the pin has already moved and the flag finds no new space to drop for: stop the server, delete the vector index directories listed in the table above by hand, restart, and follow steps 5-7. Then delete the repin marker.


Recovering from a refused boot

A boot that is refused changes nothing. Since v0.9.12 the pin is written only after storage initialisation succeeds, so a dimension guard that refuses the boot leaves the data dir exactly as it was and the store still starts on its previous configuration with no second ALLOW_REPIN. (Before that, a failed dimension migration rewrote the pin and then refused, stranding the data dir on a configuration that could not serve it.)

If the rebuild itself fails partway — a directory that cannot be deleted — nothing is recorded as consumed and the boot is refused, so fixing the permissions and restarting retries the whole thing.


Files this leaves in the data dir

FileWritten byCleared by
embedding_provider.pinevery boot that opens storagenever (it is the pin)
embedding_provider.local.jsonthe first start of a local model, a repin to one, a changed build, a re-embed (canary)the first start under a provider that is not local
embedding_provider.repin.jsona repin that changed the pinyou, after re-embedding
embedding_rebuild.consumedthe boot that honored the rebuild flagyou, to authorize another rebuild
vector_rebuild_pending.jsonthe rebuild, naming each dropped familyan index-audit repair once every named family is populated, or you
reembed/job.jsonan online re-embed's start, then the jobthe next job's start; restore-check drops it
reembed/<job_id>/the job: its copies, and after the swap the old indexes in old/the swap, a cancel or a failed job (the copies); the swap's check or POST /v1/admin/reembed/cleanup (old/)