原地迁移嵌入模型

迟早你会想要升级自己的嵌入模型。最直接的做法就是新建一个索引(或在 Weaviate 中新建一个命名向量),然后用新的嵌入模型对每个文档进行嵌入。
这种做法行之有效,好处是在正式切换之前,你可以轻松测试两个模型。但它有一个重大缺陷:在一段时间内,你需要存储两倍的向量数量。
对于资源受限、希望使用固定数量磁盘或内存的使用场景,或者规模极大、把全部内容重新嵌入一次成本太高的场景,你可能更愿意原地迁移向量,在一段时间内让部分文档继续使用旧向量,同时回填新向量。
但我们如何合并两个模型的搜索结果呢?
最终结果是,随着数据迁移推进,你的搜索质量会跌入一个兼容性低谷。
在上图中,我们把 NanoBEIR 从 bge-small-en-v1.5 迁移到 gte-modernbert-base,迁移完成后搜索质量(NDCG@10)从 0.627 提升到 0.664。
我们希望从每个模型得到的,不是基于模型自身独立量纲的“这个文档与查询有多相似”,而是两个模型经过校准后的分数。只要你有一个小规模的参考集,用两个模型分别对其做过嵌入,并且愿意用两个模型分别对查询进行编码,这个分数是可以估算出来的。
为此,我们抽取一个样本(在下面的实验中是 5,000 个随机文档),并用两个模型分别对其进行嵌入。
对于每个查询:
重新缩放后的分数是一个 z-score:即某个结果比强匹配高出多少个标准差。正因如此,我们把这套方法称为参考 z-score 融合(reference z-score fusion)。
我们在不同数据集上测试了 4 次迁移,结果显示在迁移过程中,搜索质量明显优于 RRF。
与 NDCG 最多可能下降 40% 的 RRF 相比,参考 z-score 融合的结果要稳定得多,在数据集不均衡时(迁移早期或后期)也不会出现大幅下滑。
这种方法的一个好处是,它不依赖于迁移进行到哪个阶段。其性能开销仅仅是用两个查询向量对参考向量样本做暴力计算(在现代硬件上只需几毫秒)。
在上述所有实验中,我们都使用了固定的 5,000 条参考集(若语料不足 50,000 篇文档,则取语料的 10%)。一个合理的问题是:这种方法对参考集的大小有多敏感?显然,我们不希望参考集太大,否则就失去了不复制向量的优势。
下图展示了随着参考集增大,这 4 个数据集上的变化。在 MS MARCO(880 万篇文档)这类较大的数据集上,随着参考集增大,与理想结果的差距持续缩小(从下降 7.1% 改善到 3.4%)。参考集大小的决定,实际上是在搜索质量与延迟之间做权衡,同时也取决于新模型能带来多大提升。
鉴于我们只需要参考集中的 top-k 向量来计算 z-score,在大规模场景下甚至可以用向量索引来存储参考向量。
以下是在 Weaviate 中使用两个命名向量的核心方法,以及一个完整示例:在 Weaviate HNSW 索引上将 NanoBEIR 数据从 bge-small-en-v1.5 迁移到 gte-modernbert-base。在整个迁移过程中,参考 z-score 融合与理想线的偏差始终保持在约 2% 以内,而 RRF 最多下降 35%。
collection = client.collections.create( "Docs", vector_config=[ Configure.Vectors.self_provided(name="old"), Configure.Vectors.self_provided(name="new"), ], ) # 假设向量最初位于“old”命名向量中 # 目标是在“new”命名向量中迁移 collection.data.insert(properties=props, vector={"old": old_vector}) def ref_zscore(result, query_vector, reference_vectors): # 将余弦距离转换为相似度 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)) # 迁移期间,同时搜索两个命名向量并按 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] 那微调模型呢?到目前为止,我们考察的都是完全不同模型之间的迁移。另一个好问题是:微调嵌入模型时,兼容性会发生什么变化?
微调模型从旧模型的权重出发,这意味着它一开始与旧模型完全相同,并随着训练的推进而逐渐偏离。
如果漂移不大,你可以采用比任何融合技术都更简单的做法——直接把查询切换到微调后的模型,并在需要时重新嵌入。
这种做法是否奏效取决于具体模型。为验证这一点,我们用 MedEmbed 的医疗问答数据微调了三个模型,并在数据迁移过程中测试了检索质量。
以下是 bge-small-en-v1.5 医学微调模型的结果。该模型从训练数据中获益显著,微调使其在留出的 MedEmbed 查询上提升了 33%。
当针对某个领域微调模型时,新的查询向量有可能与原始向量兼容。在领域内数据(留出的 MedEmbed)上,仅仅切换到新的查询向量就带来了 12% 的提升。如果你完全不想迁移向量,这种只改查询的做法是另一种可用策略。
参考 z-score 融合依然表现良好,而在这种情况下,仅配合新的查询向量使用效果更好:在留出的 MedEmbed 数据上,迁移过程中没有出现质量下降。
作为一项额外技术,我们还考虑了模型合并(model-merging),也就是把原始参数与微调后的参数合并在一起。这不仅有助于缓解过拟合,还能保持嵌入的兼容性,并且在其他医学数据集上取得了最佳结果。合并后的模型兼容性极好,甚至不需要融合(不过融合仍然有帮助)。
对于 gte-modernbert-base 和 DenseOn 这类更强的模型,在 MedEmbed 数据集上微调带来的提升更小,而且这些模型更容易出现过拟合的风险。因此我们使用了更少的数据(每个问题一个三元组,约为 bge-small 所用训练量的十分之一)。这意味着这些模型保持了高度兼容(在整个迁移过程中与基础模型的差距保持在约 1% 以内,且未进行任何合并或融合)。
Metric Compatible Training for Online Backfilling in Large-Scale Retrieval 针对图像检索研究了同样的半迁移状态。他们通过训练一个新模型,使两个模型的距离变得可比。
Federated Vector Retrieval across Heterogeneous VectorDBs 通过学习一个神经网络在向量空间之间建立映射,从而合并了跨多个向量数据库的结果。
更近期,Plato's Key 表明,仅靠简单的旋转和缩放就能在不同 LLM 的隐藏状态之间建立映射,而在 Drift-Adapter 中为嵌入模型升级所评估的映射之一,就是一种类似的旋转。我们尝试了这一方法,在参考集上拟合旋转,并用它把旧向量转换到新模型的空间中。对于共享同一架构的两个模型(gte-modernbert-base → DenseOn),它的表现与参考 z-score 融合大致相当,包括在 MS MARCO 上,好处是查询时只需要新模型。但对于相似度较低的模型,它在较小的语料库上比理想线低 14-31%,在 MS MARCO 上低超过 50%。一种解释是,映射会近似每一个旧向量,因此任何误差都会改变排序本身,而融合则不动每个模型各自的排序,只决定如何将它们交错合并。
总而言之,迁移嵌入模型时有几种可选方案:
如果你在迁移期间能够承担两个向量索引的开销,那么这么做是值得的,因为它会让测试变得容易得多。不过,如果你不想要或不需要每个向量都保留两份副本:
对于你自己并未训练过的新模型 → 可以考虑使用 reference z-score fusion。
如果你打算自己对一个模型做微调:1)检查它与基础模型的偏离程度;2)考虑通过模型合并(model-merging)把兼容性加回来;3)如果模型偏离得很远,考虑使用 reference z-score fusion。
不妨看看 Quickstart 教程,或者注册一个免费的 Weaviate Cloud 账号。
译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(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.

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:
- Embed the query with both models.
- Search old vectors with old query vector, new vectors with new query vector.
- Score the query against the (5,000) reference vectors returning the top (50) results.
- For each model, compute mean and std dev of top results.
- Rescale every search result (subtract mean, divide by std dev).
- 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.

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

| Corpus | Documents | Migration | NDCG@10, old → new | RRF | Ref z-score fusion | Ref z-score fusion, all migrations |
|---|---|---|---|---|---|---|
| SCIDOCS | 26K | gte-modernbert-base → Qwen3-Embedding-0.6B | 0.195 → 0.228 | -40% | -2.0% | -0.5% to -2.3% |
| FiQA | 58K | bge-small-en-v1.5 → gte-modernbert-base | 0.403 → 0.522 | -38% | -3.2% | -1.6% to -3.2% |
| Quora | 523K | all-MiniLM-L6-v2 → bge-small-en-v1.5 | 0.877 → 0.889 | -36% | -4.6% | -3.1% to -4.7% |
| MS MARCO | 8.8M | gte-modernbert-base → DenseOn | 0.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.

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.

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).

Related work
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. Allow preference cookies to show them.
正文保留英文原文,标题与摘要由机器翻译。
原文发布于 Weaviate Blog(Migrating embedding models in-place),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。