Cloud

cohere_rerank

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

This processor sends document strings to the Cohere API, which reranks them based on the relevance to the query.

To learn more about reranking, see the Cohere API documentation.

The output of this processor is an array of objects, each containing a "document" field with the original document content, a "relevance_score" field indicating how relevant it is to the query, and an index field that refers to the document’s position within the input documents array. The objects are ordered by their relevance score (highest first).

  • Common

  • Advanced

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
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

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.

This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Manage Secrets before adding it to your configuration.

Type: string

base_url

The base URL to use for API requests.

Type: string

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

# Examples:
model: rerank-v3.5

query

The search query you want to execute.

This field supports interpolation functions.

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.

Type: string

Default: 0