Reordenación
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_bodyEmbeddings y reordenación
Reordenación
Reordenar los resultados de búsqueda semánticamente
POST
/
v1
/
rerank
Reordenación
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_bodyContenido actualizado: 2026-06-06
Descripción de la interfaz
Reordena un conjunto de documentos según su relevancia semántica con la consulta, comúnmente utilizado en la segunda fase de clasificación fina en la generación mejorada por recuperación RAG.Consultar la implementación en el formato SiliconFlow Rerank API.
Modelos soportados
| Modelo | Descripción |
|---|---|
gte-rerank-v2 | Modelo de reordenación multilingüe, recomendado |
gte-rerank-v2 | Principalmente en inglés |
Parámetros de solicitud
string
requerido
Nombre del modelo de reordenación, como
gte-rerank-v2string
requerido
Texto de la consulta
string[]
requerido
Lista de documentos a ordenar
integer
Retornar los primeros N resultados; por defecto retorna todos
boolean
predeterminado:"true"
Si se debe devolver el texto original del documento en la respuesta
Formato de respuesta
{
"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
}
}
Ejemplo de código
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
}'
Proceso típico de RAG
用户查询 → Embedding 检索 Top-K → Rerank 精排 → LLM 生成回答
Se recomienda que el número de documentos de entrada para el modelo de reordenación no supere las 100 entradas. Un número excesivo de documentos incrementa la latencia y el costo.