重排序#

学习如何在Xinference中使用重新排序模型。

介绍#

给定一个查询和一系列文档,Rerank 会根据与查询的语义相关性从最相关到最不相关对文档进行重新排序。在 Xinference 中,可以通过 Rerank 端点调用 Rerank 模型来对一系列文档进行排序。

快速入门#

我们可以通过cURL、OpenAI Client或Xinference的来尝试使用Rerank API:

curl -X 'POST' \
  'http://<XINFERENCE_HOST>:<XINFERENCE_PORT>/v1/rerank' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "<MODEL_UID>",
    "query": "A man is eating pasta.",
    "documents": [
        "A man is eating food.",
        "A man is eating a piece of bread.",
        "The girl is carrying a baby.",
        "A man is riding a horse.",
        "A woman is playing violin."
    ]
  }'

Multimodal reranking with jina-reranker-m0#

jina-reranker-m0 supports text and image reranking with a maximum context length of 10,240 tokens. Text documents use the standard rerank API shown above. To rerank image URLs or local image paths, pass doc_type="image":

model.rerank(
    [
        "https://example.com/document-1.png",
        "https://example.com/document-2.png",
    ],
    "Which document describes a small language model?",
    doc_type="image",
)

For an image query, also pass query_type="image".