SiliconFlow
API手册

创建重排序请求

根据与查询的相关性对文档进行重排序。支持文本、图片和视频内容。

POST
/rerank
AuthorizationBearer <token>required

添加 Header 'Authorization: Bearer {账户 API Key}' 进行鉴权

In: header

modelstringrequired

对应的模型名称。为更好地提升服务质量,我们会对本服务提供的模型进行定期变更,包括但不限于模型上下线和模型服务能力的调整。在可行的情况下,我们会通过公告或消息推送等适当方式通知您此类变更。完整可用模型列表请查看 Models

Example"BAAI/bge-reranker-v2-m3"
querystringrequired

搜索查询。长度必须 ≥ 1。

Length1 <= length
Example"Apple"
documentsstring | arrayrequired

待排序的文档列表。支持以下格式:

  • 单个文本字符串
  • 文本字符串数组 至少需要 1 个文档。

Item: 重排序输入列表中的单个文档项目。

instructionstring

重排序器的指令。仅 Qwen/Qwen3-Reranker-8B、Qwen/Qwen3-Reranker-4B、Qwen/Qwen3-Reranker-0.6B 支持。长度必须 ≥ 1。

Length1 <= length
Example"Please rerank the documents based on the query."
top_ninteger

返回的最相关文档或索引数量。必须 ≥ 1。

Range1 <= value
Example4
return_documentsboolean

如果为 false,响应中不包含文档文本;如果为 true,则包含输入文档文本。默认值为 false。

max_chunks_per_docinteger

从文档内部生成的最大片段数。长文档会被切分为多个片段进行计算,取各片段中的最高分作为文档得分。仅 BAAI/bge-reranker-v2-m3、Pro/BAAI/bge-reranker-v2-m3、netease-youdao/bce-reranker-base_v1 支持此字段。必须 ≥ 1,默认值为 1024。

Default1024
Range1 <= value
overlap_tokensinteger

文档切分时相邻片段之间的 token 重叠数量。仅 BAAI/bge-reranker-v2-m3、Pro/BAAI/bge-reranker-v2-m3、netease-youdao/bce-reranker-base_v1 支持此字段。必须在 0 到 80 之间。

Rangevalue <= 80
modelstringrequired

多模态重排序的模型名称。支持模型:Qwen/Qwen3-VL-Reranker-8B

Example"Qwen/Qwen3-VL-Reranker-8B"
querystring | objectrequired

搜索查询。支持文本字符串或内容对象。

  • 文本查询:纯字符串
  • 图片查询:{"image": "https://example.com/image.jpg"} 或 base64

长度必须 ≥ 1。

documentsarray<string | object | object>required

待排序的文档列表。每个项目可以是文本字符串或内容对象。

  • 文本文档:纯字符串
  • 文本对象:{"text": "文档文本"}
  • 图片对象:{"image": "https://example.com/image.jpg"} 或 base64

至少需要 1 个文档。

Example["apple","banana","fruit","vegetable"]

Item: 多模态重排序输入列表中的单个文档项目。

instructionstring

重排序器的指令。仅 Qwen/Qwen3-Reranker-8B、Qwen/Qwen3-Reranker-4B、Qwen/Qwen3-Reranker-0.6B 支持。长度必须 ≥ 1。

Length1 <= length
Example"Please rerank the documents based on the query."
top_ninteger

返回的最相关文档或索引数量。必须 ≥ 1。

Range1 <= value
Example4
return_documentsboolean

如果为 false,响应中不包含文档文本;如果为 true,则包含输入文档文本。默认值为 false。

max_chunks_per_docinteger

从单个文档生成的最大片段数。必须 ≥ 1,默认值为 1024。

Default1024
Range1 <= value
overlap_tokensinteger

文档切分时相邻片段之间的 token 重叠数量。必须在 0 到 80 之间。

Rangevalue <= 80

Response Body

模型响应。响应头中包含 x-siliconcloud-trace-id 字段,作为请求的唯一追踪标识,便于日志查询和问题排查。

TypeScript Definitions

Use the response body type in TypeScript.

idstringrequired

响应的唯一标识符。

Example"rerank-20240115-abc123def456"
resultsarray<object>required

按相关性分数排序的重排序结果列表。

Item: 单个重排序结果。

metaobject

重排序响应的元数据。

curl -X POST https://api.siliconflow.cn/v1/rerank \
  -H "Authorization: Bearer $SILICONFLOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "BAAI/bge-reranker-v2-m3",
    "query": "Apple",
    "documents": ["apple", "banana", "fruit", "vegetable"],
    "return_documents": true,
    "top_n": 4
  }'
import os
import requests

url = "https://api.siliconflow.cn/v1/rerank"
headers = {
    "Authorization": f"Bearer {os.environ.get('SILICONFLOW_API_KEY')}",
    "Content-Type": "application/json"
}
payload = {
    "model": "BAAI/bge-reranker-v2-m3",
    "query": "Apple",
    "documents": ["apple", "banana", "fruit", "vegetable"],
    "return_documents": True,
    "top_n": 4
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.siliconflow.cn/v1/rerank";
const headers = {
  "Authorization": `Bearer ${process.env.SILICONFLOW_API_KEY}`,
  "Content-Type": "application/json"
};
const payload = {
  model: "BAAI/bge-reranker-v2-m3",
  query: "Apple",
  documents: ["apple", "banana", "fruit", "vegetable"],
  return_documents: true,
  top_n: 4
};

fetch(url, {
  method: "POST",
  headers: headers,
  body: JSON.stringify(payload)
})
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));
curl -X POST https://api.siliconflow.cn/v1/rerank \
  -H "Authorization: Bearer $SILICONFLOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen3-VL-Reranker-8B",
    "query": {
      "image": "https://example.com/query-image.jpg"
    },
    "documents": [
      {
        "image": "https://example.com/doc1.jpg"
      },
      "这是一个相关的文本文档..."
    ],
    "max_chunks_per_doc": 512
  }'
import os
import requests

url = "https://api.siliconflow.cn/v1/rerank"
headers = {
    "Authorization": f"Bearer {os.environ.get('SILICONFLOW_API_KEY')}",
    "Content-Type": "application/json"
}
payload = {
    "model": "Qwen/Qwen3-VL-Reranker-8B",
    "query": {
        "image": "https://example.com/query-image.jpg"
    },
    "documents": [
        {"image": "https://example.com/doc1.jpg"},
        "这是一个相关的文本文档..."
    ],
    "max_chunks_per_doc": 512
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.siliconflow.cn/v1/rerank";
const headers = {
  "Authorization": `Bearer ${process.env.SILICONFLOW_API_KEY}`,
  "Content-Type": "application/json"
};
const payload = {
  model: "Qwen/Qwen3-VL-Reranker-8B",
  query: {
    image: "https://example.com/query-image.jpg"
  },
  documents: [
    { image: "https://example.com/doc1.jpg" },
    "这是一个相关的文本文档..."
  ],
  max_chunks_per_doc: 512
};

fetch(url, {
  method: "POST",
  headers: headers,
  body: JSON.stringify(payload)
})
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));          
curl -X POST https://api.siliconflow.cn/v1/rerank \
  -H "Authorization: Bearer $SILICONFLOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen3-Reranker-8B",
    "query": "找出最相关的技术文档",
    "documents": ["文档1", "文档2", "文档3"],
    "instruction": "优先考虑最新发布的内容",
    "overlap_tokens": 20
  }'
import os
import requests

url = "https://api.siliconflow.cn/v1/rerank"
headers = {
    "Authorization": f"Bearer {os.environ.get('SILICONFLOW_API_KEY')}",
    "Content-Type": "application/json"
}
payload = {
    "model": "Qwen/Qwen3-Reranker-8B",
    "query": "找出最相关的技术文档",
    "documents": ["文档1", "文档2", "文档3"],
    "instruction": "优先考虑最新发布的内容",
    "overlap_tokens": 20
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.siliconflow.cn/v1/rerank";
const headers = {
  "Authorization": `Bearer ${process.env.SILICONFLOW_API_KEY}`,
  "Content-Type": "application/json"
};
const payload = {
  model: "Qwen/Qwen3-Reranker-8B",
  query: "找出最相关的技术文档",
  documents: ["文档1", "文档2", "文档3"],
  instruction: "优先考虑最新发布的内容",
  overlap_tokens: 20
};

fetch(url, {
  method: "POST",
  headers: headers,
  body: JSON.stringify(payload)
})
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));                     
{
  "id": "rerank-20240115-abc123def456",
  "results": [
    {
      "index": 1,
      "document": {
        "text": "深度学习是机器学习的子集..."
      },
      "relevance_score": 0.85
    }
  ],
  "meta": {
    "tokens": {
      "input_tokens": 150,
      "output_tokens": 10,
      "image_tokens": 0
    },
    "billed_units": {
      "input_tokens": 150,
      "output_tokens": 10,
      "image_tokens": 0,
      "search_units": 1,
      "classifications": 0
    }
  }
}
{
  "code": 20012,
  "message": "string",
  "data": "string"
}
"Invalid token"
"Forbidden"
"404 page not found"
{
  "message": "Request was rejected due to rate limiting. If you want more, please contact contact@siliconflow.cn. Details:TPM limit reached.",
  "data": "string"
}
{
  "code": 50505,
  "message": "Model service overloaded. Please try again later.",
  "data": "string"
}
"string"
创建重排序请求