airflow.providers.cohere.operators.rerank

Classes

CohereRerankOperator

Rerank documents by their relevance to a query using Cohere's Rerank API.

Module Contents

class airflow.providers.cohere.operators.rerank.CohereRerankOperator(*, query, documents, model=None, top_n=None, max_tokens_per_doc=None, conn_id=CohereHook.default_conn_name, timeout=None, request_options=None, **kwargs)[source]

Bases: airflow.providers.common.compat.sdk.BaseOperator

Rerank documents by their relevance to a query using Cohere’s Rerank API.

See also

For more information on how to use this operator, take a look at the guide: CohereRerankOperator

Parameters:
  • query (str) – The search query used to rank the documents.

  • documents (list[str]) – Text documents to compare with the query.

  • model (str | None) – Model to use for reranking. Uses the hook’s default when omitted.

  • top_n (int | None) – Maximum number of ranked documents to return. By default, all are returned.

  • max_tokens_per_doc (int | None) – Maximum number of tokens retained from each document.

  • conn_id (str) – Cohere connection id.

  • timeout (int | None) – Request timeout in seconds.

  • request_options (cohere.core.request_options.RequestOptions | None) – Request-specific configuration passed to the Cohere client.

template_fields: collections.abc.Sequence[str] = ('query', 'documents', 'top_n', 'max_tokens_per_doc')[source]
template_fields_renderers[source]
query[source]
documents[source]
model = None[source]
top_n = None[source]
max_tokens_per_doc = None[source]
conn_id = 'cohere_default'[source]
timeout = None[source]
request_options = None[source]
property hook: airflow.providers.cohere.hooks.cohere.CohereHook[source]

Return a Cohere hook.

execute(context)[source]

Rerank the documents and return an XCom-serializable response.

Was this entry helpful?