开发者资源

文档中心

产品指南、接入说明与 API 参考

文档中心文本重排序
文本重排序

文本重排序

SenseTime TokenPlan 当前模型与接入说明

文本重排序

按查询对候选文档计算相关性并排序。当前重排序模型为 qwen3.7-text-rerank。

请求地址

POST https://token.sensetime.com/api/v1/rerank

  • Content-Type:application/json
  • 请求体不超过 4 MiB。未定义字段会被拒绝。

授权

请求必须携带 API Key:

Authorization: Bearer <API_KEY>

将 <API_KEY> 替换为工作台创建的密钥。下面的示例使用环境变量 TOKENPLAN_API_KEY。

模型选择

当前文本重排序模型:qwen3.7-text-rerank。

调用前查询模型列表,确认被选模型实际返回的 mode 为 rerank。

请求体

fallbacks 当前仅接受空值,不要传入。

modelstring必填

模型 ID。

querystring必填

查询文本,不能为空。

documentsarray必填

1 到 2048 条文档。元素为非空字符串,或文档对象,可混合。

Show child attributesHide child attributes
textstring必填

文档对象中的文本,不能为空。

idstring

文档标识。传入时必须是非空字符串。

metaobject

附加信息。

top_ninteger

返回条数。传入时至少为 1。

max_tokens_per_docinteger

每篇文档的 token 上限。传入时至少为 1。

return_documentsboolean

为 true 时,结果中带回文档。

priorityinteger

优先级提示,是否生效取决于模型。

请求示例

curl "https://token.sensetime.com/api/v1/rerank" \
  -H "Authorization: Bearer $TOKENPLAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.7-text-rerank",
    "query": "退货政策",
    "documents": [
      "本店支持七天无理由退货。",
      {"text": "会员积分可在结算时抵扣。", "id": "doc-2"}
    ],
    "top_n": 2,
    "return_documents": true
  }'

响应字段

成功时 HTTP 状态码为 200,Content-Type 为 application/json。results 按 relevance_score 从高到低排列。

idstring

本次响应的标识。

resultsobject[]

排序结果。

Show child attributesHide child attributes
indexinteger

文档在原始 documents 中的下标,从 0 开始。

relevance_scorenumber

相关性分数。

documentobject

return_documents 为 true 时返回。

Show child attributesHide child attributes
textstring

文档文本。

idstring

文档标识。

metaobject

附加信息。

modelstring

实际响应的模型 ID。

usageobject

Token 消耗。

Show child attributesHide child attributes
prompt_tokensinteger

输入 token 数。

prompt_tokens_detailsobject
Show child attributesHide child attributes
text_tokensinteger
audio_tokensinteger
image_tokensinteger
cached_read_tokensinteger

从提示缓存读取的 token,已计入 prompt_tokens。

cached_write_tokensinteger

本次写入提示缓存的 token,已计入 prompt_tokens。

completion_tokensinteger

输出 token 数。

completion_tokens_detailsobject
Show child attributesHide child attributes
text_tokensinteger
accepted_prediction_tokensinteger
audio_tokensinteger
citation_tokensinteger
num_search_queriesinteger
reasoning_tokensinteger
image_tokensinteger
rejected_prediction_tokensinteger
total_tokensinteger

输入与输出之和。

tool_usageobject
Show child attributesHide child attributes
web_searchobject
Show child attributesHide child attributes
num_requestsinteger

Web 搜索次数。

响应示例

{
  "results": [
    {
      "index": 0,
      "relevance_score": 0.91,
      "document": { "text": "本店支持七天无理由退货。" }
    },
    {
      "index": 1,
      "relevance_score": 0.12,
      "document": { "text": "会员积分可在结算时抵扣。", "id": "doc-2" }
    }
  ],
  "model": "qwen3.7-text-rerank"
}

错误处理

model 或 query 为空、documents 不是 1 到 2048 条、文档文本为空、id 为空字符串、top_n 或 max_tokens_per_doc 小于 1,或请求体含未定义字段时,请求失败。

相关指南