跳转到主要内容
Refining the Translation Process I’ve just finished translating the example content, meticulously applying the rules to maintain structural integrity and adhere to the specified exclusions. I’ve double-checked for any accidental translations within code blocks or component names, and confirmed that key technical terms remain in English. My focus now is on iterating through the rest of the documentation, ensuring consistency and accuracy across the entire MDX file.

title: “重排序文档” openapi: “POST /v1/rerank” description: “根据与查询的相关性对文档进行重排序”

使用语义相似度模型对文档进行重排序。适用于优化搜索结果和 RAG 应用。

请求体

model
string
必填
要使用的重排序模型 ID(例如 BAAI/bge-reranker-v2-m3qwen3-rerank)。
query
string
必填
用于对文档进行排序的查询语句。
documents
array
必填
需要重排序的文档列表(字符串数组)。
top_n
integer
返回的前几个结果的数量。默认为所有文档。
return_documents
boolean
默认值:"false"
是否在响应中包含原始文档文本。

响应

results
array
带有评分的已排序文档列表。每个结果包含:
  • index (integer): 原始文档索引
  • relevance_score (number): 相关性评分 (0-1)
  • document (string): 原始文本(如果 return_documents=true
model
string
用于重排序的模型。
usage
object
Token 使用统计。
curl -X POST "https://api.lemondata.cc/v1/rerank" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "BAAI/bge-reranker-v2-m3",
    "query": "What is machine learning?",
    "documents": [
      "Machine learning is a subset of AI",
      "The weather is nice today",
      "Deep learning uses neural networks"
    ],
    "top_n": 2,
    "return_documents": true
  }'
{
  "results": [
    {
      "index": 0,
      "relevance_score": 0.95,
      "document": "Machine learning is a subset of AI"
    },
    {
      "index": 2,
      "relevance_score": 0.82,
      "document": "Deep learning uses neural networks"
    }
  ],
  "model": "BAAI/bge-reranker-v2-m3",
  "usage": {
    "prompt_tokens": 45,
    "total_tokens": 45
  }
}