> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ninjachat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Reranking

> Sort retrieved documents by relevance before generating an answer.

Use your [API key](/authentication) to rank search results against a query. Reranking scores the documents you provide; it does not search the web or store your index.

## Rank documents

```bash cURL theme={null}
curl https://www.ninjachat.ai/api/v1/rerank \
  -H "Authorization: Bearer $NINJACHAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"rerank-2.5","query":"How long do I have to return an item?","documents":["Delivery takes 3 to 5 business days.","Returns are accepted within 30 days."],"top_n":1,"return_documents":true}'
```

Read `results` for the ranked matches. Each includes the original `index` and a `relevance_score`; `return_documents: true` also includes the text.

| Parameter          | Values                                                        |
| ------------------ | ------------------------------------------------------------- |
| `model`            | `rerank-2.5` or `rerank-2.5-lite`.                            |
| `query`            | The search question.                                          |
| `documents`        | 1–1,000 nonempty strings.                                     |
| `top_n`            | Number of results to return; no more than the document count. |
| `return_documents` | Include document text; default `false`.                       |
| `truncation`       | Allow provider truncation; default `false`.                   |

Use [embeddings](/embeddings) to retrieve candidates, then rerank before sending them to your chat model.
