Rerank (reorder documents by relevance)
POST /v1/rerank reorders a set of candidate documents by their relevance to a query; it is used for re-ranking RAG retrieval results and for search result optimization. It uses the Cohere format — Cohere SDK compatible.
1. Request
bash
curl https://token.yaoshu.cc/v1/rerank \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "<rerank-model>",
"query": "What is natural language processing",
"documents": ["NLP is a field of AI...", "Computer vision is..."],
"top_n": 3
}'| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Rerank model name, as returned by GET /v1/models |
query | string | ✅ | Query text |
documents | string[] | ✅ | List of candidate documents |
top_n | number | No | Return the top N results |
2. Response
Standard Cohere structure: results[] contains index (the index of the corresponding input document) and relevance_score (relevance score; higher means more relevant), already sorted by score in descending order.
3. Billing
Metered by token (query + documents combined). Unit prices are per the model pricing page in the Console.
