Cookieを使用しています. Cookieとブラウザストレージは、ログイン状態の維持と設定の保存に使われます。許可いただいた場合は、サイトの利用状況も計測します。はいつでも変更できます。詳しくはCookieポリシーをご覧ください。

リランク

エンドポイント

リランク

POST /rerank で候補ドキュメントをクエリへの関連度順に並べ替える方法です。埋め込みで取得した 50〜200 件を上位数件に絞るリクエストとレスポンス、料金、リランクモデルの一覧、エラーを説明します。OpenAI SDK にメソッドがないため通常の HTTP で呼び出します。

プレイグラウンドで試す

ドキュメントのリストを、クエリへの関連度の順に並べ替えます。リランカーは検索パイプラインの 2 段目です。埋め込みまたはキーワード検索で 50〜200 件の候補を取得し、リランクして上位の数件だけをプロンプトに残します。

POST https://api14.com/api/v1/rerank

公式の OpenAI SDK にはリランクのメソッドがないため、通常の HTTP で呼び出します(以下の各言語の例もすべてそうしています)。

リクエスト

パラメーター型必須説明
modelstringはいリランクモデルの ID。例: cohere/rerank-v3.5。
querystringはい検索クエリ。
documentsstring[]はいスコアを付ける候補のテキスト。
top_nintegerいいえ上位 N 件の結果のみを返します。デフォルトはすべて。
return_documentsbooleanいいえ各結果にドキュメントのテキストを含めます。

例

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
});

const result = await client.post("/rerank", { body: {
  "model": "cohere/rerank-v3.5",
  "query": "What is the capital of France?",
  "documents": [
    "Paris is the capital of France.",
    "Berlin is in Germany."
  ],
  "top_n": 1
} });
console.log(result.results);
curl https://api14.com/api/v1/rerank \
  -H "Authorization: Bearer sk-api14-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cohere/rerank-v3.5",
    "query": "How do I reset my password?",
    "documents": [
      "Billing happens on the first of each month.",
      "To reset your password, open Settings and choose Security.",
      "Our office is closed on public holidays."
    ],
    "top_n": 2
  }'

レスポンス

{
  "id": "gen-1791100000-rr1",
  "model": "cohere/rerank-v3.5",
  "results": [
    { "index": 1, "relevance_score": 0.94 },
    { "index": 0, "relevance_score": 0.08 }
  ],
  "usage": { "search_units": 1, "cost": 0.002 }
}

index は、documents 配列内の位置を指します。結果は relevance_score の高い順に並びます。

料金

リランクモデルは、モデルの表示価格(「$ / 1K searches」)で、検索ごとに課金されます。料金は usage.cost に含まれ、USD 残高から差し引かれます。

リランクモデルの一覧

curl "https://api14.com/api/v1/models?category=rerank"

エラー

ステータスコード発生条件
400model_required / invalid_jsonmodel がない、またはボディの形式が正しくない。
402insufficient_balanceUSD 残高が $0。
403model_not_allowedキーの許可リストにモデルが含まれていない。
404model_not_foundモデル ID が不明、または無効化されている。
429rate_limited毎分のリクエスト数を超えた。

エラーを参照してください。