엔드포인트
리랭크
POST /rerank로 질의와의 관련도에 따라 문서 목록을 다시 정렬해 검색 품질을 높이는 방법입니다. 요청 파라미터, 응답 형식, 검색당 요금, 리랭크 모델 목록 조회, 오류를 다룹니다. 검색 결과 순서를 다듬을 때 활용하세요.
플레이그라운드에서 사용해 보기질의와의 관련도에 따라 문서 목록을 정렬합니다. 리랭커는 검색 파이프라인의 두 번째 단계입니다. 임베딩이나 키워드 검색으로 후보 50–200개를 가져온 뒤, 리랭크하여 프롬프트에 넣을 상위 몇 개만 남기세요.
POST https://api14.com/api/v1/rerank
공식 OpenAI SDK에는 rerank 메서드가 없으므로 일반 HTTP로 호출합니다(아래 모든 언어 예제가 그렇게 합니다).
요청
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
model | string | 예 | 리랭크 모델 ID. 예: cohere/rerank-v3.5. |
query | string | 예 | 검색 질의. |
documents | string[] | 예 | 점수를 매길 후보 텍스트. |
top_n | integer | 아니요 | 상위 N개 결과만 반환합니다. 기본값은 전체입니다. |
return_documents | boolean | 아니요 | 각 결과에 문서 텍스트를 포함합니다. |
예제
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가 높은 순으로 정렬됩니다.
가격
리랭크 모델은 모델에 표시된 가격으로 검색 1회당 과금되며, "$ / 1K searches"로 표시됩니다. 비용은 usage.cost에 담기며 USD 잔액에서 차감됩니다.
리랭크 모델 목록 조회
curl "https://api14.com/api/v1/models?category=rerank"
오류
| 상태 | 코드 | 발생 조건 |
|---|---|---|
| 400 | model_required / invalid_json | model이 없거나 본문 형식이 잘못되었습니다. |
| 402 | insufficient_balance | USD 잔액이 $0입니다. |
| 403 | model_not_allowed | 키의 허용 목록에 해당 모델이 없습니다. |
| 404 | model_not_found | 알 수 없거나 비활성화된 모델 ID입니다. |
| 429 | rate_limited | 분당 요청 수를 초과했습니다. |
오류를 참고하세요.