Skip to content

vllm.model_executor.models.colbert

ColBERT late interaction model for retrieval and reranking.

ColBERT uses per-token embeddings and late interaction (MaxSim) scoring instead of single-vector representations or cross-encoder concatenation.

This module provides:

  • ColBERTMixin — mixin that adds ColBERT late-interaction support to any embedding model.
  • ColBERTModel — ColBERT with BERT backbone (original architecture).
  • ColBERTModernBertModel — ColBERT with ModernBERT backbone.
  • ColBERTJinaRobertaModel — ColBERT with Jina XLM-RoBERTa backbone.

Reference: https://arxiv.org/abs/2004.12832

Classes:

ColBERTJinaRobertaModel

Bases: ColBERTMixin, Module

ColBERT late interaction model with Jina XLM-RoBERTa backbone.

For jinaai/jina-colbert-v2 and similar models.

ColBERTLfm2Model

Bases: ColBERTMixin, Module, HasInnerState, IsHybrid

ColBERT late interaction model with LFM2 backbone.

For LiquidAI/LFM2-ColBERT-350M and similar models.

The projection is auto-loaded from sentence-transformers 1_Dense/ when not present in the main checkpoint.

ColBERTMixin

Bases: Module, SupportsLateInteraction

Mixin that adds ColBERT late interaction support to any embedding model.

ColBERT (Contextualized Late Interaction over BERT) uses per-token embeddings with a linear projection layer. This mixin provides:

  • ColBERT linear projection initialisation / lazy creation
  • Weight loading helpers for the projection layer
  • A builder for the token-embedding pooler

Integration:

  1. Inherit from both ColBERTMixin and nn.Module.
  2. In __init__: call super().__init__(), then _init_colbert_components, then create self.model (the backbone) and self.pooler via _build_colbert_pooler.
  3. In load_weights: use _load_colbert_weights to separate the ColBERT projection weight, then delegate the rest to the backbone.

Methods:

_build_colbert_linear()

Build the ColBERT linear projection layer.

_build_colbert_pooler(pooler_config)

Build pooler for ColBERT token embeddings.

When colbert_linear is set, it is used as the projector. Otherwise pooler_for_token_embed falls back to auto-loading sentence-transformers Dense layers (1_Dense/ etc.).

_init_colbert_components(hidden_size, colbert_dim, head_dtype)

Initialise ColBERT projection layer.

Parameters:

  • hidden_size

    (int) –

    Hidden dimension of the encoder backbone.

  • colbert_dim

    (int | None) –

    Output dimension for ColBERT embeddings. If None, will be inferred from weights during loading (or auto-loaded from sentence-transformers Dense layers).

  • head_dtype

    (dtype) –

    Data type for the projection layer.

_load_colbert_weights(weights, colbert_weight_names=('linear.weight', 'colbert_linear.weight'))

Separate and load ColBERT projection weights.

Scans weights for entries whose name ends with one of colbert_weight_names. The matching weight is loaded into self.colbert_linear (creating it first if colbert_dim was not known at init time).

Parameters:

  • weights

    (Iterable[tuple[str, Tensor]]) –

    Iterable of (name, tensor) weight pairs.

  • colbert_weight_names

    (tuple[str, ...], default: ('linear.weight', 'colbert_linear.weight') ) –

    Suffixes that identify the ColBERT linear weight.

Returns:

  • list[tuple[str, Tensor]] –

    (remaining_weights, loaded_names) — the weights that were

  • set[str] –

    not consumed and the set of names that were loaded.

get_colbert_dim_from_config(hf_config) classmethod

Extract ColBERT dimension from a HuggingFace config.

Checks colbert_dim, dim and projection_dim in that order.

ColBERTModel

Bases: ColBERTMixin, BertEmbeddingModel

ColBERT late interaction model with BERT backbone.

Supports the token_embed task (per-token embeddings for late interaction). MaxSim scoring is computed externally.

ColBERTModernBertModel

Bases: ColBERTMixin, Module

ColBERT late interaction model with ModernBERT backbone.

For lightonai/GTE-ModernColBERT-v1 and similar models. The projection is auto-loaded from sentence-transformers 1_Dense/ when not present in the main checkpoint.