Implementation:Marker Inc Korea AutoRAG CohereReranker
| Knowledge Sources | |
|---|---|
| Domains | RAG, Passage_Reranking, API |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
CohereReranker reranks passages using Cohere's cloud-based rerank API endpoint with asynchronous batch processing.
Description
The CohereReranker class extends BasePassageReranker and leverages the Cohere rerank API to score and reorder retrieved passages based on their relevance to a given query. It initializes an asynchronous Cohere client (cohere.AsyncClientV2) using an API key sourced from the constructor parameter or the COHERE_API_KEY / CO_API_KEY environment variables. The _pure method dispatches concurrent reranking tasks per query using the process_batch utility, which respects the configurable batch size to control API throughput.
Usage
Import and use CohereReranker when you need a cloud-based, API-driven passage reranking step in an AutoRAG pipeline. It is suitable when you prefer not to run local GPU inference and have a valid Cohere API key. The default model is rerank-v3.5, with multilingual and English-specific v3.0 variants also available.
Code Reference
Source Location
- Repository: Marker_Inc_Korea_AutoRAG
- File: autorag/nodes/passagereranker/cohere.py
- Lines: 12-118
Signature
class CohereReranker(BasePassageReranker):
def __init__(self, project_dir: str, *args, **kwargs)
def _pure(
self,
queries: List[str],
contents_list: List[List[str]],
scores_list: List[List[float]],
ids_list: List[List[str]],
top_k: int,
batch: int = 64,
model: str = "rerank-v3.5",
) -> Tuple[List[List[str]], List[List[str]], List[List[float]]]
Import
from autorag.nodes.passagereranker.cohere import CohereReranker
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| queries | List[str] | Yes | List of query strings to use for reranking. |
| contents_list | List[List[str]] | Yes | List of passage content lists corresponding to each query. |
| scores_list | List[List[float]] | Yes | List of initial retrieval score lists (not used in scoring, passed through for interface compatibility). |
| ids_list | List[List[str]] | Yes | List of passage ID lists corresponding to each query. |
| top_k | int | Yes | Number of top passages to return after reranking. |
| batch | int | No | Number of concurrent API requests to process in a batch. Default is 64. |
| model | str | No | Cohere rerank model name. Options include "rerank-v3.5", "rerank-english-v3.0", "rerank-multilingual-v3.0". Default is "rerank-v3.5". |
Outputs
| Name | Type | Description |
|---|---|---|
| content_result | List[List[str]] | Reranked passage contents per query, ordered by relevance. |
| id_result | List[List[str]] | Passage IDs corresponding to the reranked contents. |
| score_result | List[List[float]] | Relevance scores assigned by the Cohere rerank model. |
Usage Examples
Basic Usage
import os
os.environ["COHERE_API_KEY"] = "your-cohere-api-key"
from autorag.nodes.passagereranker.cohere import CohereReranker
reranker = CohereReranker(project_dir="/path/to/project")
queries = ["What is retrieval augmented generation?"]
contents_list = [["RAG combines retrieval and generation.", "Unrelated passage.", "RAG improves accuracy."]]
scores_list = [[0.9, 0.5, 0.8]]
ids_list = [["id1", "id2", "id3"]]
contents, ids, scores = reranker._pure(
queries=queries,
contents_list=contents_list,
scores_list=scores_list,
ids_list=ids_list,
top_k=2,
model="rerank-v3.5",
)
print(contents) # Top 2 passages reranked by Cohere
print(scores) # Corresponding relevance scores