Skip to main content
POST
/
v1
/
rerank
创建重排序
curl --request POST \
  --url https://api.qhaigc.net/v1/rerank \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "query": "<string>",
  "documents": [
    "<string>"
  ],
  "top_n": 123
}
'
{
  "results": [
    {
      "index": 123,
      "relevance_score": 123
    }
  ],
  "usage": {}
}

功能说明

重排序(Rerank)接口可以将一组文档按照与查询(Query)的相关性进行打分和排序。这通常作为 RAG(检索增强生成)流程的最后一步,用于进一步提高检索结果的准确性。

请求参数

名称类型必选说明
modelstring模型名称,如 bge-reranker-v2-m3
querystring查询文本
documentsarray待排序的文档列表(字符串数组)
top_ninteger返回前几个结果

调用示例

import requests

url = "https://api.qhaigc.net/v1/rerank"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-your-api-key-here"
}

data = {
    "model": "bge-reranker-v2-m3",
    "query": "Organic skincare products for sensitive skin",
    "top_n": 3,
    "documents": [
        "Organic skincare for sensitive skin with aloe vera and chamomile...",
        "New makeup trends focus on bold colors and innovative techniques...",
        "Bio-Hautpflege für empfindliche Haut mit Aloe Vera und Kamille..."
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

返回结果

返回每个文档的原始索引和相关性得分(分数越高越相关)。
{
  "results": [
    {
      "index": 0,
      "relevance_score": 0.985363245010376
    },
    {
      "index": 2,
      "relevance_score": 0.6773008704185486
    },
    {
      "index": 1,
      "relevance_score": 0.00001600799623702187
    }
  ],
  "usage": {
    "prompt_tokens": 77,
    "total_tokens": 77
  }
}

相关参考

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
model
string
required
query
string
required
documents
string[]
required
top_n
integer

Response

200 - application/json

成功响应

results
object[]
usage
object