---
title: Rerank
description: Rerank document search results for optimized retrieval accuracy in RAG workflows.
---

<ApiEndpoint method="POST" path="/v1/rerank" auth="api_key" />

Reorder candidate documents by their relevance to a query through a supported reranking model.

<KeyInserter type="api" label="API Key Tester" placeholder="zrv_your_api_key" />

---

## Code example

<CodeGroup titles={["cURL", "Python"]}>

```bash
curl https://api.zorveus.com/v1/rerank \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer zrv_your_api_key" \
  -d '{
    "model": "cohere/rerank-v3.5",
    "query": "What is write-ahead logging?",
    "documents": [
      "Write-ahead logging records transactions sequentially before disk writes.",
      "Redis is an in-memory key-value data store.",
      "PostgreSQL uses MVCC for concurrency control."
    ],
    "top_n": 2
  }'
```

```python
import requests

response = requests.post(
    "https://api.zorveus.com/v1/rerank",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer zrv_your_api_key",
    },
    json={
        "model": "cohere/rerank-v3.5",
        "query": "What is write-ahead logging?",
        "documents": [
            "Write-ahead logging records transactions sequentially before disk writes.",
            "Redis is an in-memory key-value data store.",
            "PostgreSQL uses MVCC for concurrency control.",
        ],
        "top_n": 2,
    },
)

print(response.json())
```

</CodeGroup>

## Request and result

Send `query`, `documents`, and a routable `model`. Use `top_n` to limit returned results when the provider supports it. Each result identifies the original document position and includes a relevance score or provider-equivalent ranking value.

Reranking does not retrieve documents. Retrieve a candidate set first, then rerank only the number of documents that fits the model's limits and your latency budget.

Check `GET /v1/models` before using the example model. Provider model IDs and response fields can differ.
