Skip to content

Jina AI 重排序格式

POST  v1/rerank

官方文档:https://jina.ai/reranker

标准格式:Jina

AI的rerank格式被采用为标准格式。所有其他供应商(如Xinference、Cohere等)的rerank响应都会被格式化为Jina AI的格式,以提供统一的开发体验。

请求参数

Authorization

在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。

Authorization: Bearer ******************

Body 参数

Content-Type: application/json

参数名类型必填说明
modelstring必需要使用的模型 ID。有关哪些模型适用于 Chat API 的详细信息,请参阅模型端点兼容性表。
querystring必需查询文本内容。
top_ninteger必需返回最相关结果的数量。
documentsarray[string]必需用于检索或分析的文档字符串数组。
messagesarray [object]必需模型聊天记录。包含 role(可选:user/assistant/system)和 content(可选:文本内容)。
streamboolean必需如果设置为 true,模型响应数据将在生成时通过服务器发送事件流式传输到客户端。
storeboolean可选是否存储此聊天补全请求的输出以用于模型蒸馏或评估产品。
reasoning_effortstring可选仅适用于 o系列 的模型。约束推理模型的推理工作。当前支持的值为 low、medium 和 high。减少推理工作可以加快响应速度并减少响应中用于推理的标记数。
metadataobject可选可以附加到对象的16个键值对集合。这对于以结构化格式存储对象的其他信息很有用。键是最大长度为64个字符的字符串。值是最大长度为512个字符的字符串。
modalitiesarray[string]可选您希望模型为此请求生成的输出类型。大多数模型都能生成文本,这是默认设置: ["text"]。该模型还可以用于生成音频。要请求此模型同时生成文本和音频响应,您可以使用: ["text", "audio"]。
predictionobject可选预测输出的配置,当提前知道模型响应的大部分内容时,可以大大提高响应时间。这在您只对文件进行微小更改时最常见。
audioobject可选音频输出的参数。当使用 modalities: ["audio"] 请求音频输出时需要。
temperaturenumber可选要使用的采样温度,介于 0 和 2 之间。较高的值(如0.8)会使输出更加随机,而较低的值(如0.2)会使其更加集中和确定性。我们通常建议更改此值或 top_p,但不要同时更改。
top_pnumber可选一种替代采样温度的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记结果。因此,0.1 意味着只考虑包含前 10% 概率质量的标记。我们通常建议更改此值或 temperature,但不要同时更改。
ninteger可选为每个输入消息生成多少个聊天补全选择。请注意,您将根据所有选择生成的标记数量收费。保持 n 为 1 可最大限度地降低成本。
stopstring可选不支持最新的推理模型和 .o3、o4-mini。API 将停止生成更多标记的最多 4 个序列。返回的文本不会包含停止序列。
max_completion_tokensinteger可选补全中可以生成的标记数的上限,包括可见输出标记和推理标记。
presence_penaltynumber可选介于 -2.0 和 2.0 之间的数字。正值根据新标记到目前为止在文本中出现的情况来惩罚它们,从而增加模型讨论新主题的可能性。
frequency_penaltynumber可选介于 -2.0 和 2.0 之间的数字。正值根据新标记到目前为止在文本中的现有频率来惩罚它们,从而降低模型逐字重复同一行的可能性。
logit_biasstring可选修改指定标记出现在补全中的可能性。接受一个 JSON 对象,该对象将标记(由分词器中的标记 ID 指定)映射到从 -100 到 100 的关联偏差值。在数学上,偏差被添加到模型在采样之前生成的对数中。确切的效果会因模型而异,但介于 -1 和 1 之间的值应该会减少或增加选择的可能性;像 -100 或 100 这样的值应该导致相关标记被禁止或独占选择。
logprobsboolean可选是否返回输出标记的对数概率。
userstring可选表示最终用户的唯一标识符,可以帮助 OpenAI 监控和检测滥用行为。

请求示例 (JSON)

{
    "model": "jina-reranker-v2-base-multilingual",
    "query": "What is the capital of the United States?",
    "top_n": 3,
    "documents": [
        "Carson City is the capital city of the American state of Nevada.",
        "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
        "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
        "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
        "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
    ]
}

返回响应

200 成功

Content-Type: application/json

响应参数

字段名类型必填说明
idstring必需请求唯一标识符。用于定位和追踪本次 API 调用的 ID。
objectstring必需对象类型。对于聊天补全接口,该值固定为 "chat.completion"
createdinteger必需创建时间戳。生成本次响应的 Unix 时间戳(秒级)。
modelstring必需实际使用的模型。生成此响应的具体模型名称及版本(例如 gpt-4o-2024-05-13)。
choicesarray [object]必需回复选项数组。包含模型生成的回复内容列表(默认长度为1)。
├─ indexinteger可选当前选项在数组中的索引位置。
├─ messageobject可选生成的消息对象,包含以下核心字段:
├─ rolestring必需角色身份,通常固定为 "assistant"
├─ contentnull/string必需模型生成的文本内容。若模型进行了工具调用或纯音频输出,此处可能为 null
├─ refusalnull/string必需如果模型拒绝回答某些敏感或不合规的内容,拒绝的理由会在此字段显示。
├─ audioobject必需音频输出对象。当请求了音频模态时,这里会包含生成的音频数据及相关参数。
└─ annotationsarray[string]必需针对回复内容的附加注释或引用信息。
├─ logprobsnull可选输出 token 的对数概率信息(需在请求中开启 logprobs: true)。
└─ finish_reasonstring可选停止原因。模型停止生成的原因,常见值有: • stop:自然结束或遇到停止词 • length:达到最大 token 限制 • tool_calls:模型发起了工具/函数调用。
usageobject必需Token 用量统计,包含以下明细:
├─ prompt_tokensinteger必需输入提示词(Prompt)消耗的 Token 数量。
├─ completion_tokensinteger必需模型生成的回复(Completion)消耗的 Token 数量。
├─ total_tokensinteger必需本次请求消耗的总 Token 数(输入 + 输出)。

响应示例

{
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "\n\nHello there, how may I assist you today?"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 9,
        "completion_tokens": 12,
        "total_tokens": 21
    }
}

示例代码

python
import http.client
import json

conn = http.client.HTTPSConnection("nxaiapp.com")
payload = json.dumps({
   "model": "jina-reranker-v2-base-multilingual",
   "query": "What is the capital of the United States?",
   "top_n": 3,
   "documents": [
      "Carson City is the capital city of the American state of Nevada.",
      "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
      "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
      "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
      "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
   ]
})
headers = {
   'Authorization': 'Bearer <token>',
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1/rerank", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))