Skip to content

Rerank

Rerank a list of documents by their relevance to a query. Useful for improving retrieval results from vector search or keyword search.

POST /v1/rerank

Required capability: rerank

Request Body

ParameterTypeRequiredDescription
modelstringYesReranking model identifier (e.g. rerank-english-v3.0, rerank-multilingual-v3.0).
querystringYesThe search query to rank documents against.
documentsstring[]YesArray of document strings to rerank (1-10,000 documents).
top_nintegerNoNumber of top results to return. Defaults to the length of the input documents array.
return_documentsbooleanNoIf true, the response includes the document text alongside scores.

Request size limit: 10 MB

Response

{
"results": [
{
"index": 3,
"relevance_score": 0.9856,
"document": "Quantum computing uses qubits that can exist in superposition..."
},
{
"index": 0,
"relevance_score": 0.7234,
"document": "Classical computers use binary bits..."
}
],
"model": "rerank-english-v3.0"
}

Response Fields

FieldTypeDescription
resultsarrayArray of reranked results, sorted by relevance score (highest first).
results[].indexintegerOriginal index of the document in the input array.
results[].relevance_scorenumberRelevance score between 0 and 1. Higher is more relevant.
results[].documentstringThe document text (only present when return_documents is true).
modelstringThe model used for reranking.

Example

Terminal window
curl https://your-gateway.example.com/v1/rerank \
-H "Authorization: Bearer aigw_sk_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "rerank-english-v3.0",
"query": "What is quantum computing?",
"documents": [
"Classical computers use binary bits to process information.",
"The weather forecast predicts rain tomorrow.",
"Machine learning models require training data.",
"Quantum computing uses qubits that can exist in superposition states.",
"The stock market closed higher today."
],
"top_n": 3,
"return_documents": true
}'