Back to News Feed
Hugging Face Blog6d ago

Training and Finetuning Multi-Vector Embedding Models with Sentence Transformers

The Sentence Transformers library has long been the gold standard for Python developers looking to implement semantic search, retrieval-augmented generation (RAG), and textual similarity. With the release of version 6.0, the framework takes a significant leap forward by introducing the MultiVectorEncoder. This new model type brings ColBERT-style late interaction retrieval directly into the Sentence Transformers ecosystem, complete with a robust, end-to-end training pipeline.

In this guide, we explore how to leverage this architecture to finetune multi-vector models that can outperform even the most powerful general-purpose retrievers on your specific data. Whether you are building from scratch or adapting existing models, the process is now accessible via a simple pip install -U "sentence-transformers[train]".

---

Understanding Multi-Vector Models

Traditional dense embedding models compress an entire document into a single, fixed-length vector. While efficient, this compression forces the model to average out fine-grained semantic signals.

In contrast, multi-vector models—often referred to as "late interaction" or "ColBERT-style" models—eschew this compression. Instead, they maintain a distinct vector for every token in the text. When a query is processed, the model uses the MaxSim operator, where each query token identifies its most relevant counterpart in the document. By summing these token-level matches, the model preserves granular information that single-vector models typically lose, resulting in superior retrieval accuracy at the cost of a larger index.

---

Why Finetuning is Essential

General-purpose retrieval models are often trained on broad datasets like MS MARCO, which may not align with the vocabulary, query intent, or document structure of specialized domains like legal, medical, or technical documentation.

The Truncation Problem

Most off-the-shelf retrieval models are configured for short passages, often capping documents at 180 to 512 tokens. In specialized fields, documents are frequently much longer. When a model truncates a 1,000-token document to 300 tokens, it silently discards the majority of the content before scoring even begins. By training your own model, you can configure the document length to match your specific data requirements, preventing this loss of critical information.

Domain-Specific Signals

Because multi-vector models perform token-level matching, they are exceptionally sensitive to domain-specific nuances. Even modest amounts of in-domain training data can lead to significant performance gains, allowing the model to "learn" the specific language of your industry.

---

The Training Toolkit

Training a MultiVectorEncoder involves five core components: 1. Model: The architecture you choose to finetune or build from scratch. 2. Dataset: Your training and evaluation data. 3. Loss Function: The mathematical objective that guides optimization. 4. Training Arguments: Configuration parameters for performance and tracking. 5. Trainer: The engine that orchestrates the entire training loop.

Selecting a Starting Point

The choice of base model is critical. Experiments demonstrate that starting with "unsupervised" checkpoints—those that have undergone large-scale contrastive pretraining but lack general-purpose supervised finetuning—often yields the best results. These models possess the necessary late-interaction structure without the "baked-in" biases of general-purpose search, making them highly receptive to domain-specific adaptation.

Configuring the Model

When loading an existing multi-vector model, you should prioritize lifting any artificial length caps:

from sentence_transformers import MultiVectorEncoder

model = MultiVectorEncoder("lightonai/mLateOn-unsupervised")
# Lift caps to allow the model to process full-length documents
model[0].query_length = None
model[0].document_length = None

Additionally, implementing a punctuation skiplist can improve performance while simultaneously reducing the size of your document index by nearly 10% by excluding non-informative tokens from the scoring process.

---

Data and Training Objectives

Dataset Preparation

The MultiVectorEncoderTrainer is compatible with standard datasets.Dataset objects. For most retrieval tasks, simple pairs of (query, relevant_passage) are sufficient. You can load these from the Hugging Face Hub or from local files like JSON or Parquet.

The Loss Function

For question-passage pairs, CachedMultiVectorMultipleNegativesRankingLoss is the recommended workhorse. It utilizes GradCache to decouple the effective contrastive batch size from the memory constraints of your GPU. This allows you to use large batch sizes—which are crucial for high-quality retrieval training—even on consumer-grade hardware.

Pro Tip: Unlike dense embedding training, where a scale of 20.0 is common, multi-vector models should generally use a scale of 1.0. Because MaxSim scores are sums of token-level similarities, they naturally span a wider range, and applying a high scale would saturate the softmax and destroy your gradients.

---

Evaluation: The Proof is in the Performance

To validate the effectiveness of this approach, we conducted a rigorous evaluation on a medical retrieval dataset (MIRIAD). The goal was to compare a custom-finetuned mLateOn-medical model against a wide array of dense, sparse, and multi-vector baselines.

Key Findings

  • Superior Accuracy: The finetuned multi-vector model achieved an NDCG@10 of 0.9139, significantly outperforming the strongest zero-shot models.
  • Architecture Dominance: Late-interaction models consistently outperformed dense models, even when those dense models were significantly larger in parameter count.
  • The Power of Context: Lifting document length caps provided a massive boost across all architectures, proving that for long-document retrieval, the ability to "read" the full text is as important as the model architecture itself.

| Model | Architecture | NDCG@10 | | :--- | :--- | :--- | | mLateOn-medical (Finetuned) | Multi-vector | 0.9139 | | lightonai/mLateOn (Zero-shot) | Multi-vector | 0.8520 | | Qwen3-Embedding-4B (Zero-shot) | Dense | 0.7817 | | BM25 | Lexical | 0.7501 |

---

Optimizing the Index

A common critique of multi-vector retrieval is the storage requirement. However, this is largely a matter of configuration. While raw embeddings for a large corpus can be substantial, modern techniques make these indexes highly efficient:

  • Hierarchical Token Pooling: By clustering token embeddings and storing cluster means, you can drastically reduce the number of vectors per document with minimal impact on accuracy.
  • Quantization: Techniques like 1-bit PLAID quantization can shrink the index by over 10x while maintaining performance levels comparable to uncompressed embeddings.

By combining these strategies, you can achieve a high-performance retrieval system that fits comfortably within standard infrastructure budgets.

---

Conclusion

Finetuning multi-vector models is no longer an experimental endeavor reserved for massive research labs. With the tools provided in the latest Sentence Transformers update, you can build a domain-specific retriever in a matter of hours on a single GPU. By focusing on the right starting checkpoint, utilizing GradCache for efficient training, and properly configuring your index, you can achieve retrieval performance that far exceeds general-purpose solutions.

The path to state-of-the-art search is clear: stop relying on general-purpose averages and start training for your specific data.

#embedding#model