Late interaction retrieval ranks documents by matching individual query tokens against document tokens. An existing PyLate ColBERT model can move to Sentence Transformers MultiVectorEncoder while keeping its trained weights and checking that document rankings remain unchanged.
MultiVectorEncoder reads a PyLate checkpoint's query and document prefixes, query expansion settings, and punctuation skiplist. Its separate query and document methods replace the is_query argument, and similarity() performs the MaxSim scoring previously handled by colbert_scores().
The saved-model compatibility works in one direction. A PyLate checkpoint loads into MultiVectorEncoder, but a model saved by MultiVectorEncoder cannot load back into PyLate. Keeping the original checkpoint and PyLate environment preserves rollback; PLAID indexing and retrieval also remain in PyLate because Sentence Transformers has no equivalent index API.
Steps to migrate a PyLate model to Sentence Transformers MultiVectorEncoder:
- Record the dependencies of your working PyLate environment before changing application code.
$ .venv-pylate/bin/python -m pip freeze > pylate-requirements.txt
The POSIX commands assume a project with an existing PyLate environment named .venv-pylate; substitute its actual interpreter path if different. The CPU baseline uses Python 3.14 on Linux x86-64, PyLate 1.6.0, Sentence Transformers 5.3.0, Transformers 5.3.0, fast-plaid 1.4.6.2110, and PyTorch 2.11.0+cpu.
Related: Install Python on Ubuntu or Debian
Related: Install Python packages with pip - Create pylate_baseline.py in your text editor with your checkpoint and representative queries and documents.
- pylate_baseline.py
import json from pathlib import Path import torch from pylate import models, scores checkpoint = "lightonai/colbertv2.0" revision = "0b9b1e380096a3b72b6b4877f68d59effb62e0f2" queries = [ "Which planet is known as the Red Planet?", "What is the largest planet in our solar system?", ] documents = [ "Mars is known as the Red Planet.", "Jupiter is the largest planet in our solar system.", "Venus is often called Earth's twin.", ]
The public checkpoint is a trained PyLate version of ColBERTv2 and needs no Hugging Face token. For your application, replace the checkpoint, queries, and documents with the original model and representative retrieval inputs. A Hub model needs its own commit in revision; a local checkpoint path uses revision = None. Both libraries will read these same inputs from the saved baseline.
Related: ColBERTv2 checkpoint - Append the PyLate encoding and scoring calls after the document list.
- pylate_baseline.py
model = models.ColBERT( model_name_or_path=checkpoint, revision=revision, device="cpu" ) query_embeddings = model.encode(queries, is_query=True) document_embeddings = model.encode(documents, is_query=False) matrix = torch.cat( [scores.colbert_scores(query_embeddings, [doc]) for doc in document_embeddings], dim=1, ) ranking = matrix.argsort(dim=1, descending=True, stable=True)
PyLate scores one document at a time here because its scoring function expects equal token counts within a document batch. Concatenating the columns supports passages of different lengths. Rows follow query order and columns follow document order. Higher MaxSim scores mean a closer match for that query. A trained ColBERT checkpoint supplies its learned projection and token settings; a bare BERT checkpoint is not a replacement.
- Append the baseline export after the ranking calculation.
- pylate_baseline.py
baseline = { "checkpoint": checkpoint, "revision": revision, "queries": queries, "documents": documents, "scores": matrix.tolist(), "ranking": ranking.tolist(), } Path("pylate-baseline.json").write_text(json.dumps(baseline, indent=2)) print("PyLate scores:") for row in matrix: print([round(float(value), 4) for value in row]) print("PyLate rankings:", ranking.tolist())
- Save pylate_baseline.py in your editor.
- Run the baseline with your original PyLate interpreter. Example output:
$ .venv-pylate/bin/python pylate_baseline.py ##### snipped ##### PyLate scores: [28.9878, 14.8271, 11.0073] [14.9741, 28.474, 13.0309] PyLate rankings: [[0, 1, 2], [1, 0, 2]]
The first load downloads the public checkpoint. An unauthenticated Hub warning concerns download rate limits; this public model needs no sign-in. The resulting pylate-baseline.json holds the full score matrix, document order, checkpoint revision, and input text. The unchanged original environment and checkpoint remain the rollback source for rerunning this command.
- Create a separate virtual environment for Sentence Transformers 6.2.
Sentence Transformers 6 changes APIs and requires Transformers 5. Installing it into the PyLate environment conflicts with PyLate's pinned Sentence Transformers version. The separate environment leaves the working application available for rollback.
$ python3 -m venv .venv-mve
On Ubuntu, python3-venv supplies the environment support.
Related: Create a Python virtual environment - Install the CPU PyTorch build into the new environment.
$ .venv-mve/bin/python -m pip install "torch==2.11.0+cpu" \ --index-url https://download.pytorch.org/whl/cpuThe matching PyTorch build keeps the library comparison on the same CPU runtime. No CUDA installation is needed.
- Install Sentence Transformers 6.2 into the new environment.
$ .venv-mve/bin/python -m pip install "sentence-transformers==6.2.0" \ "transformers==5.3.0"Transformers 5.3.0 matches the PyLate baseline, so the migration changes the encoder API without also changing the underlying Transformers release.
Related: Sentence Transformers migration guide - Check the new environment for dependency conflicts.
$ .venv-mve/bin/python -m pip check No broken requirements found.
- Create migrate_pylate.py in your editor with the baseline-loading code.
- migrate_pylate.py
import json from pathlib import Path import torch from sentence_transformers import MultiVectorEncoder baseline = json.loads(Path("pylate-baseline.json").read_text()) queries = baseline["queries"] documents = baseline["documents"] old_scores = torch.tensor(baseline["scores"]) old_ranking = torch.tensor(baseline["ranking"])
- Append the MultiVectorEncoder loading and scoring calls after the baseline variables.
- migrate_pylate.py
model = MultiVectorEncoder( baseline["checkpoint"], revision=baseline["revision"], device="cpu" ) query_embeddings = model.encode_query(queries) document_embeddings = model.encode_document(documents) matrix = model.similarity(query_embeddings, document_embeddings) ranking = matrix.argsort(dim=1, descending=True, stable=True)
encode_query() replaces encode(..., is_query=True), encode_document() replaces encode(..., is_query=False), and model.similarity() replaces scores.colbert_scores(). The checkpoint's saved prefixes are applied automatically; adding them to the input text again would change the result.
- Append the score comparison and migrated-model save after the ranking calculation.
- migrate_pylate.py
torch.testing.assert_close(matrix, old_scores, rtol=1e-5, atol=1e-4) assert torch.equal(ranking, old_ranking), "Rankings changed after migration" model.save_pretrained("migrated-colbert") print("MultiVectorEncoder scores:") for row in matrix: print([round(float(value), 4) for value in row]) print("Original rankings:", old_ranking.tolist()) print("Migrated rankings:", ranking.tolist())
migrated-colbert must be a new output directory, separate from your original checkpoint. The new save format cannot be loaded by PyLate.
The score comparison allows small floating-point differences, while the ranking comparison requires the full document order to match for every query. A traceback stops the save when either comparison fails.
- Append the saved-model reload and ranking comparison at the end of migrate_pylate.py.
- migrate_pylate.py
reloaded = MultiVectorEncoder("migrated-colbert", device="cpu") reloaded_scores = reloaded.similarity( reloaded.encode_query(queries), reloaded.encode_document(documents) ) reloaded_ranking = reloaded_scores.argsort( dim=1, descending=True, stable=True ) torch.testing.assert_close(reloaded_scores, matrix, rtol=1e-5, atol=1e-4) assert torch.equal(reloaded_ranking, old_ranking), "Reload changed rankings" print("Reloaded rankings:", reloaded_ranking.tolist()) print("Saved model: migrated-colbert")
The reload reads the saved directory rather than loading the original Hub checkpoint again. It checks that the saved model still encodes the inputs and reproduces the original rankings. This covers encoding and scoring; an existing PLAID index still belongs to PyLate and stays in its separate environment.
- Save migrate_pylate.py in your editor.
- Confirm that the migrated model saves and reloads with the original document rankings. Example output:
$ .venv-mve/bin/python migrate_pylate.py ##### snipped ##### MultiVectorEncoder scores: [28.9878, 14.8271, 11.0073] [14.9741, 28.474, 13.0309] Original rankings: [[0, 1, 2], [1, 0, 2]] Migrated rankings: [[0, 1, 2], [1, 0, 2]] ##### snipped ##### Reloaded rankings: [[0, 1, 2], [1, 0, 2]] Saved model: migrated-colbert
Document indices are zero-based. If either score or ranking comparison raises a traceback, the migration has not passed for those inputs. The original PyLate environment and checkpoint remain available.