Rerank
Reorder a candidate set by relevance to a query. Cohere-compatible canonical schema.
POST/api/v1/rerank
Reranking is the standard second stage of a retrieval pipeline: retrieve a broad candidate set cheaply, then rerank the top documents with a cross-encoder for precision. SearchRouter adopts Cohere's /rerank shape as canonical across Cohere, Jina, Voyage, and Mixedbread.
Request
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | required | Rerank model slug, e.g. cohere/rerank-v3.5, jina/reranker-v2, voyage/rerank-2. |
| query | string | required | The query documents are scored against. |
| documents | string[] | required | The candidate documents to rerank. |
| top_n | integer | optional | Return only the top N results. Default: all. |
| return_documents | boolean | optional | Include document text in each result. Default true. |
json
{
"model": "cohere/rerank-v3.5",
"query": "what is hybrid search?",
"documents": ["doc text 1", "doc text 2", "doc text 3"],
"top_n": 3,
"return_documents": true
}Response
| Field | Type | Required | Description |
|---|---|---|---|
| id | string | optional | Unique request id. |
| model | string | optional | The resolved model slug. |
| provider | string | optional | The provider that served the request. |
| results | object[] | optional | Reranked results, highest relevance first (see below). |
| usage | object | optional | { total_tokens, search_units, cost } - cost in USD. |
Result object
| Field | Type | Required | Description |
|---|---|---|---|
| index | integer | optional | Index of the document in the original documents array. |
| relevance_score | number | optional | Relevance score, higher is more relevant. |
| document | object | null | optional | { text } when return_documents is true. |
json
{
"id": "sr-rerank-xyz",
"model": "cohere/rerank-v3.5",
"provider": "cohere",
"results": [
{ "index": 2, "relevance_score": 0.98, "document": { "text": "doc text 3" } },
{ "index": 0, "relevance_score": 0.71, "document": { "text": "doc text 1" } }
],
"usage": { "total_tokens": 0, "search_units": 1, "cost": 0.001 }
}ⓘSpecial case: Mixedbread. Mixedbread returns
data[] with a score field instead of results[] with relevance_score. Its adapter remaps both so the response is identical to the canonical shape above.Examples
cURL
bash
curl https://searchrouter.ai/api/v1/rerank \
-H "Authorization: Bearer $SR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "cohere/rerank-v3.5",
"query": "what is hybrid search?",
"documents": [
"Hybrid search blends BM25 and vector similarity.",
"Cats are small domesticated mammals.",
"Reranking reorders candidates by relevance."
],
"top_n": 2
}'Python
python
import os, requests
resp = requests.post(
"https://searchrouter.ai/api/v1/rerank",
headers={"Authorization": f"Bearer {os.environ['SR_API_KEY']}"},
json={
"model": "cohere/rerank-v3.5",
"query": "what is hybrid search?",
"documents": ["doc text 1", "doc text 2", "doc text 3"],
"top_n": 3,
},
)
resp.raise_for_status()
for r in resp.json()["results"]:
print(r["relevance_score"], r["index"])JavaScript
javascript
const resp = await fetch("https://searchrouter.ai/api/v1/rerank", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SR_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "cohere/rerank-v3.5",
query: "what is hybrid search?",
documents: ["doc text 1", "doc text 2", "doc text 3"],
top_n: 3,
}),
});
const { results } = await resp.json();
results.forEach((r) => console.log(r.relevance_score, r.index));