Skip to main content
POST
/
v1
/
rerank
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
Last updated: 2026-06-06

Overview

Reorder a set of documents by semantic relevance to a query. Commonly used as the second-stage reranking step in RAG (Retrieval-Augmented Generation) pipelines.
Implemented following the SiliconFlow Rerank API format.

Supported Models

ModelDescription
gte-rerank-v2Multilingual reranking model, recommended
gte-rerank-v2Primarily English

Request Parameters

model
string
required
Reranking model name, e.g. gte-rerank-v2
query
string
required
Query text
documents
string[]
required
List of documents to rerank
top_n
integer
Return the top N results. Defaults to returning all
return_documents
boolean
default:"true"
Whether to include the original document text in the response

Response Format

{
  "model": "gte-rerank-v2",
  "results": [
    {
      "index": 2,
      "relevance_score": 0.9875,
      "document": { "text": "Most relevant document content" }
    },
    {
      "index": 0,
      "relevance_score": 0.7432,
      "document": { "text": "Second most relevant document content" }
    },
    {
      "index": 1,
      "relevance_score": 0.1205,
      "document": { "text": "Less relevant document content" }
    }
  ],
  "usage": {
    "total_tokens": 128
  }
}

Code Examples

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": "What is a vector database",
        "documents": [
            "A vector database is a database system specialized for storing and retrieving high-dimensional vectors",
            "Relational databases use tables to store structured data",
            "Vector databases support approximate nearest neighbor search, suitable for semantic retrieval scenarios",
            "Redis is an in-memory key-value store"
        ],
        "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": "What is a vector database",
    "documents": [
      "A vector database is a database system specialized for storing and retrieving high-dimensional vectors",
      "Relational databases use tables to store structured data"
    ],
    "top_n": 2
  }'

Typical RAG Pipeline

User Query → Embedding Retrieval Top-K → Rerank → LLM Generates Answer
The number of input documents for reranking should not exceed 100. Too many documents will increase latency and cost.