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

ParameterTypeRequiredDescription
modelstringrequiredRerank model slug, e.g. cohere/rerank-v3.5, jina/reranker-v2, voyage/rerank-2.
querystringrequiredThe query documents are scored against.
documentsstring[]requiredThe candidate documents to rerank.
top_nintegeroptionalReturn only the top N results. Default: all.
return_documentsbooleanoptionalInclude 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

FieldTypeRequiredDescription
idstringoptionalUnique request id.
modelstringoptionalThe resolved model slug.
providerstringoptionalThe provider that served the request.
resultsobject[]optionalReranked results, highest relevance first (see below).
usageobjectoptional{ total_tokens, search_units, cost } - cost in USD.

Result object

FieldTypeRequiredDescription
indexintegeroptionalIndex of the document in the original documents array.
relevance_scorenumberoptionalRelevance score, higher is more relevant.
documentobject | nulloptional{ 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));