Embeddings: store the embed-model fingerprint and refuse a mismatched config #189

Open
opened 2026-10-26 21:40:55 +00:00 by cameron · 0 comments
Owner

Problem

Stored vectors are only searchable with the model, dimension and prefixes that produced them, and nothing enforces that. Changing [embedding] in llm.toml, or the embed model behind llama-swap, without running reembed_embeddings silently breaks similarity search. Today the only guards are a comment and the per-row dim check.

Proposal

  • Store a fingerprint of the embedding contract (backend + model id + dim + hash of the query/document prefixes) once, in a small table or a user_ai_prefs-style single row, written by reembed_embeddings and on the first embed into an empty corpus.
  • At startup, compare it with the resolved [embedding] config. On a mismatch, log an error naming both sides and the fix (reembed_embeddings). Refuse to embed, or only warn? To decide.
  • model_version columns already carry per-row labels (LocalLlm::embedding_model_version). Decide whether the fingerprint replaces or complements them.

Notes

  • Follow-up from the llm.toml work (branch feat/llm-config-file, ADR-0003). That branch's startup check already warns when llama-swap's embed metadata.dim differs from embedding.dim. It doesn't catch prefix or model swaps of the same width.
  • Needs a migration. Back up the prod DB and prove the change on a copy first.
## Problem Stored vectors are only searchable with the model, dimension and prefixes that produced them, and nothing enforces that. Changing `[embedding]` in `llm.toml`, or the `embed` model behind llama-swap, without running `reembed_embeddings` silently breaks similarity search. Today the only guards are a comment and the per-row dim check. ## Proposal - Store a fingerprint of the embedding contract (backend + model id + `dim` + hash of the query/document prefixes) once, in a small table or a `user_ai_prefs`-style single row, written by `reembed_embeddings` and on the first embed into an empty corpus. - At startup, compare it with the resolved `[embedding]` config. On a mismatch, log an error naming both sides and the fix (`reembed_embeddings`). Refuse to embed, or only warn? To decide. - `model_version` columns already carry per-row labels (`LocalLlm::embedding_model_version`). Decide whether the fingerprint replaces or complements them. ## Notes - Follow-up from the llm.toml work (branch `feat/llm-config-file`, ADR-0003). That branch's startup check already warns when llama-swap's embed `metadata.dim` differs from `embedding.dim`. It doesn't catch prefix or model swaps of the same width. - Needs a migration. Back up the prod DB and prove the change on a copy first.
cameron added the needs-triage label 2026-10-26 21:40:55 +00:00
Sign in to join this conversation.