作者:來自ElasticJINA
新的 0.6B - parameter 的 listwise reranker ,在單個 context window 中同時考慮 query 和所有 candidate documents 。
我們很高興發佈 jina-reranker-v3 ,這是我們最新一代的 reranker ,在多語言檢索基準上提供最先進的性能。這個 0.6B - parameter 的 document reranker 引入了一種新的 last but not late interaction(最後但不遲的交互) ,與現有方法採取了根本不同的方式。 jina-reranker-v3 以 listwise 方式工作:它在單個 context window 內對 query 和所有 candidate documents 應用 causal attention ,在從每個 document 的 final token 提取 contextual embeddings 之前,實現豐富的跨 document 交互。我們的新模型在 BEIR 上達到了 61.94 nDCG@10 ,性能超過 Qwen3-Reranker-4B ,同時模型體積小 6× 。
模型架構
jina-reranker-v3 構建在 Qwen3-0.6B backbone 上,這是一個僅 decoder 的 transformer 模型,帶有 causal self-attention。該模型同時處理多個 documents 和 query,在指定的 token 位置提取 contextual embeddings,以實現高效的相似度計算。
給定一個 query 和一組 candidate documents ,jina-reranker-v3使用一個專門的 prompt template 處理 reranking 任務,該模板在單次 forward pass 中實現跨 document 交互。輸入構建遵循特定格式:
<|im_start|>system You are a search relevance expert who can determine a ranking of passages based on their relevance to the query. <|im_end|> <|im_start|>user I will provide you with k passages, each indicated by a numerical identifier. Rank the passages based on their relevance to query: [QUERY] <passage id="1"> [DOCUMENT_1]<|doc_emb|> </passage> <passage id="2"> [DOCUMENT_2]<|doc_emb|> </passage> ... <passage id="k"> [DOCUMENT_k]<|doc_emb|> </passage> <query> [QUERY]<|query_emb|> </query> <|im_end|> <|im_start|>assistant <think></think>
在輸入結構中,query 出現兩次 —— 一次在開頭用於任務指令,一次在末尾用於最終 attention 處理。這種雙重位置使得最終的 query 位置可以通過 causal attention 關注所有前面的 documents。兩個關鍵的特殊 token 標記了 embedding 提取位置:<|doc_emb|> token 放在每個 document 之後,用於標記 document embedding 的提取點,而 <|query_emb|> token 放在最終的 query 之後,用於標記 query embedding 的提取點。這些 embeddings 通過共享的 causal self-attention 機制捕捉了局部 document 語義和全局跨 document 上下文。
我們稱這種 query-document 交互為 “last but not late”。之所以叫 “last”,是因為 <|doc_emb|> 放在每個 document 的最後一個 token。之所以叫 “not late”,是因為與 ColBERT 等 late interaction 模型不同,那些模型在多向量匹配前會單獨編碼 documents,而我們在 forward pass 中在同一個 context window 內實現了 query-document 和 document-document 交互。
最後,一個帶 ReLU 激活的兩層 MLP projector 將 1024 維的 hidden states 映射到 256 維的 ranking space。相關性評分通過投影后的 query embedding 與每個投影后的 document embedding 之間的 cosine similarity 計算,從而為輸入集合中的每個 document 生成相關性分數。
入門
通過 API
使用 jina-reranker-v3 最簡單的方法是通過我們的 Search Foundation API 。我們可以參考之前的文章 “Jina-VLM:小型多語言視覺語言模型” 來獲取一個 API key。然後,我們使用如下的命令來定義一個環境變量:
export JINA_API_KEY=<Your JIAN API KEY>
curl -X POST \
https://api.jina.ai/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer JINA_API_KEY" \
-d '{
"model": "jina-reranker-v3",
"query": "slm markdown",
"documents": [
...
],
"return_documents": false
}'
比如:
curl -X POST \
https://api.jina.ai/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $JINA_API_KEY" \
-d '{
"model": "jina-reranker-v3",
"query": "阿里巴巴(中國)有限公司是哪一年成立的?",
"documents": [
"阿里巴巴是全球領先的B2B電子商務網上貿易平台",
"阿里巴巴(中國)有限公司成立於2007年03月26日,法定代表人蔣芳"
],
"return_documents": false
}' | jq .
$ curl -X POST \
> https://api.jina.ai/v1/rerank \
> -H "Content-Type: application/json" \
> -H "Authorization: Bearer $JINA_API_KEY" \
> -d '{
> "model": "jina-reranker-v3",
> "query": "阿里巴巴(中國)有限公司是哪一年成立的?",
> "documents": [
> "阿里巴巴是全球領先的B2B電子商務網上貿易平台",
> "阿里巴巴(中國)有限公司成立於2007年03月26日,法定代表人蔣芳"
> ],
> "return_documents": false
> }' | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 494 100 168 100 326 194 377 --:--:-- --:--:-- --:--:-- 571
{
"model": "jina-reranker-v3",
"object": "list",
"usage": {
"total_tokens": 218
},
"results": [
{
"index": 1,
"relevance_score": 0.55301309
},
{
"index": 0,
"relevance_score": -0.05146404
}
]
}
很顯然,文檔 index 為 1 的文檔和 “阿里巴巴(中國)有限公司是哪一年成立的?” 更為貼近。
通過 transformers
from transformers import AutoModel
model = AutoModel.from_pretrained(
'jinaai/jina-reranker-v3',
dtype="auto",
trust_remote_code=True,
)
model.eval()
現在你可以使用模型的 rerank 函數來計算 query 和一組 documents 的相關性分數:
query = "What are the health benefits of green tea?"
documents = [
"Green tea contains antioxidants called catechins that may help reduce inflammation and protect cells from damage.",
"El precio del café ha aumentado un 20% este año debido a problemas en la cadena de suministro.",
"Studies show that drinking green tea regularly can improve brain function and boost metabolism.",
"Basketball is one of the most popular sports in the United States.",
"綠茶富含兒茶素等抗氧化劑,可以降低心臟病風險,還有助於控制體重。",
"Le thé vert est riche en antioxydants et peut améliorer la fonction cérébrale.",
]
# Rerank documents
results = model.rerank(query, documents)
# Results are sorted by relevance score (highest first)
for result in results:
print(f"Score: {result['relevance_score']:.4f}")
print(f"Document: {result['document'][:100]}...")
print()
完整的代碼:
transformer.py
$ python transformer.py modeling.py: 10.4kB [00:00, 11.6MB/s] A new version of the following files was downloaded from https://huggingface.co/jinaai/jina-reranker-v3: - modeling.py . Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision. model.safetensors: 100%|█████████████████████████████████████████████████████████| 1.19G/1.19G [00:54<00:00, 21.8MB/s] generation_config.json: 100%|████████████████████████████████████████████████████████| 202/202 [00:00<00:00, 1.46MB/s] tokenizer_config.json: 10.7kB [00:00, 17.9MB/s] tokenizer.json: 100%|████████████████████████████████████████████████████████████| 11.4M/11.4M [00:04<00:00, 2.41MB/s] added_tokens.json: 100%|█████████████████████████████████████████████████████████████| 795/795 [00:00<00:00, 6.74MB/s] special_tokens_map.json: 100%|███████████████████████████████████████████████████████| 777/777 [00:00<00:00, 2.29MB/s] Score: 0.2966 Document: Green tea contains antioxidants called catechins that may help reduce inflammation and protect cells... Score: 0.2262 Document: 綠茶富含兒茶素等抗氧化劑,可以降低心臟病風險,還有助於控制體重。... Score: 0.1911 Document: Studies show that drinking green tea regularly can improve brain function and boost metabolism.... Score: 0.1645 Document: Le thé vert est riche en antioxydants et peut améliorer la fonction cérébrale.... Score: -0.1602 Document: El precio del café ha aumentado un 20% este año debido a problemas en la cadena de suministro.... Score: -0.1699 Document: Basketball is one of the most popular sports in the United States....
結論
jina-reranker-v3 是一個新的 0.6B parameter 多語言 listwise reranker,引入了 last but not late interaction,以實現高效的 document reranking。Documents 在編碼過程中可以互相關注,建立交互,從而影響最終排序。
一個主要關注點是這種交互是否對輸入順序的變化具有魯棒性——也就是説,如果我們打亂輸入順序,排名是否保持不變?我們用一個 query 對 110 個 candidate documents 進行了隨機排列測試,並在下圖中繪製了每個排名位置的方差。
關鍵發現是,排名靠前的位置表現出極好的穩定性。排名 1-10 的方差最小,最相關的 documents 無論輸入順序如何,都能穩定排在頂部。這對於 nDCG@10 和類似的 top-k 指標至關重要。無關的 documents 一直排在底部,清晰區分了相關內容和無關內容。
中間部分顯示了明顯的位置交換,這是預期且可接受的。模型使用 causal self-attention,並根據序列中前面的內容編碼不同的上下文信息。
在實際應用中,我們關心的是最頂部的結果,這種行為完全可以接受。我們的評估顯示jina-reranker-v3的性能優於早期版本,包括jina-reranker-v2-base-multilingual和jina-colbert-v2,以及更大的替代模型如 Qwen3-Reranker-4B 和jina-reranker-m0,進一步證實了這一點。
原文:Jina Reranker v3: 0.6B Listwise Reranker for SOTA Multilingual Retrieval