意味的類似性モデルを使用してドキュメントを再ランク付けします。検索結果の改善や RAG アプリケーションに役立ちます。
リクエストボディ
同期リクエストのタイムアウト: この非チャットエンドポイントは、ルーティング先モデルの処理完了を待ちます。大きな入力、長い音声、大きなバッチは一般的な 30s のクライアント既定値を超えることがあるため、HTTP クライアントのタイムアウトは少なくとも 120s に設定してください。
使用するリランカーモデルの ID(例:qwen3-vl-rerank、qwen3-vl-rerank)。
ドキュメントをランク付けするためのクエリ。最大長は 32,000 文字です。
再ランク付けするドキュメント(文字列)のリスト。上限は最大 1,000 件、各ドキュメント最大 100,000 文字、ドキュメント合計最大 2,000,000 文字です。
返す上位結果の数です。既定ではすべての documents を返します。1 以上、かつ documents.length 以下である必要があります。将来プロバイダーがより厳しい公開制限を示した場合、TokenLab はここに記録して適用します。
レスポンスに元のドキュメントテキストを含めるかどうか。
レスポンス
スコア順にランク付けされたドキュメントのリスト。各結果には以下が含まれます:
index (integer): 元のドキュメントのインデックス
relevance_score (number): 関連性スコア (0-1)
document (string): 元のテキスト(return_documents=true の場合)
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
}
}