Skip to content

Decision: switching the embedding model to another model of the same width keeps the vectors the old model made #4935

Open

Description

@yannickmonney

Summary

The knowledge base keeps vectors in one table per width (chunk_vectors_<width>), and those tables do not record which model made a vector. When an administrator changes the organization's embedding model in Settings to a different model of the same width, nothing is re-embedded: the old vectors stay, new queries are embedded by the new model, and search compares vectors from two different models. Search results get worse without any message. MCP refuses a change of model once the knowledge base holds anything; the app does not. This was first noticed on 2026-10-10 while building settings over MCP, and has been waiting for a decision since.

Anchors are at main da3b98b730 (2026-10-13).

What the repo says today

  • The vector tables hold chunk_id and embedding only, one table per width (services/db/migrations/knowledge-db/private_knowledge/00000000000015_chunk_vectors_by_width.sql:15-18). The supported widths are 256, 384, 512, 768, 1024, 1536, 2048, 3072 and 4096 (packages/shared/src/schemas/knowledge.ts:89-91). The shared public-web corpus has the same tables (services/db/migrations/knowledge-db/public_web/00000000000016_chunk_vectors_by_width.sql).
  • The app saves a model through POST /embedding and checks nothing about what is indexed (services/platform/backend/domains/knowledge/routes.ts:323-353, which calls saveKnowledgeEmbedding in embedding-save.ts:116).
  • What follows a save is decided by width. requeueDocumentsWithoutVectors re-queues the documents that have no vector of the width the model now states (services/platform/backend/domains/knowledge/service.ts:1600-1635). Its comment says: "Decided by what the corpus holds, never by comparing the old settings with the new: a save that leaves the width alone finds nothing here".
  • MCP refuses another model while documents or websites are indexed (EMBEDDING_CORPUS_NOT_EMPTY, rule MCP-R28: services/platform/backend/domains/knowledge/settings-resource.ts:90-101, test settings-resource.test.ts:144). Its hint sends the person to Settings › Data residency, "where what is indexed is queued again", which is true only when the width changes.

What was and was not observed

Read from the code above. I did not reproduce a degraded search with two same-width models on a running stack, so the size of the effect is not measured. In general two embedding models produce vectors in different spaces even when they are the same width; whether the degradation is large for any particular pair was not examined.

Options

  1. Re-embed on any model change: clear the organization's vectors of that width and re-queue every document, which costs the re-embedding a width change already costs.
  2. Record the model: add a model column to the vector tables and search and re-queue by model. A migration in every knowledge database, bring-your-own databases included; allows keeping both while re-embedding.
  3. Refuse in the app as MCP does: allow a model change only while the knowledge base is empty, and tell the person to remove and re-add.
  4. Leave as it is and warn in the page and the docs.

Whichever is chosen, the shared public-web corpus needs the same answer, and the MCP hint should say what is true.

Questions

  • How often does an organization move between two models of the same width? (Models with the same width from one vendor are common.)
  • Is the cost of re-embedding on a change acceptable to the people who change it?

Related

#4685 (settings over MCP, where MCP-R28 was written)

Activity

  1. added
    priority: medium
    needs discussion
    service: platform
    service: db
    on Oct 13, 2026
  2. yannickmonney commented on Nov 2, 2026

    @yannickmonney
    ContributorAuthor

    Documents and email bodies: handled on train by 8d148e30e (fix(platform): embed documents again after a change of embedding model), which reaches main with the next train. Websites are not covered and move to #5326.

    What the commit does, closest to option 2 above but with the model recorded per document rather than per vector:

    • Knowledge-db migration 17 adds a nullable private_knowledge.documents.embedding_model: the model whose vectors a document's chunks hold, by the name the settings state. Indexing stamps it on every claim, reuses stored chunks only under that model (no skip, no resume, no copy from a document another model embedded), and stops writing once a run of another model claimed the row.
    • A change counts when the model's name or its width differs. The provider does not count: the same model saved under the same name through another provider re-queues nothing. Names count as saved, so text-embedding-3-small and openai/text-embedding-3-small are two models.
    • The embedding save re-queues the completed documents and email bodies another model embedded, beside those with no vector of the width (requeueDocumentsNotEmbeddedByModel, renamed from requeueDocumentsWithoutVectors). While they wait, the documents' dense leg leaves out vectors whose document records another model; they are still found by their words.
    • Documents indexed before the release record no model and pass for the model stated. Saving or removing the model first stamps them with the model stated until then. A save that names another model is refused while the knowledge database does not answer, because after the change nothing would tell which model made them.
    • A file or an email body whose run read the settings before a save moved them goes back in the queue when its run ends, for a change of width too. The daily knowledge.reconcile_corpus re-queues whatever the stated model has not embedded, the backstop for what a save could not reach.

    What stays open here:

    • MCP-R28 is unchanged. Its hint ("where what is indexed is queued again") is now true for documents and email bodies on any change of model, and for websites only on a change of width.
    • An organization that switched to another model of the same width before this release keeps those documents as they are: at its next save they are stamped with the model stated then. Changing the width once, or removing and adding the documents again, embeds them anew.
    • During a rolling deploy the previous image records no model, so a model saved while the deployment rolls can leave a document that image indexes first with the old model's vectors (the knowledge spec's Not yet list).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds discussionpriority: mediumservice: dbservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions