重排序
curl --request POST \
--url https://api.example.com/v1/rerank \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"query": "<string>",
"documents": [
"<string>"
],
"top_n": 123,
"return_documents": true
}
'import requests
url = "https://api.example.com/v1/rerank"
payload = {
"model": "<string>",
"query": "<string>",
"documents": ["<string>"],
"top_n": 123,
"return_documents": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
query: '<string>',
documents: ['<string>'],
top_n: 123,
return_documents: true
})
};
fetch('https://api.example.com/v1/rerank', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/rerank",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'query' => '<string>',
'documents' => [
'<string>'
],
'top_n' => 123,
'return_documents' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/rerank"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n \"<string>\"\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/rerank")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n \"<string>\"\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/rerank")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n \"<string>\"\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}"
response = http.request(request)
puts response.read_body嵌入 & 重排序
重排序
对搜索结果进行语义重排序
POST
/
v1
/
rerank
重排序
curl --request POST \
--url https://api.example.com/v1/rerank \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"query": "<string>",
"documents": [
"<string>"
],
"top_n": 123,
"return_documents": true
}
'import requests
url = "https://api.example.com/v1/rerank"
payload = {
"model": "<string>",
"query": "<string>",
"documents": ["<string>"],
"top_n": 123,
"return_documents": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
query: '<string>',
documents: ['<string>'],
top_n: 123,
return_documents: true
})
};
fetch('https://api.example.com/v1/rerank', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/rerank",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'query' => '<string>',
'documents' => [
'<string>'
],
'top_n' => 123,
'return_documents' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/rerank"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n \"<string>\"\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/rerank")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n \"<string>\"\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/rerank")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n \"<string>\"\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}"
response = http.request(request)
puts response.read_body更新日期:2026-06-06
接口说明
对一组文档按照与查询的语义相关性进行重新排序,常用于 RAG 检索增强生成的第二阶段精排。参考 SiliconFlow Rerank API 格式实现。
支持模型
| 模型 | 说明 |
|---|---|
gte-rerank-v2 | 多语言重排序模型,推荐 |
gte-rerank-v2 | 英文为主 |
请求参数
重排序模型名称,如
gte-rerank-v2查询文本
待排序的文档列表
返回前 N 个结果,默认返回全部
是否在响应中返回文档原文
响应格式
{
"model": "gte-rerank-v2",
"results": [
{
"index": 2,
"relevance_score": 0.9875,
"document": { "text": "最相关的文档内容" }
},
{
"index": 0,
"relevance_score": 0.7432,
"document": { "text": "次相关的文档内容" }
},
{
"index": 1,
"relevance_score": 0.1205,
"document": { "text": "不太相关的文档内容" }
}
],
"usage": {
"total_tokens": 128
}
}
代码示例
import requests
response = requests.post(
"https://api.crazyrouter.com/v1/rerank",
headers={
"Authorization": "Bearer sk-xxx",
"Content-Type": "application/json"
},
json={
"model": "gte-rerank-v2",
"query": "什么是向量数据库",
"documents": [
"向量数据库是专门存储和检索高维向量的数据库系统",
"关系型数据库使用表格存储结构化数据",
"向量数据库支持近似最近邻搜索,适合语义检索场景",
"Redis 是一个内存键值存储系统"
],
"top_n": 2,
"return_documents": True
}
)
data = response.json()
for result in data["results"]:
print(f"[{result['relevance_score']:.4f}] {result['document']['text']}")
curl -X POST https://api.crazyrouter.com/v1/rerank \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gte-rerank-v2",
"query": "什么是向量数据库",
"documents": [
"向量数据库是专门存储和检索高维向量的数据库系统",
"关系型数据库使用表格存储结构化数据"
],
"top_n": 2
}'
典型 RAG 流程
用户查询 → Embedding 检索 Top-K → Rerank 精排 → LLM 生成回答
重排序模型的输入文档数量建议不超过 100 条。文档过多会增加延迟和费用。
⌘I