---
type: api
title: Perform reranking inference on the service
description: ## Required authorization
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-inference-rerank
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-inference-rerank
products:
  - Elasticsearch
---

# Perform reranking inference on the service

Availability: 8.11+

## Paths

- `POST` `/_inference/rerank/{inference_id}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#bearerauth)

#### Path Parameters

- `inference_id` (string Id)
  The unique identifier for the inference endpoint.

## Description



## Required authorization

* Cluster privileges: `monitor_inference`

## Query String Parameters

- `timeout` (string Duration · default: 30s)
  The amount of time to wait for the inference request to complete.

## Request Body

`application/json`

- `query` (string) — required
  Query input.
- `input` (union string | [] string) — required
  The text on which you want to perform the inference task.
It can be a single string or an array.

> info
> Inference endpoints for the `completion` task type currently only support a single string as input.
- `task_settings` (TaskSettings) — optional
  Task settings for the individual inference request.
These settings are specific to the task type you specified and override the task settings specified when initializing the service.

## Response

`application/json`

- `rerank` ([] RankedDocument)
  - `index` (number)
  - `relevance_score` (number)
  - `text` (string)
## Code Examples

#### Console

```console
POST _inference/rerank/cohere_rerank
{
  "input": ["luke", "like", "leia", "chewy","r2d2", "star", "wars"],
  "query": "star wars main character"
}
```

#### JavaScript

```javascript
const response = await client.inference.rerank({
  inference_id: "cohere_rerank",
  input: ["luke", "like", "leia", "chewy", "r2d2", "star", "wars"],
  query: "star wars main character",
});
```

#### Python

```python
resp = client.inference.rerank(
    inference_id="cohere_rerank",
    input=[
        "luke",
        "like",
        "leia",
        "chewy",
        "r2d2",
        "star",
        "wars"
    ],
    query="star wars main character",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_inference/rerank/cohere_rerank" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": [
      "luke",
      "like",
      "leia",
      "chewy",
      "r2d2",
      "star",
      "wars"
    ],
    "query": "star wars main character"
  }'
```

#### Java

```java
client.inference().rerank(r -> r
    .inferenceId("cohere_rerank")
    .input(List.of("luke","like","leia","chewy","r2d2","star","wars"))
    .query("star wars main character")
);
```

#### C#

```c#
var response = await client.Inference
    .RerankAsync(inferenceId: "cohere_rerank", d1 => d1
        .Input("luke", "like", "leia", "chewy", "r2d2", "star", "wars")
        .Query("star wars main character")
    );
```

#### PHP

```php
$resp = $client->inference()->rerank([
    "inference_id" => "cohere_rerank",
    "body" => [
        "input" => array(
            "luke",
            "like",
            "leia",
            "chewy",
            "r2d2",
            "star",
            "wars",
        ),
        "query" => "star wars main character",
    ],
]);
```

#### Ruby

```ruby
response = client.inference.rerank(
  inference_id: "cohere_rerank",
  body: {
    "input": [
      "luke",
      "like",
      "leia",
      "chewy",
      "r2d2",
      "star",
      "wars"
    ],
    "query": "star wars main character"
  }
)
```

## Response Examples

#### Rerank task

A successful response from `POST _inference/rerank/cohere_rerank`.

```json
{
  "rerank": [
    {
      "index": "2",
      "relevance_score": "0.011597361",
      "text": "leia"
    },
    {
      "index": "0",
      "relevance_score": "0.006338922",
      "text": "luke"
    },
    {
      "index": "5",
      "relevance_score": "0.0016166499",
      "text": "star"
    },
    {
      "index": "4",
      "relevance_score": "0.0011695103",
      "text": "r2d2"
    },
    {
      "index": "1",
      "relevance_score": "5.614787E-4",
      "text": "like"
    },
    {
      "index": "6",
      "relevance_score": "3.7850367E-4",
      "text": "wars"
    },
    {
      "index": "3",
      "relevance_score": "1.2508839E-5",
      "text": "chewy"
    }
  ]
}
```

#### Rerank task

A successful response from `POST _inference/rerank/bge-reranker-base-mkn`.

```json
{
  "rerank": [
    {
      "index": 6,
      "relevance_score": 0.50955844
    },
    {
      "index": 5,
      "relevance_score": 0.084341794
    }
  ]
}
```

#### Rerank task

A successful response from `POST _inference/rerank/bge-reranker-base-mkn`.

```json
{
  "rerank": [
    {
      "index": 6,
      "relevance_score": 0.50955844,
      "text": "wars"
    },
    {
      "index": 5,
      "relevance_score": 0.084341794,
      "text": "star"
    },
    {
      "index": 3,
      "relevance_score": 0.004520818,
      "text": "chewy"
    }
  ]
}
```

