Migrating embedding models in-place

Migrating embedding models in-place


Introduction​

Sooner or later you will want to upgrade your embedding model. The straightforward way to do this is to just build a new index (or a new named vector in Weaviate), and embed each document with the new embedding model.

This works well, and has the benefit that you can easily test both models before switching. However it comes with a major drawback, in that for a period of time, you need to store twice the number of vectors.

For use cases that are resource constrained, where you want to use a fixed amount of disk or memory, or are at very large scale where re-embedding everything is just too expensive, you may want to instead migrate vectors in-place and for a period of time have some documents use the old vectors, while new vectors are backfilled.

But how can we combine search results for two models?

  • Firstly, the old and new models are usually completely incompatible vector spaces, even having different dimensions.
  • Raw distances cannot generally be used to merge results as one model will return scores significantly closer for a given query.
  • Standard techniques to combine results like reciprocal rank fusion (RRF) fail in this situation as they assume the same documents can occur in both sets of queries.

The net result is your search quality drops into a compatibility valley as data is migrated.

The compatibility valley: search quality on NanoBEIR while migrating from bge-small-en-v1.5 to gte-modernbert-base, querying with one model or combining both with RRF

In the above graph we migrated NanoBEIR from bge-small-en-v1.5 to gte-modernbert-base which when complete lifts search quality (NDCG@10) from 0.627 → 0.664.

  • With the naive approach of querying with just one model, search quality decays depending on the proportion of data migrated.
  • RRF is better than the naive approach but suffers significantly at the tails (losing 37%) and search quality dips below the original model for the entire migration.

Combining the scores​

What we would like from each model is not “how similar is this document to the query” on a model’s independent scale, but a calibrated score from both models. This is something you can estimate, if you have a small reference set embedded with both models, and are happy to encode the query with both models.

To do this we take a sample (in the below experiments 5,000 random documents) and embed them with both models.

For each query:

  1. Embed the query with both models.
  2. Search old vectors with old query vector, new vectors with new query vector.
  3. Score the query against the (5,000) reference vectors returning the top (50) results.
  4. For each model, compute mean and std dev of top results.
  5. Rescale every search result (subtract mean, divide by std dev).
  6. Merge the two lists on the rescaled score.

The rescaled score is a z-score: how many standard deviations a result sits above a strong match. Because of this we call the approach reference z-score fusion.

Reference z-score fusion: the query is encoded with both models, each index is searched, scores are rescaled against the reference set and merged into one list

We tested 4 migrations on different datasets, and the results showed much better search quality than RRF during the migration.

Search quality during migration at four collection sizes, comparing RRF with reference z-score fusion

CorpusDocumentsMigrationNDCG@10, old → newRRFRef z-score fusionRef z-score fusion, all migrations
SCIDOCS26Kgte-modernbert-base → Qwen3-Embedding-0.6B0.195 → 0.228-40%-2.0%-0.5% to -2.3%
FiQA58Kbge-small-en-v1.5 → gte-modernbert-base0.403 → 0.522-38%-3.2%-1.6% to -3.2%
Quora523Kall-MiniLM-L6-v2 → bge-small-en-v1.50.877 → 0.889-36%-4.6%-3.1% to -4.7%
MS MARCO8.8Mgte-modernbert-base → DenseOn0.405 → 0.437-39%-7.1%-7.1% to -10.6%

Compared to RRF which can suffer up to a 40% drop in NDCG, reference z-score fusion produces much tighter results, with no large drop when the datasets are unbalanced (early or late in the migration).

One benefit of this approach is that nothing depends on how far the migration has progressed. The performance overhead is just brute forcing the reference vector sample with both query vectors (a few milliseconds on modern hardware).

We used a fixed 5,000 reference set (or 10% of the corpus if it has fewer than 50,000 documents) for all experiments above. One valid question is how sensitive is this approach to the size of the reference set? Obviously we don’t want this to be too large or it negates the benefits of not duplicating vectors.

The below graph shows what happens on the 4 datasets as the reference set increases. On larger datasets like MS MARCO (8.8M documents) the gap from ideal continues to decrease with a larger set (from a 7.1% drop to 3.4%). The decision on the size becomes a tradeoff between search quality and latency, and how much better the new model is.

Given we only need the top-k vectors from the reference set for the z-score calculation, a vector index could even be used at scale to store the reference vectors.

Shortfall below the ideal line against reference set size for four datasets

In Weaviate​

Here is the core approach in Weaviate using two named vectors, along with a full example that migrates NanoBEIR data from bge-small-en-v1.5 to gte-modernbert-base on a Weaviate HNSW index. Reference z-score fusion stayed within about 2% of the ideal line throughout the migration, while RRF dropped by up to 35%.

