Skip to content

Reuse a stored embedding only for the model that made it - #38873

Closed
manerow wants to merge 1 commit into
mainfrom
fix/embedding-model-on-stored-vectors
Closed

manerow wants to merge 1 commit into
mainfrom
fix/embedding-model-on-stored-vectors

Conversation

@manerow

@manerow manerow commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Describe your changes:

Follow-up to PR #38415 and PR #38517, and the document-level half of PR #38845: that PR flags an index built for another model, this one makes the rebuild replace its vectors.

The bug. After a switch to another embedding model of the same vector size, OpenMetadata keeps the old model's vectors. Every path keeps a stored vector while its fingerprint (a hash of the entity's text) matches, and a model switch changes no text. So reindex, the chunk backfill, live edits and reembed all keep them, and semantic search silently compares new-model queries with old-model vectors. reembed embeds nothing and reports success. Chunk reuse never checked the vector size either.

What changes.

  • Every doc that carries a vector records the model that made it: embeddingModel (model id) and embeddingDimension, on entity docs and chunk docs, mapped in every index (chunk doc version 9 adds them to existing chunk indexes).
  • One rule wherever a stored vector is kept: reuse it only when its fingerprint matches the current text and its recorded model equals the configured one (EmbeddingModel, StoredEmbeddingReuse, ChunkHeader.holdsVectorsOf). Fingerprint and model stay separate facts; the dimension is part of the model.
  • reembed ignores stored vectors, counts an entity only when both writes succeed, and exits 1 when any entity failed.
  • The embedding field list, copied four times, has one source.

Decision record: ADR:2026-11-11-reindex-reuses-an-embedding-only-when-its-fingerprint-matches, amended (v3).

Upgrade note. No existing doc records its model, so every embedded entity is embedded once more by the first reindex (or write) that touches it: one paid provider call per chunk, the cost of embedding the catalog once. Locally, 22 entities written by main cost 23 calls on the first Search Indexing (22 chunks, one pre-flight), then 1.

Type of change:

  • Bug fix

Tests:

  • Unit: new EmbeddingModelSwitchTest (in-memory engine, two stub models of one dimension). On main 7 of 10 cases and the new EmbeddingEnricherTest splice case fail (model B never called); the same-model controls pass. Here all pass.
  • StoredEmbeddingReuseIT, OpenSearch 3.4.0 and Elasticsearch 9.3.0: 6/6; on main the 2 new scenarios fail on both.
  • Search, vector and reindex packages: 3694 tests; the one failure (JobRecoveryOrphanDetectionTest) fails on main too. OntologyTermBulkWrite only takes the shared field list and rule, so has no unit test.

Manual testing performed

Elasticsearch 9.3.0, MySQL, a stub with two 16-dimension models (B permutes A's space). 22 entities embedded with A, then switched to B:

Step on model B main this PR
Search Indexing (staged rebuild) 1 call; 22/22 entity and chunk docs keep A 23 calls; all B
reindex --force again 1 call; all A 1 call; all B, reused
reembed 0 calls, "completed successfully"; all A 22 calls; all B
PATCH a field outside the embedded text 0 calls; keeps A 1 call; that table is B
Search "weather readings from field sensors" unrelated seed entities weather first

Checklist:

  • I have added a test that covers the exact scenario we are fixing.

@manerow
manerow requested a review from a team as a code owner November 26, 2026 14:09
@manerow
manerow requested a review from IceS2 November 26, 2026 14:09
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@manerow manerow added the skip-pr-checks Bypass PR metadata validation check label Nov 26, 2026
@gitar-bot

gitar-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Adding embedding-model fields across entity and chunk mappings upgrades catalog search schemas; the first reindex may re-embed all vectors, changing retrieval and provider load.

Stores the embedding model id and dimension on every vector-bearing entity and chunk doc, and reuses a stored vector only when its fingerprint matches and its recorded model equals the configured one. This fixes stale vectors surviving a model switch of the same dimension across reindex, chunk backfill, live edits, and reembed. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@manerow

manerow commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by PR #38882: the same change, stacked on PR #38845 so it uses that PR's EmbeddingModel. Merge it after PR #38845.

@manerow manerow closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant