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:
- :class:
ColBERTMixin— mixin that adds ColBERT late-interaction support to any embedding model. - :class:
ColBERTModel— ColBERT with BERT backbone (original architecture). - :class:
ColBERTModernBertModel— ColBERT with ModernBERT backbone. - :class:
ColBERTJinaRobertaModel— ColBERT with Jina XLM-RoBERTa backbone.
Reference: https://arxiv.org/abs/2004.12832
ColBERTJinaRobertaModel ¶
Bases: ColBERTMixin, Module
ColBERT late interaction model with Jina XLM-RoBERTa backbone.
For jinaai/jina-colbert-v2 and similar models.
Source code in vllm/model_executor/models/colbert.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
ColBERTMixin ¶
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:
supports_late_interactionclass-var- ColBERT linear projection initialisation / lazy creation
- Weight loading helpers for the projection layer
- A builder for the token-embedding pooler
Integration:
- Inherit from both
ColBERTMixinandnn.Module. - In
__init__: callsuper().__init__(), then :meth:_init_colbert_components, then createself.model(the backbone) andself.poolervia :meth:_build_colbert_pooler. - In
load_weights: use :meth:_load_colbert_weightsto separate the ColBERT projection weight, then delegate the rest to the backbone.
Source code in vllm/model_executor/models/colbert.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
_build_colbert_linear ¶
_build_colbert_linear() -> Linear
Build the ColBERT linear projection layer.
Source code in vllm/model_executor/models/colbert.py
_build_colbert_pooler ¶
_build_colbert_pooler(
pooler_config: PoolerConfig,
) -> Pooler
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.).
Source code in vllm/model_executor/models/colbert.py
_init_colbert_components ¶
Initialise ColBERT projection layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_size | int | Hidden dimension of the encoder backbone. | required |
colbert_dim | int | None | Output dimension for ColBERT embeddings. If | required |
head_dtype | dtype | Data type for the projection layer. | required |
Source code in vllm/model_executor/models/colbert.py
_load_colbert_weights ¶
_load_colbert_weights(
weights: Iterable[tuple[str, Tensor]],
colbert_weight_names: tuple[str, ...] = (
"linear.weight",
"colbert_linear.weight",
),
) -> tuple[list[tuple[str, Tensor]], set[str]]
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:
| Name | Type | Description | Default |
|---|---|---|---|
weights | Iterable[tuple[str, Tensor]] | Iterable of | required |
colbert_weight_names | tuple[str, ...] | Suffixes that identify the ColBERT linear weight. | ('linear.weight', 'colbert_linear.weight') |
Returns:
| Type | Description |
|---|---|
list[tuple[str, Tensor]] |
|
set[str] | not consumed and the set of names that were loaded. |
Source code in vllm/model_executor/models/colbert.py
get_colbert_dim_from_config classmethod ¶
get_colbert_dim_from_config(hf_config) -> int | None
Extract ColBERT dimension from a HuggingFace config.
Checks colbert_dim, dim and projection_dim in that order.
Source code in vllm/model_executor/models/colbert.py
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.
Source code in vllm/model_executor/models/colbert.py
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.