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.
-
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"}}'totakes the names you would configure:providerasCORTEX_EMBEDDING_PROVIDER,modelasCORTEX_EMBEDDING_MODEL(orCORTEX_LOCAL_EMBEDDING_MODELforlocal),dimsasCORTEX_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.localalone ispotion-multilingual-128Mon any server. The answer names the target's pin, the rows of each vector family, an estimate (inputs, tokens,cost_usdat the price book's rate for a remote model, the disk and memory the copies take) and every entry ofblockersthat 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_withis what step 4 configures. -
Start. The same body with
"dry_run": falseanswers202with the job. Add"retain_old_index": trueto 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, onCORTEX_REEMBED_THREADSthreads (default a quarter of the cores), pausing while memory is high or the disk guard reads warn or critical (pausedsays which). A remote target's calls land in the usage ledger under the rolereembed. -
Watch.
GET /v1/admin/reembed(orcortexdb_reembed_*onGET /metrics) untilstateisready: 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/canceldeletes the copies). -
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_within 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_VERIFIEDin the log). It then serves on the new model. -
Check.
GET /v1/admin/reembed:stateisswappedandverify.okistrue.POST /v1/admin/index-audit {"vectors": true}reportsmissing_vectors_total: 0. After a crash rather than a graceful stop the job readsswapping, phaserepairing, for a while: the swap embeds with the new model the rows the copy may have missed (REEMBED_REPAIR), then readsswapped.verify.missingcounts vector-index rows (one per chunk), the log'sREEMBED_REPAIREDcounts events, each with all its chunks. -
Clean up, only after
retain_old_indexor averify.okoffalse(which keeps the old index whatever you asked):POST /v1/admin/reembed/cleanupdeletesreembed/<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:
| Job | Started with | What happens |
|---|---|---|
ready | the new model | The swap (step 4) |
building or ready | the current model | The job resumes; a ready job that stopped gracefully stays ready |
building | the new model | Exit 78 REEMBED_NOT_READY, nothing changed: restart on the current model and let it finish, or cancel |
swapping | the new model | The swap finishes from where it stopped |
swapping, pin not yet moved | the current model | The renames are undone; the job is ready again |
swapping, pin moved | the current model | Exit 78 REEMBED_SWAP_INCOMPLETE: start with the new model |
swapped | the current (old) model | Exit 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 ready | 342 s (about 3,000 rows a second), no provider call, no row unresolved |
| Process memory | 4.6 GiB at the start, 7.4 GiB at the peak (the copy's graphs and RocksDB write buffers) |
| Disk beside the live indexes | 0.88 GB |
| Graceful stop | 0.55 s, the copy exact |
| The swapping restart | ready 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 store | p50 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 startup | What changed | Go 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=voice | an API-embedded dir meets the in-process embedder | Moving 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 differently | When 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-dim | the width | Dimension change |
Neither, but /v1/admin/index-audit reports embedding_repin | a provider switch was booted with ALLOW_REPIN alone | Same-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
-
Back up the data dir.
scripts/cold_backup.pywith 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. -
Stop the server.
-
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 \ ./cortexdbALLOW_REPINauthorizes the pin change;REBUILD_VECTORSauthorizes the deletion. Both are required, and each says something different. -
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).
-
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_totalis0. On a large corpus this is a real invoice — it re-embeds every chunk. -
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.
-
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:
- The window is minutes, not tens of minutes, with the static default. Embedding needs no
network and no provider quota. On the build box (24 cores), this procedure refilled a dir of
2,006 single-chunk events in 0.6 s with potion-multilingual-128M, about 3,200 events a second, and
the embedding bench's Python harness embedded LongMemEval-S's 515,720 chunks with the same model
in about 3 minutes on 2 vCPUs. With
granite-embedding-107m-multilingualthe same refill took 6.6 s, about 300 events a second: the refill embeds one event at a time, so it runs on one write worker, which embeds about 180 LongMemEval-sized chunks (83 tokens) a second. A dir that size takes about 50 minutes with granite. The refill's cost is CPU time, not an invoice. - Recall is BM25-only until the refill ends, as for any drop. Writes keep working, and each new write is embedded locally as it is indexed.
Procedure (single node)
-
Back up the data dir (
scripts/cold_backup.py, server stopped). -
Stop the server.
-
Restart once with the profile and both flags:
CORTEX_PROFILE=voice \ CORTEX_EMBEDDING_ALLOW_REPIN=1 \ CORTEX_EMBEDDING_REBUILD_VECTORS=1 \ ./cortexdbWithout the profile,
CORTEX_EMBEDDING_PROVIDER=localandCORTEX_LOCAL_EMBEDDING_MODEL=potion-multilingual-128M(orgranite-embedding-107m-multilingual) do the same. In the Docker image the models are already in/opt/cortexdb/models, and in a release tarball inmodels/beside the binary;CORTEX_EMBEDDING_URL,_MODELand_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). -
Remove both flags from the unit or compose file.
ALLOW_REPINis for this one restart, and the rebuild flag is spent once it has run. -
Refill the chunk vectors:
POST /v1/admin/index-audit {"repair":true,"vectors":true}, again untilmissing_vectors_totalis0(the steps above, 5 to 7). -
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:
- potion-multilingual-128M ↔ granite-embedding-107m-multilingual (256 ↔ 384 dims).
- The same model at another precision (
…:256:int8against…:256:fp32) keeps the width, and the rebuild still drops every vector index, because the pin changes. For the static model's int8 and fp32 forms the vectors differ very little (cosine 0.99998 on average), but the pin treats them as two identities.
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 kind | Accepted at cosine | Why |
|---|---|---|
static (potion-multilingual-128M) | 0.99999 | Its 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.995 | ONNX 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 |
- Within the tolerance, with a build that differs: the start goes on, logs
LOCAL_EMBEDDING_BUILD_CHANGEDwith what changed (for example the ONNX Runtime library of a new release, or another CPU), and records the new build. The first pin's vectors stay the reference. - Past it: the start is refused, exit 78,
LOCAL_EMBEDDING_CONFIG(VOICE_PROFILE_CONFIGunder the profile), naming the lowest cosine, the text and what changed since the dir was embedded. Nothing in the dir is written. The vectors the dir holds and the ones this build would make are two spaces, and mixing them would corrupt recall.
Ways out of the refusal:
- Keep the dir's vectors: start the release that embedded the dir, or point
CORTEX_LOCAL_EMBEDDING_DIRat a models directory holding its files (andCORTEX_LOCAL_EMBED_ORT_LIBat its ONNX Runtime library). - Re-embed with this build: back the dir up, then restart once with
CORTEX_EMBEDDING_ALLOW_REPIN=1andCORTEX_EMBEDDING_REBUILD_VECTORS=1. The log saysLOCAL_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.
| Family | Directory | Refilled by the audit? | How it comes back |
|---|---|---|---|
| chunk | vector / vector_shards | partly | index-audit {"repair":true,"vectors":true} rebuilds EVENT chunks; enrichment rebuilds the fact/triple/summary rows that share this index |
| entity | entity_vector | no | re-run enrichment (CORTEX_ENRICHMENT_DELAY_SECONDS) over the corpus |
| derived | derived_vectors | no | re-run the fact/layer builds — see the warning below |
| summary | summary_vectors / summary_vector_shards | no | re-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:
- the repin writes
<data_dir>/embedding_provider.repin.json, and /v1/admin/index-auditreports it asembedding_repinon every call, with the remediation spelled out, until you delete the file.
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
| File | Written by | Cleared by |
|---|---|---|
embedding_provider.pin | every boot that opens storage | never (it is the pin) |
embedding_provider.local.json | the 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.json | a repin that changed the pin | you, after re-embedding |
embedding_rebuild.consumed | the boot that honored the rebuild flag | you, to authorize another rebuild |
vector_rebuild_pending.json | the rebuild, naming each dropped family | an index-audit repair once every named family is populated, or you |
reembed/job.json | an online re-embed's start, then the job | the 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/) |