collection = client.collections.create(
"Docs",
vector_config=[
Configure.Vectors.self_provided(name="old"),
Configure.Vectors.self_provided(name="new"),
],
)

# assume the vectors start in the "old" named vector
# and goal is to migrate to the "new" named vector

collection.data.insert(properties=props, vector={"old": old_vector})

def ref_zscore(result, query_vector, reference_vectors):
# convert cosine to similarity
scores = 1.0 - np.array([o.metadata.distance for o in result.objects])
top = np.sort(reference_vectors @ query_vector)[-50:]
zscores = (scores - top.mean()) / top.std()
return list(zip(result.objects, zscores))

# while migrating, search both named vectors and merge on the z-score

old = collection.query.near_vector(
near_vector=q_old, target_vector="old", limit=10,
return_metadata=MetadataQuery(distance=True))

new = collection.query.near_vector(
near_vector=q_new, target_vector="new", limit=10,
return_metadata=MetadataQuery(distance=True))

old_hits = ref_zscore(old, q_old, ref_old)
new_hits = ref_zscore(new, q_new, ref_new)
results = sorted(old_hits + new_hits, key=lambda hit: -hit[1])[:10]

What about fine-tuned models?​

So far we have looked at migration between completely different models. Another good question is what happens to compatibility when fine-tuning embedding models?

A fine-tuned model starts from the old model’s weights, which means it starts out identical and drifts as more training occurs.

If it hasn’t drifted far, you can do something simpler than any fusion technique - just switch your queries to the fine-tuned model straight away, and re-embed as needed.

Whether this works or not depends on the model. To validate this we fine-tuned three models using medical question-answering data from MedEmbed and tested search quality as the data was migrated.

Results​

Below are results for a bge-small-en-v1.5 medical fine-tune. This model gained significantly from the training data and fine-tuning improved it by 33% on held-out MedEmbed queries.

Migrating to a fine-tuned bge-small-en-v1.5: unmerged, merged weights, and reference z-score fusion

When fine-tuning a model for a domain, it is possible that the new query vector is compatible with the original vectors. On the in-domain data (held-out MedEmbed), a 12% improvement occurred just from switching to the new query vector. This query-only change is another strategy you can use if you do not want to migrate vectors at all.

Reference z-score fusion still worked well, and in this situation it was better to use it with only the new query vector: there was no quality drop during migration on the held-out MedEmbed data.

As an additional technique, we also considered model-merging, where the original and fine-tuned parameters are merged together. This not only helps with overfitting but also keeps the embeddings compatible, and it achieved the best results on the other medical datasets. The merged model was so compatible it didn’t need fusion (though it still helped).

For stronger models like gte-modernbert-base and DenseOn, there was less improvement from fine-tuning on the MedEmbed dataset and the models were more at risk of overfitting. Because of this we used less data (one triplet per question, roughly a tenth of the training used for bge-small). This meant the models stayed highly compatible (within about 1% of the base model throughout the migration without any merging or fusion).

How a light fine-tune affects compatibility with the base model for three embedding models

Metric Compatible Training for Online Backfilling in Large-Scale Retrieval studied the same half-migrated state for image retrieval. They made the two models’ distances comparable by training a new model.

Federated Vector Retrieval across Heterogeneous VectorDBs merged results across vector databases by learning a neural network to map between vector spaces.

More recently, Plato’s Key showed that a simple rotation and scale can map between the hidden states of different LLMs, and a similar rotation is one of the maps evaluated for embedding model upgrades in Drift-Adapter. We tried this approach, fitting the rotation on the reference set and using it to convert old vectors into the new model’s space. For two models sharing an architecture (gte-modernbert-base → DenseOn) it performed about as well as reference z-score fusion, including on MS MARCO, with the benefit it only needs the new model at query time. For less similar models though it fell 14-31% below the ideal line on the smaller corpora and more than 50% on MS MARCO. One explanation is that a mapping approximates every old vector, so any error changes the ranking itself, while fusion leaves each model’s ranking untouched and only decides how to interleave them.

Summary​

To summarize, when migrating embedding models you have a few options:

If you can afford two vector indexes during the migration, it is a good idea to do so because it makes things much easier to test. However, if you don’t want or need two copies of each vector:

For a new model you haven’t trained yourself → look at using reference z-score fusion.

If you are going to do your own fine-tune of a model: 1) check how far it has drifted from the base model 2) consider model-merging to add compatibility back in 3) if the model has drifted far away consider using reference z-score fusion.

Ready to start building?​

Check out the Quickstart tutorial, or sign up for a free Weaviate Cloud account.

Comments are loaded from GitHub Discussions via giscus. to show them.

← WeaviateAll Companies