Training and Finetuning Multi-Vector Embedding Models with Sentence Transformers Hugging Face's Sentence Transformers library v6.0 introduces a fourth model type, MultiVectorEncoder, for ColBERT-style late interaction retrieval, along with a complete training approach. The blog post demonstrates finetuning a multi-vector model that outperforms general-purpose retrievers on medical retrieval evaluation, trained in 14.5 hours on a single RTX 3090. Sentence Similarity • 0.1B • Updated • 214k • 201 Training and Finetuning Multi-Vector Embedding Models with Sentence Transformers Update on GitHub https://github.com/huggingface/blog/blob/main/train-multi-vector-encoder.md Sentence Transformers https://sbert.net/ is a Python library for using and training embedding and reranker models for a wide range of applications, such as retrieval augmented generation, semantic search, semantic textual similarity, and more. Its v6.0 update introduces a fourth model type: MultiVectorEncoder , for ColBERT-style late interaction retrieval, alongside a complete training approach for it. In this blogpost, I'll show you how to use it to finetune a multi-vector model that outperforms general-purpose retrievers on your data. This method can also train strong new multi-vector models from scratch. Everything below runs on pip install -U "sentence-transformers train " . Finetuning multi-vector models involves several components: the model itself, datasets, loss functions, training arguments, evaluators, and the trainer class. I'll have a look at each of these components, accompanied by practical examples of how they can be used for finetuning strong multi-vector models. Lastly, in the Evaluation evaluation section, I'll show you that my finetuned multi-vector-encoder/mLateOn-medical https://huggingface.co/multi-vector-encoder/mLateOn-medical model, trained in 14.5 hours on a single RTX 3090 alongside this blogpost, easily outperforms every general-purpose retrieval model I could find on my medical retrieval evaluation: dense, sparse, lexical, and multi-vector alike. If you're interested in finetuning dense embedding models, sparse embedding models, or rerankers instead, then consider reading through my prior Training and Finetuning Embedding Models https://huggingface.co/blog/train-sentence-transformers , Training and Finetuning Sparse Embedding Models https://huggingface.co/blog/train-sparse-encoder , and Training and Finetuning Reranker Models https://huggingface.co/blog/train-reranker blogposts. This blogpost is about trainingmulti-vector models. If you want to learn how tousethem, from loading and encoding to indexing in vector databases, see the companion Multi-Vector Late Interaction Embedding Models with Sentence Transformers blogpost. Table of Contents What are Multi-Vector models? what-are-multi-vector-models Why Finetune? why-finetune Training Components training-components Model model Dataset dataset Loss Function loss-function Training Arguments training-arguments Evaluator evaluator Trainer trainer Evaluation evaluation Acknowledgements acknowledgements Additional Resources additional-resources What are Multi-Vector models? A dense embedding model compresses a whole text into a single vector, and similarity is one dot product between two such summaries. A multi-vector model also called a late-interaction or ColBERT-style model skips that compression. It keeps one small vector per token and scores a query against a document with the MaxSim operator, where every query token finds its best-matching document token and the scores are summed. Token-level matching preserves exactly the fine-grained signals that a single vector has to average away, which usually means stronger retrieval, at the cost of a bigger index. The companion Multi-Vector Embedding Models https://huggingface.co/blog/multi-vector-encoder blogpost covers the architecture, encoding, scoring, and indexing in detail, so I'll keep this section short and get to the training. Why Finetune? Finetuning multi-vector models significantly improves their retrieval performance on your specific domain: the vocabulary, the query style, and the notion of relevance all differ between web search, legal discovery, code search, and scientific literature review. Because queries and documents are matched token by token, multi-vector models pick up fine-grained domain signals that single-vector models tend to average away, and they respond very well to even modest amounts of in-domain finetuning data. Beyond that, most released retrieval models were configured for short passages. The classic ColBERT checkpoints truncate documents at 180 or 300 tokens, and many popular dense models at 256 or 512, because their MS MARCO-style training data rarely goes beyond that. If your documents are long, these models silently discard most of every document before scoring it. On my medical evaluation with passages averaging 941 tokens, I measured that this truncation costs up to 0.24 NDCG@10, considerably more than any difference between model architectures. When you train your own model, you configure the document length that your data needs. LightOn ran into this same dynamic with code retrieval, where general LateOn https://huggingface.co/lightonai/LateOn wasn't enough and they trained LateOn-Code https://huggingface.co/lightonai/LateOn-Code . Your domain, whether that's medical, legal, financial, or your company's internal documents, is not getting an official model. This blogpost shows you how to build it yourself, in a matter of hours, on a single consumer GPU. Training Components Training MultiVectorEncoder models involves the following components: : The model to finetune or the architecture to build fresh. Model : The data used for training and evaluation. Dataset : A function that measures the model's performance and guides the optimization process. Loss Function optional : Parameters that impact training performance, tracking, and debugging. Training Arguments optional : A class for evaluating the model before, during, or after training. Evaluator : Brings together all training components. Trainer Let's take a closer look at each component. Model Multi-vector training gives you a real choice of starting point, and it matters more than you might expect. Finetuning an existing multi-vector model If you want to further finetune an existing multi-vector model, you don't have to worry about the architecture at all: python from sentence transformers import MultiVectorEncoder Loading in fp32 is preferred for training if your memory can handle it model = MultiVectorEncoder "lightonai/mLateOn-unsupervised", model kwargs={"torch dtype": "float32"}, processor kwargs={"model max length": 8192}, the tokenizer-level token limit The checkpoint brings its own recipe along: its query and document marker tokens, its projection head, its scoring skiplist. For finetuning, you generally want to keep all of that and change only what your data demands. The first thing to check is the length configuration, since many released checkpoints cap documents at 180 to 512 tokens see Why Finetune? why-finetune , and my medical passages run to 1,400 tokens. The mLateOn family already serves the backbone's full 8192 token context, but if your starting checkpoint carries caps, lift them: Let the model read full documents instead of the caps it was trained with, e.g. GTE-ModernColBERT-v1 ships with query length=48 and document length=300 model 0 .query length = None model 0 .document length = None With the per-task caps unset, truncation falls back to the tokenizer's model max length , which is why I configure that limit at load time above. I made one more change, adding a punctuation skiplist that excludes punctuation tokens from document-side scoring and storage. In a 4-way ablation none, punctuation, stopwords, both it modestly won on quality, and it shrinks the document index by 9.6% on this data for free: python import string model 2 is the MultiVectorMask module model 2 .skiplist words = list string.punctuation model 2 .resolve with tokenizer model.tokenizer token ids are cached, so re-resolve after changing Building one from a base transformer You can also point MultiVectorEncoder at any base transformer, and a fresh, randomly initialized token-level projection is appended for you: python from sentence transformers import MultiVectorEncoder model = MultiVectorEncoder "answerdotai/ModernBERT-base", model kwargs={"torch dtype": "float32"} MultiVectorEncoder 0 : Transformer {..., 'architecture': 'ModernBertModel'} 1 : Dense {'in features': 768, 'out features': 128, 'bias': False, ...} 2 : MultiVectorMask {'skiplist words': , 'skiplist tasks': 'document' , ...} 3 : Normalize {...} That's the classic ColBERT pipeline: a Transformer producing contextualized token embeddings, a token-level Dense projecting each of them down to 128 dimensions, a MultiVectorMask deciding which tokens count during scoring, and a token-level Normalize . The projection starts random, so training is required before this model is useful. Interestingly, this works with strong dense embedding backbones too. A fresh projection on Alibaba-NLP/gte-modernbert-base https://huggingface.co/Alibaba-NLP/gte-modernbert-base reached within 0.03 of the existing-checkpoint starting points in my experiments, from nothing but the projection and 25k training pairs. The classic ColBERT tokenization tricks MASK query expansion, Q / D prefix tokens, a document length cap, a punctuation skiplist are all off by default and configurable. See Creating Custom Models https://sbert.net/docs/multi vector encoder/usage/custom models.html for the full set. For what it's worth, I tested MASK query expansion in four configurations for my domain finetune and none of them made a measurable difference, so don't feel obliged to reach for the classic recipe. Which starting point should you pick? I measured this directly while preparing this blogpost, taking six starting points and training each with the identical recipe on 25k medical question-passage pairs from MIRIAD https://huggingface.co/datasets/tomaarsen/miriad-4.4M-split , then evaluating on 1,000 held-out questions against a 50,000 passage corpus: | Starting point | Zero-shot NDCG@10 | After 25k pairs | Delta | |---|---|---|---| | 0.9398 +0.0311 lightonai/mLateOn https://huggingface.co/lightonai/mLateOn lightonai/LateOn-unsupervised https://huggingface.co/lightonai/LateOn-unsupervised 0.9206 +0.0180 lightonai/LateOn https://huggingface.co/lightonai/LateOn lightonai/GTE-ModernColBERT-v1 https://huggingface.co/lightonai/GTE-ModernColBERT-v1 gte-modernbert-base https://huggingface.co/Alibaba-NLP/gte-modernbert-base The result surprised me, and it replicated across two model families. The -unsupervised checkpoints adapt to a new domain far better than their finished siblings, overtaking them despite starting lower. These checkpoints sit after large-scale contrastive pretraining but before supervised finetuning on general retrieval, so they carry all the late-interaction structure with none of the general-purpose tuning that domain training then has to undo. The finished checkpoints, by contrast, barely moved or even regressed, at every learning rate I tried. So, if the model family you like publishes a pre-supervised checkpoint, start there. If not, a fresh projection on a strong retrieval-pretrained backbone is a close runner-up. Continuing from a fully finished checkpoint is the weakest option for domain adaptation, despite being the most natural-feeling one. Dataset The MultiVectorEncoderTrainer https://sbert.net/docs/package reference/multi vector encoder/trainer.html uses or https://huggingface.co/docs/datasets/main/en/package reference/main classes datasets.Dataset datasets.Dataset instances for training and evaluation. You can load data from the https://huggingface.co/docs/datasets/main/en/package reference/main classes datasets.DatasetDict datasets.DatasetDict Hugging Face Datasets Hub https://huggingface.co/datasets or use local data in whatever format you prefer e.g. CSV, JSON, Parquet, Arrow, or SQL . Note: Lots of public datasets that work out of the box with Sentence Transformers have been tagged with sentence-transformers on the Hugging Face Hub, so you can easily find them on https://huggingface.co/datasets?other=sentence-transformers https://huggingface.co/datasets?other=sentence-transformers . Consider browsing through these to find ready-to-go datasets that might be useful for your tasks, domains, or languages. Data on the Hugging Face Hub You can use the load dataset https://huggingface.co/docs/datasets/main/en/package reference/loading methods datasets.load dataset function to load data from datasets on the Hub: python from datasets import load dataset train dataset = load dataset "tomaarsen/miriad-4.4M-split", split="train" print train dataset """ Dataset { features: 'question', 'passage text' , num rows: 4467542 } """ This is the dataset I'll train on in this blogpost: 4.4 million medical questions from MIRIAD https://huggingface.co/datasets/miriad/miriad-4.4M , each paired with the source passage that contains its answer averaging 941 tokens . Simple query, relevant passage pairs like these are the easiest retrieval training data to collect for your own domain, and as you'll see, they're all you need. Local Data You can also use load dataset https://huggingface.co/docs/datasets/main/en/package reference/loading methods datasets.load dataset for loading local data in common file formats: python from datasets import load dataset dataset = load dataset "csv", data files="my file.csv" or dataset = load dataset "json", data files="my file.json" And if your local data requires pre-processing, you can use datasets.Dataset.from dict https://huggingface.co/docs/datasets/main/en/package reference/main classes datasets.Dataset.from dict to initialize your dataset with a dictionary of lists: python from datasets import Dataset queries = documents = Open a file, perform preprocessing, filtering, cleaning, etc. and append to the lists dataset = Dataset.from dict { "query": queries, "document": documents, } Dataset Format It is important that your dataset format matches your loss function or that you choose a loss function that matches your dataset format . Verifying whether a dataset format works with a loss function involves two steps: - If your loss function requires a Label according to the Loss Overview https://sbert.net/docs/multi vector encoder/loss overview.html table, then your dataset must have a column named "label" or "score" . This column is automatically taken as the label. - All columns not named "label" or "score" are considered Inputs according to the Loss Overview https://sbert.net/docs/multi vector encoder/loss overview.html table. The number of remaining columns must match the number of valid inputs for your chosen loss. The names of these columns are irrelevant , only the order matters . There are two multi-vector specific conventions on top of this: - Positional query and document assignment: the first column is embedded as the query and all following columns as documents , regardless of the column names. This default can be overridden per column via the standard router mapping training argument. - Knowledge distillation format: one column per candidate document, i.e. query, document 1, ..., document N, scores where scores is a list of N teacher scores per row. For KD datasets that store query and document IDs alongside separate text datasets e.g. lightonai/ms-marco-en-bge https://huggingface.co/datasets/lightonai/ms-marco-en-bge , you can useto resolve the IDs to texts on the fly. resolve ids Loss Function Loss functions quantify how well a model performs for a given batch of data, allowing an optimizer to update the model weights to produce more favourable i.e., lower loss values. The right loss function for your task depends on the data you have and what you're trying to achieve. You can find a full list of options in the Loss Overview https://sbert.net/docs/multi vector encoder/loss overview.html . For the common case of question-answer or question-passage pairs, the workhorse is in-batch negatives training with MultiVectorMultipleNegativesRankingLoss https://sbert.net/docs/package reference/multi vector encoder/losses.html multivectormultiplenegativesrankingloss , where every other document in the batch acts as a negative for each query. Bigger batches mean more negatives and stronger training, so in practice you'll want its GradCache variant, , which decouples the effective batch size from what fits on your GPU: https://sbert.net/docs/package reference/multi vector encoder/losses.html cachedmultivectormultiplenegativesrankingloss CachedMultiVectorMultipleNegativesRankingLoss python from sentence transformers import MultiVectorEncoder from sentence transformers.multi vector encoder.losses import CachedMultiVectorMultipleNegativesRankingLoss model = MultiVectorEncoder "lightonai/mLateOn-unsupervised", model kwargs={"torch dtype": "float32"} loss = CachedMultiVectorMultipleNegativesRankingLoss model=model, mini batch size=16, how many documents to encode per chunk: bounds memory, not quality The mini batch size parameter bounds the memory by encoding documents in chunks of this size, while the effective contrastive batch size 128 in my run below, and in my ablations bigger batches bought nothing further stays a free choice. GradCache guarantees identical results regardless of the chunk size, so lower it for smaller GPUs at only a wall-clock cost. When your document lengths vary a lot, consider its sibling mini batch num tokens , which packs each chunk to a total token budget instead of a document count, so a chunk of unusually long documents can never spike your memory my mini batch size=16 at roughly 940 tokens per document corresponds to mini batch num tokens=15 000 . One multi-vector specific trap is that the contrastive losses default to scale=1.0 , unlike the dense embedding equivalent which defaults to scale=20.0 . That 20.0 exists because a cosine similarity is a single value in -1, 1 , too narrow a range for a sharp softmax. A MaxSim score instead sums one best-match similarity per query token, so it already spans roughly 0, query length : a 32-token query can score up to 32. So don't copy scale=20.0 over from a dense training script, since it would saturate the softmax and kill your gradients. For distillation from a stronger teacher, which is how the strongest general-purpose late-interaction models are trained, see MultiVectorDistillKLDivLoss https://sbert.net/docs/package reference/multi vector encoder/losses.html multivectordistillkldivloss and the Knowledge Distillation tab in the Training Overview https://sbert.net/docs/multi vector encoder/training overview.html trainer documentation. Training Arguments You can customize the training process using the MultiVectorEncoderTrainingArguments https://sbert.net/docs/package reference/multi vector encoder/training args.html class. This class lets you adjust parameters that can impact training speed and help you understand what's happening during training. For more information on the most useful training arguments, check out the Multi-Vector Encoder Training Overview Training Arguments https://sbert.net/docs/multi vector encoder/training overview.html training-arguments . It's worth reading to get the most out of your training. Here's an example, using the values from my actual training run: python from sentence transformers import MultiVectorEncoderTrainingArguments from sentence transformers.base.sampler import BatchSamplers args = MultiVectorEncoderTrainingArguments Required parameter: output dir="models/mLateOn-medical", Optional training parameters: num train epochs=1, per device train batch size=128, the effective contrastive batch, thanks to GradCache per device eval batch size=16, learning rate=1e-4, warmup steps=0.05, prompts={"question": " Q ", "passage text": " D "}, the checkpoint's markers, keyed by training column fp16=False, Set to True if you have a GPU that supports FP16 bf16=True, Set to True if you have a GPU that supports BF16 batch sampler=BatchSamplers.NO DUPLICATES, in-batch negatives benefit from no duplicates Optional tracking/debugging parameters: eval strategy="steps", eval steps=0.1, save strategy="steps", save steps=0.05, logging steps=0.01, run name="mLateOn-medical", Will be used in e.g. Trackio, W&B, etc. A few of these deserve a comment: prompts : training does not automatically apply the prompts stored in the model, so map them onto your training columns explicitly. Here that is the checkpoint's Q marker for the question column and D for the passage column, keeping training consistent with inference. max length deliberately not set : this argument caps tokenization during training only , for when you want cheaper training than the model's full serving length. I measured what that shortcut costs on this data. Training at 512 tokens lost about 0.015 NDCG@10 for about 2x the speed, and the deficit did not shrink with more data, because the model simply never sees what got cut off. Leave it unset so training matches inference, unless you need the speedup more than the quality. learning rate=1e-4 : after a sweep from 5e-6 to 2e-4, I had the best luck with this higher-than-usual learning rate. Evaluator To track your model's performance during training, you can pass an eval dataset to the trainer for evaluation loss, but concrete retrieval metrics are much more informative. Sentence Transformers includes the following built-in evaluators for multi-vector models: | Evaluator | Required Data | |---|---| MultiVectorInformationRetrievalEvaluator | MultiVectorNanoBEIREvaluator MultiVectorTripletEvaluator MultiVectorRerankingEvaluator {'query': '...', 'positive': ... , 'negative': ... } dictionaries MultiVectorDistillationEvaluator For domain finetuning, the MultiVectorInformationRetrievalEvaluator https://sbert.net/docs/package reference/multi vector encoder/evaluation.html multivectorinformationretrievalevaluator built from your own held-out data is the one that matters. One tip on constructing it is that the corpus should be hard enough that models can be told apart. In my case the MIRIAD questions are generated from their own source passages, which makes retrieval unusually easy. Against just the 10k gold passages, nearly every model scored above 0.97 NDCG@10. If your evaluation saturates like that, add distractor passages I use deduplicated passages from the training split until the scores spread out: python from datasets import load dataset from sentence transformers.multi vector encoder.evaluation import MultiVectorInformationRetrievalEvaluator dataset = load dataset "tomaarsen/miriad-4.4M-split" Gold: 1,000 evaluation questions, each mapping to its own passage, with the eval split's full ~10k unique passages as the initial corpus corpus = {} queries = {} relevant docs = {} passage to id = {} for idx, row in enumerate dataset "eval" : if row "passage text" not in passage to id: passage to id row "passage text" = f"p{len passage to id }" corpus passage to id row "passage text" = row "passage text" if idx < 1 000: queries f"q{idx}" = row "question" relevant docs f"q{idx}" = {passage to id row "passage text" } Distractors: unique train passages that make the haystack realistic seen = set passage to id for row in dataset "train" : if len corpus = 200 000: break if row "passage text" not in seen: seen.add row "passage text" corpus f"d{len corpus }" = row "passage text" evaluator = MultiVectorInformationRetrievalEvaluator queries=queries, corpus=corpus, relevant docs=relevant docs, name="miriad-dev", batch size=16, results = evaluator model Trainer The MultiVectorEncoderTrainer https://sbert.net/docs/package reference/multi vector encoder/trainer.html is where all previous components come together. Here is the complete script that trained multi-vector-encoder/mLateOn-medical https://huggingface.co/multi-vector-encoder/mLateOn-medical , the model from the introduction: python import logging import string import traceback from datasets import load dataset from sentence transformers import MultiVectorEncoder, MultiVectorEncoderModelCardData, MultiVectorEncoderTrainer, MultiVectorEncoderTrainingArguments, from sentence transformers.base.sampler import BatchSamplers from sentence transformers.multi vector encoder.evaluation import MultiVectorInformationRetrievalEvaluator from sentence transformers.multi vector encoder.losses import CachedMultiVectorMultipleNegativesRankingLoss logging.basicConfig format="% asctime s - % message s", datefmt="%Y-%m-%d %H:%M:%S", level=logging.INFO def main : 1. Load the starting checkpoint: contrastively pretrained, not yet supervised Loading in fp32 is preferred for training if your memory can handle it model = MultiVectorEncoder "lightonai/mLateOn-unsupervised", model kwargs={"torch dtype": "float32"}, processor kwargs={"model max length": 8192}, model card data=MultiVectorEncoderModelCardData language="en", license="apache-2.0", model name="mLateOn finetuned on MIRIAD medical retrieval", , 2. Lift the per-task length caps so training and inference see full medical passages model 0 .query length = None model 0 .document length = None 3. Skip punctuation tokens during scoring: a small quality win and a 9.6% smaller index model 2 .skiplist words = list string.punctuation model 2 .resolve with tokenizer model.tokenizer 4. Load 1 million medical question-passage pairs train dataset = load dataset "tomaarsen/miriad-4.4M-split", split="train" .select range 1 000 000 5. In-batch negatives with GradCache: large effective batch, memory-bounded chunks loss = CachedMultiVectorMultipleNegativesRankingLoss model=model, mini batch size=16 6. A light dev evaluator to watch progress during training: 500 held-out questions against the eval split's ~10k unique passages. The full 200k protocol runs afterwards. eval split = load dataset "tomaarsen/miriad-4.4M-split", split="eval" corpus, queries, relevant docs, passage to id = {}, {}, {}, {} for idx, row in enumerate eval split : if row "passage text" not in passage to id: passage to id row "passage text" = f"p{len passage to id }" corpus passage to id row "passage text" = row "passage text" if idx < 500: queries f"q{idx}" = row "question" relevant docs f"q{idx}" = {passage to id row "passage text" } dev evaluator = MultiVectorInformationRetrievalEvaluator queries=queries, corpus=corpus, relevant docs=relevant docs, name="miriad-dev", batch size=16 7. Training arguments, as discussed above run name = "mLateOn-medical" args = MultiVectorEncoderTrainingArguments output dir=f"models/{run name}", num train epochs=1, per device train batch size=128, per device eval batch size=16, learning rate=1e-4, warmup steps=0.05, prompts={"question": " Q ", "passage text": " D "}, fp16=False, Set to True if you have a GPU that supports FP16 bf16=True, Set to True if you have a GPU that supports BF16 batch sampler=BatchSamplers.NO DUPLICATES, eval strategy="steps", eval steps=0.1, save strategy="steps", save steps=0.05, logging steps=0.01, run name=run name, 8. Create a trainer & train trainer = MultiVectorEncoderTrainer model=model, args=args, train dataset=train dataset, loss=loss, evaluator=dev evaluator, trainer.train 9. Save the trained model model.save pretrained f"models/{run name}/final" 10. Optional Push it to the Hugging Face Hub try: model.push to hub run name except Exception: logging.error f"Error uploading model to the Hugging Face Hub:\n{traceback.format exc }" if name == " main ": main That's the whole recipe: a pre-supervised checkpoint, a million domain pairs, in-batch negatives, full document length, and a higher-than-usual learning rate. The run took 14.5 hours on my single RTX 3090 at a peak of 17.5 GB VRAM, and every one of those choices was the winner of a measured comparison rather than a guess. For readers on smaller budgets, my scaling experiments put 100k pairs 75 minutes of training within 0.012 NDCG@10 of the full million-pair run. Most of the gain comes in the first hour. Callbacks The MultiVectorEncoder trainer supports various transformers.TrainerCallback https://huggingface.co/docs/transformers/main classes/callback transformers.TrainerCallback subclasses, including: for logging training metrics to W&B if WandbCallback wandb is installedfor logging training metrics to TensorBoard if TensorBoardCallback tensorboard is accessiblefor tracking carbon emissions during training if CodeCarbonCallback codecarbon is installed Enable these via the report to training argument, e.g. report to= "wandb", "codecarbon" , with the required dependencies installed. It defaults to "none" , and report to="all" activates every integration whose dependency is installed. Refer to the Transformers Callbacks documentation https://huggingface.co/docs/transformers/en/main classes/callback for more information on these callbacks and how to create your own. Multi-Dataset Training Typically, top-performing general-purpose models are trained on multiple datasets simultaneously. However, this approach can be challenging due to the varying formats of each dataset. Fortunately, the MultiVectorEncoderTrainer https://sbert.net/docs/package reference/multi vector encoder/trainer.html allows you to train on multiple datasets without requiring a uniform format. Additionally, it provides the flexibility to apply different loss functions to each dataset. Here are the steps to train with multiple datasets at once: - Use a dictionary of instances or a datasets.Dataset as the datasets.DatasetDict train dataset and optionally also eval dataset . - Optional Use a dictionary of loss functions mapping dataset names to losses. Only required if you wish to use different loss functions for different datasets. Each training/evaluation batch will only contain samples from one of the datasets. The order in which batches are sampled from the multiple datasets is defined by the MultiDatasetBatchSamplers https://sbert.net/docs/package reference/sentence transformer/sampler.html sentence transformers.training args.MultiDatasetBatchSamplers enum, which can be passed to the via https://sbert.net/docs/package reference/multi vector encoder/training args.html MultiVectorEncoderTrainingArguments multi dataset batch sampler . Valid options are: MultiDatasetBatchSamplers.ROUND ROBIN : Round-robin sampling from each dataset until one is exhausted. With this strategy, it's likely that not all samples from each dataset are used, but each dataset is sampled from equally. MultiDatasetBatchSamplers.PROPORTIONAL default : Sample from each dataset in proportion to its size. With this strategy, all samples from each dataset are used and larger datasets are sampled from more frequently. Evaluation To find out where the finetuned model stands, I evaluated it against over 50 retrieval model configurations across four architecture families on the MIRIAD evaluation set, built exactly as in the Evaluator evaluator section above, with 1,000 held-out medical questions searching 200,000 unique passages the 10k gold passages hidden among 190k deduplicated distractors from the training split . This corpus is four times the size of the 50,000-passage one from Which starting point should you pick? which-starting-point-should-you-pick , so scores are not comparable between the two tables. The headline results, with the full table in the collapsible below: | Model | Family | NDCG@10 | |---|---|---| multi-vector-encoder/mLateOn-medical mine | Multi-vector, finetuned 0.9139 lightonai/mLateOn https://huggingface.co/lightonai/mLateOn lightonai/GTE-ModernColBERT-v1 https://huggingface.co/lightonai/GTE-ModernColBERT-v1 cap lifted Qwen/Qwen3-Embedding-4B https://huggingface.co/Qwen/Qwen3-Embedding-4B voyageai/voyage-4-nano https://huggingface.co/voyageai/voyage-4-nano naver/splade-v3 https://huggingface.co/naver/splade-v3 The finetuned model tops the table, beating the strongest zero-shot model of any architecture by +0.062 NDCG@10. In other words, the strongest zero-shot model returns the right passage as the very first hit for 75.8% of the queries, while the finetuned model does so for 84.9%, cutting the rank-1 error by more than a third. The architecture pattern is just as clear, with the top of the table exclusively late interaction. On long documents, one vector per token beats one vector per document, even at matched training and matched backbones. DenseOn and LateOn share training data and architecture except for the head, and the late-interaction sibling wins by +0.12, with the multilingual pair mDenseOn and mLateOn replicating this at +0.13. Scale doesn't rescue single vectors either. Qwen3-Embedding-4B https://huggingface.co/Qwen/Qwen3-Embedding-4B , the strongest dense model with roughly 33x the active non-embedding parameters of mine, still stops 0.13 short, and the 8B version scores lower than the 4B. BM25 also performs surprisingly well, beating every sparse model, every truncation-capped multi-vector model, and all but three dense models: the multi-billion Qwen3-Embedding-4B https://huggingface.co/Qwen/Qwen3-Embedding-4B and 8B https://huggingface.co/Qwen/Qwen3-Embedding-8B , and voyage-4-nano https://huggingface.co/voyageai/voyage-4-nano , which reads its full 32k token context to edge past by just 0.006. Don't expect that to transfer to your own data though. MIRIAD's questions are generated from the passages, so the lexical overlap between a query and its gold passage is far larger than in typical retrieval, and BM25's unlimited context length lets it use every one of those overlapping words while most neural checkpoints truncate. A BM25 baseline is cheap and always worth running, just don't count on this margin. The full field at a glance, sorted by score and colored by architecture family. Click to see the full evaluation table Models marked @N are evaluated with their document length cap lifted to N tokens, since their native caps 180 to 512 tokens would otherwise truncate the 941-token average passages. For every multi-vector model this lift was worth +0.08 to +0.24 NDCG@10 over the as-served row, and even the dense DenseOn gained +0.03 from the same treatment. Note that this does not mean that multi-vector-encoder/mLateOn-medical https://huggingface.co/multi-vector-encoder/mLateOn-medical is the strongest model on all domains. It's simply the strongest in my domain. This is totally fine, as I just need this model to work well on my data. Don't underestimate the power of finetuning multi-vector models on your domain. Fourteen and a half hours on a single consumer GPU produced a model that no general-purpose retriever comes close to on this data, and the recipe is a single script with no teacher model and no mined negatives Optimizing the index The fair objection to multi-vector retrieval is index size, and this domain is close to the worst case for it. Storing one vector per token, my model needs about 878 vectors per passage, so the 200,000-passage corpus takes roughly 45 GB at fp16, where a dense model needs well under 1 GB. Document length is what makes that gap so wide. The Natural Questions passages in the companion post https://huggingface.co/blog/multi-vector-encoder average about 125 token vectors each, seven times fewer, so a corpus of short passages starts from a far smaller index than this one does. The HierarchicalTokenPooling https://sbert.net/docs/package reference/multi vector encoder/modules.html hierarchicaltokenpooling module compresses exactly this by clustering each document's token embeddings and storing the cluster means, keeping roughly 1 / pool factor of the vectors: python from sentence transformers.multi vector encoder.modules import HierarchicalTokenPooling pooling = HierarchicalTokenPooling pool factor=4 document embeddings = model.encode document passages, token pooling=pooling I measured it post-hoc on the finished model, with no pooling-aware training, and on long documents it is remarkably cheap. The solid points are uncompressed embeddings, so that every family is counted the same way and scored with exact search. You would not deploy any of them like that, though. Dense indexes routinely use int8 or binary quantization with rescoring, sparse indexes compress their postings, and multi-vector indexes use PLAID-style residual compression. Don't read those points as the disk you need to buy, but as relative storage cost. Token pooling is the solid line. Halving the vector count costs 0.0033 NDCG@10 and leaves rank-1 accuracy untouched, and keeping only a quarter of them, at 11.2 GB, still scores 0.8991. The curve keeps going I measured out to a tenth of the vectors, still at 0.8765 but there is little reason to push pooling that far once quantization is on the table, which is what the dashed line below is about. The dashed line is what a real deployment might look like. I gave Omar Khattab early access to the model and the benchmark, and he measured these configurations with fast-plaid https://github.com/lightonai/fast-plaid at 1-bit residual quantization, using compact 17-bit centroid ids and 18-bit document ids instead of its ordinary unpacked 64-bit integers, plus document-side pruning: | configuration | vectors kept | index | NDCG@10 | |---|---|---|---| | 1-bit PLAID, all vectors | 100% | 3.37 GB | 0.8984 | | 1-bit PLAID + pruning | 65% | 2.23 GB | 0.8830 | | 1-bit PLAID + pruning | 42% | 1.45 GB | 0.8642 | That first row is 13x smaller than the raw embeddings, for 0.0155 NDCG@10. That is a far better trade than anywhere on the pooling curve. Quantization shrinks each vector while pooling and pruning cut how many you keep, so they compose, and quantization is the one to reach for first. Push further and the last row lands at 1.45 GB, smaller than the fp16 embeddings of Qwen3-Embedding-8B https://huggingface.co/Qwen/Qwen3-Embedding-8B 1.64 GB , while scoring 0.0895 higher. The objection that multi-vector indexes are too big does not survive a properly configured index. The pruning here is naive, meant only to establish that token reduction works on top of quantization, so read the bottom two rows as a floor rather than the frontier. If you would rather not hand-tune quantization at all, the Indexing https://huggingface.co/blog/multi-vector-encoder indexing section of the companion post covers fast-plaid, Qdrant, Weaviate, and Vespa. Multi-vector retrieval is only as expensive as its index. The raw embeddings for this corpus are 45 GB, and a properly configured index is at least 7x smaller at nearly the same accuracy. The index deserves as much of your attention as the checkpoint. Acknowledgements Thanks to Omar Khattab https://github.com/okhat for measuring the quantized and pruned index configurations in Optimizing the index optimizing-the-index , and for the discussions around late-interaction index costs. Additional Resources Training Examples These pages have training examples with explanations as well as links to training scripts. You can use them to get familiar with the multi-vector training loop: MIRIAD https://sbert.net/examples/multi vector encoder/training/miriad/README.html : domain-specific training on medical retrieval, an earlier and simpler cousin of this blogpost's recipe MS MARCO https://sbert.net/examples/multi vector encoder/training/msmarco/README.html : contrastive and knowledge distillation recipes Multimodal https://sbert.net/examples/multi vector encoder/training/multimodal/README.html : ColPali-style visual document retrieval training PEFT Adapters https://sbert.net/examples/multi vector encoder/training/peft/README.html : parameter-efficient finetuning with LoRA Documentation For further learning, you may also want to explore the following resources on Sentence Transformers: Installation https://sbert.net/docs/installation.html Quickstart https://sbert.net/docs/quickstart.html Usage https://sbert.net/docs/multi vector encoder/usage/usage.html Creating Custom Models https://sbert.net/docs/multi vector encoder/usage/custom models.html Pretrained Models https://sbert.net/docs/multi vector encoder/pretrained models.html Training Overview https://sbert.net/docs/multi vector encoder/training overview.html This blogpost is a distillation of the Training Overview documentation Loss Overview https://sbert.net/docs/multi vector encoder/loss overview.html API Reference https://sbert.net/docs/package reference/multi vector encoder/index.html And here is an advanced page that might interest you: And the companion blogpost, covering everything about using these models: