文本重排序
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 当前仅接受空值,不要传入。
模型 ID。
查询文本,不能为空。
1 到 2048 条文档。元素为非空字符串,或文档对象,可混合。
Show child attributesHide child attributes
文档对象中的文本,不能为空。
文档标识。传入时必须是非空字符串。
附加信息。
返回条数。传入时至少为 1。
每篇文档的 token 上限。传入时至少为 1。
为 true 时,结果中带回文档。
优先级提示,是否生效取决于模型。
请求示例
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 从高到低排列。
本次响应的标识。
排序结果。
Show child attributesHide child attributes
文档在原始 documents 中的下标,从 0 开始。
相关性分数。
return_documents 为 true 时返回。
Show child attributesHide child attributes
文档文本。
文档标识。
附加信息。
实际响应的模型 ID。
Token 消耗。
Show child attributesHide child attributes
输入 token 数。
Show child attributesHide child attributes
从提示缓存读取的 token,已计入 prompt_tokens。
本次写入提示缓存的 token,已计入 prompt_tokens。
输出 token 数。
Show child attributesHide child attributes
输入与输出之和。
Show child attributesHide child attributes
Show child attributesHide child attributes
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,或请求体含未定义字段时,请求失败。