文档重排序(Rerank)
将查询和候选文档提交给重排序模型,模型会为每个文档计算相关性分数并返回排序后的结果。常用于检索增强生成(RAG)的召回结果精排阶段。
请求
POST /v1/rerank
Content-Type: application/json
Authorization: Bearer sk-your-api-key
调用示例
curl -X POST "https://www.walmind.cn/v1/rerank" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "your-rerank-model",
"query": "如何配置向量数据库?",
"documents": [
"向量数据库用于存储和检索向量。",
"模型 API 使用 Bearer Token 认证。"
],
"top_n": 2,
"return_documents": true
}'
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
model | string | 重排序模型 ID,必填 |
query | string | 查询文本,必填 |
documents | array | 待排序文档列表,必填 |
top_n | integer | 返回前 N 个结果,可选 |
return_documents | boolean | 是否在结果中回传文档内容,默认 false |
响应示例
{
"id": "rerank-example",
"results": [
{"index": 0, "relevance_score": 0.92, "document": {"text": "向量数据库用于存储和检索向量。"}},
{"index": 1, "relevance_score": 0.12, "document": {"text": "模型 API 使用 Bearer Token 认证。"}}
],
"meta": {}
}
index 是原始 documents 数组中的下标;不要把排序后的下标当作原始文档 ID。文档数量、长度和语言支持以重排序模型的限制为准。