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

# Document Reranking

> <ul><li>Rerank a list of documents by relevance to a query</li></ul>

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl --request POST \
    --url 'https://api.elkapi.com/v1/rerank' \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "jina-reranker-v2-base-multilingual",
    "query": "query",
    "documents": [
      "document"
    ]
  }'
  ```

  ```python Python theme={null} theme={null}
  import requests

  url = "https://api.elkapi.com/v1/rerank"
  headers = {
      "Authorization": "Bearer <token>"
  }
  headers["Content-Type"] = "application/json"
  payload = {
      "model": "jina-reranker-v2-base-multilingual",
      "query": "query",
      "documents": [
          "document"
      ]
  }

  response = requests.request("POST", url, headers=headers, json=payload)
  print(response.json())
  ```

  ```javascript JavaScript theme={null} theme={null}
  const url = "https://api.elkapi.com/v1/rerank";

  const headers = {
    "Authorization": "Bearer <token>"
  };
  headers["Content-Type"] = "application/json";
  const payload = {
    "model": "jina-reranker-v2-base-multilingual",
    "query": "query",
    "documents": [
      "document"
    ]
  };

  const response = await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(payload)
  });

  console.log(await response.json());
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null} theme={null}
  {
    "id": "id",
    "results": [
      {
        "index": 1,
        "relevance_score": 1,
        "document": {}
      }
    ],
    "meta": {}
  }
  ```
</ResponseExample>

## Authorizations

<ParamField header="Authorization" type="string" required>
  All endpoints require Bearer Token authentication.

  Add it to the request headers:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" required default="jina-reranker-v2-base-multilingual">
  Example: `jina-reranker-v2-base-multilingual`
</ParamField>

<ParamField body="query" type="string" required>
  Query text
</ParamField>

<ParamField body="documents" type="array<string or object>" required>
  List of documents to rerank
</ParamField>

<ParamField body="top_n" type="integer">
  Return the top N results
</ParamField>

<ParamField body="return_documents" type="boolean" default="false" />

## Response

<ResponseField name="id" type="string" />

<ResponseField name="results" type="array<object>">
  <ResponseField name="results.index" type="integer" />

  <ResponseField name="results.relevance_score" type="number" />

  <ResponseField name="results.document" type="object" />
</ResponseField>

<ResponseField name="meta" type="object" />
