---
title: cohere_rerank
latest-connect-version: 4.118.0
latest-operator-version: v26.2.6
latest-console-tag: v3.14.0
latest-redpanda-tag: v26.2.7
docname: processors/cohere_rerank
page-component-name: connect
page-version: master
page-component-version: master
page-component-title: Connect
page-relative-src-path: processors/cohere_rerank.adoc
page-edit-url: https://github.com/redpanda-data/rp-connect-docs/edit/main/modules/components/pages/processors/cohere_rerank.adoc
description: Reranks a list of documents by their relevance to a query, using the Cohere API.
page-cloud-available: "true"
page-cloud-available-url: https://docs.redpanda.com/cloud-data-platform/develop/connect/components/processors/cohere_rerank/
page-git-created-date: "2025-05-19"
page-git-modified-date: "2026-11-13"
page-generated-sources:
  - include: connect:components:partial$descriptions/processors/cohere_rerank.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
  - include: connect:components:partial$availability/processors/cohere_rerank.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
  - include: connect:components:partial$examples/processors/cohere_rerank.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
  - include: connect:components:partial$fields/processors/cohere_rerank.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
page-generated-content: partial
---

# cohere_rerank

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [connect-full.txt](https://docs.redpanda.com/connect-full.txt)

<!-- Source: https://docs.redpanda.com/connect/components/processors/cohere_rerank.md -->

Reranks a list of documents by their relevance to a query, using the Cohere API.

Introduced in version 4.53.0.

This processor sends document strings to the [Cohere API](https://docs.cohere.com/reference/rerank), which reranks them based on the relevance to the query.

To learn more about reranking, see the [Cohere API documentation](https://docs.cohere.com/docs/rerank-2).

The output of this processor is an array of objects. Each object has the following fields:

-   `document`: The original document content.

-   `relevance_score`: How relevant the document is to the query.

-   `index`: The document’s position within the input documents array.


The objects are ordered by their relevance score (highest first).

#### Common

```yml
processor:
  label: ""
  cohere_rerank:
    base_url: https://api.cohere.com
    api_key: "" # No default (required)
    model: "" # No default (required)
    query: "" # No default (required)
    documents: "" # No default (required)
    top_n: "0"
    max_tokens_per_doc: 4096
```

#### Advanced

```yml
processor:
  label: ""
  cohere_rerank:
    base_url: https://api.cohere.com
    api_key: "" # No default (required)
    model: "" # No default (required)
    query: "" # No default (required)
    documents: "" # No default (required)
    top_n: "0"
    max_tokens_per_doc: 4096
```

## Metadata

-   `relevance_scores`: An array of scores for each input document that indicates how relevant it is to the query. The scores are in the same order as the documents in the input. The higher the score, the more relevant the document.


## Examples

### Rerank some documents based on a query

Rerank some documents based on a query

```yaml
input:
  generate:
    interval: 1s
    mapping: |
      root = {
        "query": fake("sentence"),
        "docs": [fake("paragraph"), fake("paragraph"), fake("paragraph")],
      }
pipeline:
  processors:
  - cohere_rerank:
      model: rerank-v3.5
      api_key: "${COHERE_API_KEY}"
      query: "${!this.query}"
      documents: "root = this.docs"
output:
  stdout: {}
```

## Fields

### `api_key`

Your API key for the Cohere API.

> ⚠️ **CAUTION**
>
> This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see [Secrets](https://docs.redpanda.com/connect/configuration/secrets/).

**Type**: `string`

### `base_url`

The base URL to use for API requests.

**Type**: `string`

**Default**: `https://api.cohere.com`

### `documents`

A list of text strings that are compared to the specified query. For optimal performance, Cohere recommends that you:

-   Send fewer than 1000 documents in a single request.

-   Send structured data in YAML format.


**Type**: `string`

### `max_tokens_per_doc`

This processor automatically truncates long documents to the specified number of tokens.

**Type**: `int`

**Default**: `4096`

### `model`

The name of the Cohere model you want to use.

**Type**: `string`

```yaml
# Examples:
model: rerank-v3.5
```

### `query`

The search query you want to execute.

This field supports [interpolation functions](https://docs.redpanda.com/connect/configuration/interpolation/#bloblang-queries).

**Type**: `string`

### `top_n`

The number of documents to return when the query is executed. If set to `0`, all documents are returned.

This field supports [interpolation functions](https://docs.redpanda.com/connect/configuration/interpolation/#bloblang-queries).

**Type**: `string`

**Default**: `0`