Rerank
curl --request POST \
--url https://api.leapx-hub.com/v1/rerank \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"query": "<string>",
"documents": [
{}
],
"top_n": 123,
"return_documents": true
}
'import requests
url = "https://api.leapx-hub.com/v1/rerank"
payload = {
"model": "<string>",
"query": "<string>",
"documents": [{}],
"top_n": 123,
"return_documents": True
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
query: '<string>',
documents: [{}],
top_n: 123,
return_documents: true
})
};
fetch('https://api.leapx-hub.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.leapx-hub.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' => [
[
]
],
'top_n' => 123,
'return_documents' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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.leapx-hub.com/v1/rerank"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n {}\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.leapx-hub.com/v1/rerank")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n {}\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.leapx-hub.com/v1/rerank")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n {}\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}"
response = http.request(request)
puts response.read_body{
"model": "rerank-v1",
"results": [
{
"index": 0,
"relevance_score": 0.95,
"document": "AI is a branch of computer science dedicated to creating intelligent systems."
},
{
"index": 1,
"relevance_score": 0.82,
"document": "Machine learning is a subfield of AI focused on learning from data."
},
{
"index": 2,
"relevance_score": 0.65,
"document": "Deep learning uses neural networks for pattern recognition."
}
],
"usage": {
"total_tokens": 128
}
}
Text Series
Rerank
POST
/
v1
/
rerank
Rerank
curl --request POST \
--url https://api.leapx-hub.com/v1/rerank \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"query": "<string>",
"documents": [
{}
],
"top_n": 123,
"return_documents": true
}
'import requests
url = "https://api.leapx-hub.com/v1/rerank"
payload = {
"model": "<string>",
"query": "<string>",
"documents": [{}],
"top_n": 123,
"return_documents": True
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
query: '<string>',
documents: [{}],
top_n: 123,
return_documents: true
})
};
fetch('https://api.leapx-hub.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.leapx-hub.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' => [
[
]
],
'top_n' => 123,
'return_documents' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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.leapx-hub.com/v1/rerank"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n {}\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.leapx-hub.com/v1/rerank")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n {}\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.leapx-hub.com/v1/rerank")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"query\": \"<string>\",\n \"documents\": [\n {}\n ],\n \"top_n\": 123,\n \"return_documents\": true\n}"
response = http.request(request)
puts response.read_body{
"model": "rerank-v1",
"results": [
{
"index": 0,
"relevance_score": 0.95,
"document": "AI is a branch of computer science dedicated to creating intelligent systems."
},
{
"index": 1,
"relevance_score": 0.82,
"document": "Machine learning is a subfield of AI focused on learning from data."
},
{
"index": 2,
"relevance_score": 0.65,
"document": "Deep learning uses neural networks for pattern recognition."
}
],
"usage": {
"total_tokens": 128
}
}
Introduction
Rerank documents by relevance to a query, commonly used in RAG to optimize retrieval results.Authentication
string
required
Bearer Token, e.g.
Bearer sk-xxxxxxxxxxRequest Parameters
string
required
Model name, e.g.
rerank-v1string
required
Query text
array
required
List of documents to rank
integer
Return top N results (default: all)
boolean
default:"false"
Return document content
cURL Example
curl https://api.leapx-hub.com/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-XyLy**************************mIqSt" \
-d '{
"model": "rerank-v1",
"query": "What is artificial intelligence?",
"documents": [
"AI is a branch of computer science dedicated to creating intelligent systems.",
"Machine learning is a subfield of AI focused on learning from data.",
"Deep learning uses neural networks for pattern recognition."
],
"top_n": 3,
"return_documents": true
}'
Python Example
import requests
url = "https://api.leapx-hub.com/v1/rerank"
headers = {
"Authorization": "Bearer sk-XyLy**************************mIqSt",
"Content-Type": "application/json"
}
data = {
"model": "rerank-v1",
"query": "What is artificial intelligence?",
"documents": [
"AI is a branch of computer science dedicated to creating intelligent systems.",
"Machine learning is a subfield of AI focused on learning from data.",
"Deep learning uses neural networks for pattern recognition."
],
"top_n": 3,
"return_documents": True
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
{
"model": "rerank-v1",
"results": [
{
"index": 0,
"relevance_score": 0.95,
"document": "AI is a branch of computer science dedicated to creating intelligent systems."
},
{
"index": 1,
"relevance_score": 0.82,
"document": "Machine learning is a subfield of AI focused on learning from data."
},
{
"index": 2,
"relevance_score": 0.65,
"document": "Deep learning uses neural networks for pattern recognition."
}
],
"usage": {
"total_tokens": 128
}
}
Response Fields
| Field | Type | Description |
|---|---|---|
| results[].index | integer | Original document index |
| results[].relevance_score | float | Relevance score (0-1) |
| results[].document | string | Document content (when return_documents=true) |
Notes
- Common in RAG: first vector search for candidates, then rerank to optimize
- Higher
relevance_scoremeans more relevant to query - Requires
requestslibrary:pip install requests
⌘I
