特定模型示例¶
ColBERT 晚期交互模型¶
ColBERT (Contextualized Late Interaction over BERT) 是一种检索模型,它使用每 Token 嵌入和 MaxSim 评分进行文档排序。与单向量嵌入模型不同,ColBERT 保留了 Token 级别的表示,并通过晚期交互计算相关性得分,在提供比交叉编码器(Cross-encoder)更高效率的同时,保证了更好的准确性。
vLLM 支持使用多种编码器主干(Backbone)的 ColBERT 模型
| 架构 | 主干 (Backbone) | 示例 HF 模型 |
|---|---|---|
HF_ColBERT | BERT | answerdotai/answerai-colbert-small-v1, colbert-ir/colbertv2.0 |
ColBERTModernBertModel | ModernBERT | lightonai/GTE-ModernColBERT-v1 |
ColBERTJinaRobertaModel | Jina XLM-RoBERTa | jinaai/jina-colbert-v2 |
ColBERTLfm2Model | LFM2 | LiquidAI/LFM2-ColBERT-350M |
基于 BERT 的 ColBERT 模型可直接开箱即用
对于非 BERT 主干,请使用 --hf-overrides 设置正确的架构
# ModernBERT backbone
vllm serve lightonai/GTE-ModernColBERT-v1 \
--hf-overrides '{"architectures": ["ColBERTModernBertModel"]}'
# Jina XLM-RoBERTa backbone
vllm serve jinaai/jina-colbert-v2 \
--hf-overrides '{"architectures": ["ColBERTJinaRobertaModel"]}' \
--trust-remote-code
# LFM2 backbone
vllm serve LiquidAI/LFM2-ColBERT-350M \
--hf-overrides '{"architectures": ["ColBERTLfm2Model"]}'
然后,您可以使用 rerank API
curl -s https://:8000/rerank -H "Content-Type: application/json" -d '{
"model": "answerdotai/answerai-colbert-small-v1",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of artificial intelligence.",
"Python is a programming language.",
"Deep learning uses neural networks."
]
}'
或者 score API
curl -s https://:8000/score -H "Content-Type: application/json" -d '{
"model": "answerdotai/answerai-colbert-small-v1",
"text_1": "What is machine learning?",
"text_2": ["Machine learning is a subset of AI.", "The weather is sunny."]
}'
您还可以使用具有 token_embed 任务的 pooling API 获取原始 Token 嵌入
curl -s https://:8000/pooling -H "Content-Type: application/json" -d '{
"model": "answerdotai/answerai-colbert-small-v1",
"input": "What is machine learning?",
"task": "token_embed"
}'
示例可以在此处找到: examples/pooling/score/colbert_rerank_online.py
ColQwen3 多模态晚期交互模型¶
ColQwen3 基于 ColPali,后者将 ColBERT 的晚期交互方法扩展到了多模态输入。虽然 ColBERT 仅作用于纯文本 Token 嵌入,但 ColPali/ColQwen3 可以将文本和图像(例如 PDF 页面、截图、图表)嵌入到每 Token 的 L2 归一化向量中,并通过 MaxSim 评分计算相关性。ColQwen3 特别使用 Qwen3-VL 作为其视觉-语言主干。
| 架构 | 主干 (Backbone) | 示例 HF 模型 |
|---|---|---|
ColQwen3 | Qwen3-VL | TomoroAI/tomoro-colqwen3-embed-4b, TomoroAI/tomoro-colqwen3-embed-8b |
OpsColQwen3Model | Qwen3-VL | OpenSearch-AI/Ops-Colqwen3-4B, OpenSearch-AI/Ops-Colqwen3-8B |
Qwen3VLNemotronEmbedModel | Qwen3-VL | nvidia/nemotron-colembed-vl-4b-v2, nvidia/nemotron-colembed-vl-8b-v2 |
启动服务器
纯文本评分与重排序¶
使用 /rerank API
curl -s https://:8000/rerank -H "Content-Type: application/json" -d '{
"model": "TomoroAI/tomoro-colqwen3-embed-4b",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of artificial intelligence.",
"Python is a programming language.",
"Deep learning uses neural networks."
]
}'
或者使用 /score API
curl -s https://:8000/score -H "Content-Type: application/json" -d '{
"model": "TomoroAI/tomoro-colqwen3-embed-4b",
"text_1": "What is the capital of France?",
"text_2": ["The capital of France is Paris.", "Python is a programming language."]
}'
多模态评分与重排序(文本查询 × 图像文档)¶
/score 和 /rerank API 也直接接受多模态输入。使用 data_1/data_2(用于 /score)或 documents(用于 /rerank)字段传入图像文档,其中包含 content 列表(包含 image_url 和 text 部分)——这与 OpenAI 聊天补全 API 使用的格式相同。
根据文本查询对图像文档进行评分
curl -s https://:8000/score -H "Content-Type: application/json" -d '{
"model": "TomoroAI/tomoro-colqwen3-embed-4b",
"data_1": "Retrieve the city of Beijing",
"data_2": [
{
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64>"}},
{"type": "text", "text": "Describe the image."}
]
}
]
}'
根据文本查询对图像文档进行重排序
curl -s https://:8000/rerank -H "Content-Type: application/json" -d '{
"model": "TomoroAI/tomoro-colqwen3-embed-4b",
"query": "Retrieve the city of Beijing",
"documents": [
{
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64_1>"}},
{"type": "text", "text": "Describe the image."}
]
},
{
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64_2>"}},
{"type": "text", "text": "Describe the image."}
]
}
],
"top_n": 2
}'
原始 Token 嵌入¶
您还可以使用 /pooling API 并指定 token_embed 任务来获取原始 Token 嵌入。
curl -s https://:8000/pooling -H "Content-Type: application/json" -d '{
"model": "TomoroAI/tomoro-colqwen3-embed-4b",
"input": "What is machine learning?",
"task": "token_embed"
}'
对于通过 pooling API 进行的图像输入,请使用聊天风格的 messages 字段。
curl -s https://:8000/pooling -H "Content-Type: application/json" -d '{
"model": "TomoroAI/tomoro-colqwen3-embed-4b",
"messages": [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64>"}},
{"type": "text", "text": "Describe the image."}
]
}
]
}'
示例¶
- 多向量检索: examples/pooling/token_embed/colqwen3_token_embed_online.py
- 重排序(文本 + 多模态): examples/pooling/score/colqwen3_rerank_online.py
ColQwen3.5 多模态晚期交互模型¶
ColQwen3.5 基于 ColPali,将 ColBERT 的晚期交互方法扩展到了多模态输入。它使用 Qwen3.5 混合主干(线性 + 全注意力),并生成用于 MaxSim 评分的每 Token L2 归一化向量。
| 架构 | 主干 (Backbone) | 示例 HF 模型 |
|---|---|---|
ColQwen3_5 | Qwen3.5 | athrael-soju/colqwen3.5-4.5B |
启动服务器
然后您可以使用 rerank 端点
curl -s https://:8000/rerank -H "Content-Type: application/json" -d '{
"model": "athrael-soju/colqwen3.5-4.5B",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of artificial intelligence.",
"Python is a programming language.",
"Deep learning uses neural networks."
]
}'
或者使用 score 端点
curl -s https://:8000/score -H "Content-Type: application/json" -d '{
"model": "athrael-soju/colqwen3.5-4.5B",
"text_1": "What is the capital of France?",
"text_2": ["The capital of France is Paris.", "Python is a programming language."]
}'
示例可以在此处找到: examples/pooling/score/colqwen3_5_rerank_online.py
Llama Nemotron 多模态¶
嵌入(Embedding)模型¶
Llama Nemotron VL 嵌入模型将双向 Llama 嵌入主干(来自 nvidia/llama-nemotron-embed-1b-v2)与作为视觉编码器的 SigLIP 相结合,从文本和/或图像中生成单向量嵌入。
| 架构 | 主干 (Backbone) | 示例 HF 模型 |
|---|---|---|
LlamaNemotronVLModel | 双向 Llama + SigLIP | nvidia/llama-nemotron-embed-vl-1b-v2 |
启动服务器
vllm serve nvidia/llama-nemotron-embed-vl-1b-v2 \
--trust-remote-code \
--chat-template examples/pooling/embed/template/nemotron_embed_vl.jinja
注意
该模型 Tokenizer 自带的聊天模板不适用于嵌入 API。在使用基于 messages 的(聊天风格)嵌入 API 时,请使用上述提供的覆盖模板。
覆盖模板使用消息的 role 来自动预置适当的前缀:对于查询,将 role 设置为 "query"(预置 query:);对于篇章(passages),设置为 "document"(预置 passage:)。任何其他角色将省略前缀。
嵌入文本查询
curl -s https://:8000/v1/embeddings -H "Content-Type: application/json" -d '{
"model": "nvidia/llama-nemotron-embed-vl-1b-v2",
"messages": [
{
"role": "query",
"content": [
{"type": "text", "text": "What is machine learning?"}
]
}
]
}'
通过聊天风格的 messages 字段嵌入图像
curl -s https://:8000/v1/embeddings -H "Content-Type: application/json" -d '{
"model": "nvidia/llama-nemotron-embed-vl-1b-v2",
"messages": [
{
"role": "document",
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64>"}},
{"type": "text", "text": "Describe the image."}
]
}
]
}'
重排序(Reranker)模型¶
Llama Nemotron VL 重排序模型将相同的双向 Llama + SigLIP 主干与用于交叉编码器评分和重排序的序列分类头(sequence-classification head)相结合。
| 架构 | 主干 (Backbone) | 示例 HF 模型 |
|---|---|---|
LlamaNemotronVLForSequenceClassification | 双向 Llama + SigLIP | nvidia/llama-nemotron-rerank-vl-1b-v2 |
启动服务器
vllm serve nvidia/llama-nemotron-rerank-vl-1b-v2 \
--runner pooling \
--trust-remote-code \
--chat-template examples/pooling/score/template/nemotron-vl-rerank.jinja
注意
该检查点 Tokenizer 自带的聊天模板不适用于 Score/Rerank API。在服务时使用提供的覆盖模板:examples/pooling/score/template/nemotron-vl-rerank.jinja。
根据文本查询对图像文档进行评分
curl -s https://:8000/score -H "Content-Type: application/json" -d '{
"model": "nvidia/llama-nemotron-rerank-vl-1b-v2",
"data_1": "Find diagrams about autonomous robots",
"data_2": [
{
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64>"}},
{"type": "text", "text": "Robotics workflow diagram."}
]
}
]
}'
根据文本查询对图像文档进行重排序
curl -s https://:8000/rerank -H "Content-Type: application/json" -d '{
"model": "nvidia/llama-nemotron-rerank-vl-1b-v2",
"query": "Find diagrams about autonomous robots",
"documents": [
{
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64_1>"}},
{"type": "text", "text": "Robotics workflow diagram."}
]
},
{
"content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64_2>"}},
{"type": "text", "text": "General skyline photo."}
]
}
],
"top_n": 2
}'
BAAI/bge-m3¶
BAAI/bge-m3 模型附带了用于稀疏和 ColBERT 嵌入的额外权重,但不幸的是,在其 config.json 中架构被声明为 XLMRobertaModel,这导致 vLLM 将其作为普通的 ROBERTA 模型加载,而忽略了额外权重。要加载完整的模型权重,请按如下方式覆盖其架构:
然后,您可以像这样获取稀疏嵌入:
curl -s https://:8000/pooling -H "Content-Type: application/json" -d '{
"model": "BAAI/bge-m3",
"task": "token_classify",
"input": ["What is BGE M3?", "Definition of BM25"]
}'
由于输出模式的限制,输出由每个输入的每个 Token 的 Token 分数列表组成。这意味着您还需要调用 /tokenize 才能将 Token 与分数配对。请参阅 tests/models/language/pooling/test_bge_m3.py 中的测试以了解如何操作。
您可以像这样获取 ColBERT 嵌入: