Semantik benzerlik modellerini kullanarak dokümanları yeniden sıralayın. Arama sonuçlarını ve RAG uygulamalarını iyileştirmek için kullanışlıdır.
İstek Gövdesi
Senkron istek zaman aşımı: Bu chat dışı endpoint, yönlendirilen modelin tamamlanmasını bekler. Büyük girdiler, uzun sesler veya büyük batch’ler yaygın 30s istemci varsayılanlarını aşabilir; bu yüzden HTTP istemcisi zaman aşımını en az 120s olarak ayarlayın.
Kullanılacak reranker modelinin kimliği (örneğin, qwen3-vl-rerank).
Dokümanların sıralanacağı sorgu. Maksimum uzunluk: 32,000 karakter.
Yeniden sıralanacak dokümanların (dizelerin) listesi. Sınırlar: en fazla 1,000 doküman, her doküman en fazla 100,000 karakter ve toplamda en fazla 2,000,000 doküman karakteri.
Döndürülecek en iyi sonuç sayısı. Varsayılan olarak tüm documents döner. En az 1 olmalı ve documents.length değerini aşmamalıdır. Bir provider ileride daha sıkı bir public limit yayımlarsa TokenLab bunu burada dokümante eder ve uygular.
return_documents
boolean
varsayılan: "false"
Orijinal doküman metninin yanıtta yer alıp almayacağı.
Yanıt
Puanlarıyla birlikte sıralanmış doküman listesi. Her sonuç şunları içerir:
index (integer): Orijinal doküman dizini
relevance_score (number): İlgi düzeyi puanı (0-1)
document (string): Orijinal metin (eğer return_documents=true ise)
Yeniden sıralama için kullanılan model.
Token kullanım istatistikleri.
cURL
Python
JavaScript
Go
PHP
curl -X POST "https://api.tokenlab.sh/v1/rerank" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-vl-rerank",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of AI",
"The weather is nice today",
"Deep learning uses neural networks"
],
"top_n": 2,
"return_documents": true
}'
import requests
response = requests.post(
"https://api.tokenlab.sh/v1/rerank" ,
headers = { "Authorization" : "Bearer sk-your-api-key" },
json = {
"model" : "qwen3-vl-rerank" ,
"query" : "What is machine learning?" ,
"documents" : [
"Machine learning is a subset of AI" ,
"The weather is nice today" ,
"Deep learning uses neural networks"
],
"top_n" : 2
}
)
print (response.json())
const response = await fetch ( 'https://api.tokenlab.sh/v1/rerank' , {
method: 'POST' ,
headers: {
'Authorization' : 'Bearer sk-your-api-key' ,
'Content-Type' : 'application/json'
},
body: JSON . stringify ({
model: 'qwen3-vl-rerank' ,
query: 'What is machine learning?' ,
documents: [
'Machine learning is a subset of AI' ,
'The weather is nice today' ,
'Deep learning uses neural networks'
],
top_n: 2
})
});
const data = await response . json ();
console . log ( data . results );
package main
import (
" bytes "
" encoding/json "
" fmt "
" net/http "
)
func main () {
payload := map [ string ] interface {}{
"model" : "qwen3-vl-rerank" ,
"query" : "What is machine learning?" ,
"documents" : [] string {
"Machine learning is a subset of AI" ,
"The weather is nice today" ,
"Deep learning uses neural networks" ,
},
"top_n" : 2 ,
}
body , _ := json . Marshal ( payload )
req , _ := http . NewRequest ( "POST" , "https://api.tokenlab.sh/v1/rerank" , bytes . NewBuffer ( body ))
req . Header . Set ( "Authorization" , "Bearer sk-your-api-key" )
req . Header . Set ( "Content-Type" , "application/json" )
client := & http . Client {}
resp , _ := client . Do ( req )
defer resp . Body . Close ()
var result map [ string ] interface {}
json . NewDecoder ( resp . Body ). Decode ( & result )
fmt . Println ( result [ "results" ])
}
<? php
$ch = curl_init ( 'https://api.tokenlab.sh/v1/rerank' );
curl_setopt_array ( $ch , [
CURLOPT_RETURNTRANSFER => true ,
CURLOPT_POST => true ,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json' ,
'Authorization: Bearer sk-your-api-key'
],
CURLOPT_POSTFIELDS => json_encode ([
'model' => 'qwen3-vl-rerank' ,
'query' => 'What is machine learning?' ,
'documents' => [
'Machine learning is a subset of AI' ,
'The weather is nice today' ,
'Deep learning uses neural networks'
],
'top_n' => 2
])
]);
$response = curl_exec ( $ch );
curl_close ( $ch );
$data = json_decode ( $response , true );
print_r ( $data [ 'results' ]);
{
"results" : [
{
"index" : 0 ,
"relevance_score" : 0.95 ,
"document" : "Machine learning is a subset of AI"
},
{
"index" : 2 ,
"relevance_score" : 0.82 ,
"document" : "Deep learning uses neural networks"
}
],
"model" : "qwen3-vl-rerank" ,
"usage" : {
"prompt_tokens" : 45 ,
"total_tokens" : 45
}
}