TOOL WIKI · DATA & RETRIEVAL

Cohere Rerank

Scores candidate documents against a query to refine retrieval ordering.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Select the useful policy from retrieved candidates

A policy assistant needs usable source text or relevant evidence before a generation model can answer a question reliably.

Input
A returns question and candidate shipping/returns texts.
Expected output
A ranked candidate index mapped back to the original source text.
  • Success check: The reranker returns an index into the supplied candidate list, preserving the source mapping.
  • Try a failure: A correct rank cannot recover a missing source; include retrieval misses in end-to-end evaluation.

Example scope: Actual hosted reranking call; the retriever supplied the candidate set first.

Official reference · Cohere Rerank

WHAT IT ISReranking API
WHERE IT FITSData & retrieval
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
inputprocessresultcheckoutputQuestion + candidatesExisting search resultsCohere RerankReranking APIRanked candidatesKeep identifiers intactContext selectionFit the budgetGrounded answerClaims + provenanceRetrieval evaluationRecall and usefulness
  1. Retrieve a bounded candidate set with text and stable document identifiers.

  2. Improving the relevance of a retrieved candidate set. A reranker cannot recover a document the initial retrieval never returned.

  3. Reorder the candidates without losing the original source and permission metadata.

  4. Select sufficient evidence and avoid adding irrelevant passages.

  5. Generate the answer using the selected evidence.

  6. Measure whether relevant documents survive both retrieval and reranking.

    Result or stopping point
Cohere Rerank

Improving the relevance of a retrieved candidate set. A reranker cannot recover a document the initial retrieval never returned.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • Improving the relevance of a retrieved candidate set.

A design decision to make

  • A reranker cannot recover a document the initial retrieval never returned.

Prerequisites and setup

  • A Cohere key and enabled rerank model. The service receives the displayed query and candidate texts.
Shell
python3 -m venv .venv
source .venv/bin/activate
pip install cohere
export COHERE_API_KEY="YOUR_KEY"
export COHERE_RERANK_MODEL="YOUR_ENABLED_RERANK_MODEL"

Try a small integration

rerank.py

Python · rerank.py
import os
import cohere

client = cohere.ClientV2(api_key=os.environ["COHERE_API_KEY"])
documents = ["Shipping takes about five days.","Returns are accepted within 30 days."]
result = client.rerank(model=os.environ["COHERE_RERANK_MODEL"],
    query="What is the return window?",documents=documents,top_n=1)
for hit in result.results:
    print({"index":hit.index,"text":documents[hit.index],"relevance":hit.relevance_score})

Run and check the result

Shell
python rerank.py
  • The reranker returns an index into the supplied candidate list, preserving the source mapping.
  • Rerank after access filtering. A reranker cannot recover relevant evidence that the first-stage retriever omitted.

Common failures

  • A successful parse job does not prove table/reading-order accuracy; compare output with the original page.
  • Enforce file-size, duration and memory limits. Treat extracted text as untrusted content rather than instructions.

Production decisions

  • Preserve document ID, version, page/section, access scope and parser/model configuration alongside each chunk or vector.
  • Evaluate extraction and retrieval separately. Test tables, scans, empty documents, duplicates, malformed input and source deletion.
  • Tune candidate count and truncation against latency/cost. Validate multilingual and structured-document behavior.

Keep exploring

Retrieval that can ask a better questionA context pipeline for a long-running agent

Explore the same layer

UnstructuredDoclingLlamaParseSentence Transformers

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.