← All sessions, cheat sheets & labs
Week 2 · Field guide · Reranking

Cohere Rerank

A cross-encoder rerank API: hand it your query plus candidate chunks and it reorders them by true relevance. The precision step after cheap retrieval.

rerankingcommercial APIprovider-agnostic

What it is

The precision pass over your candidates.

Cohere Rerank is a cross-encoder scoring API. Where retrieval compares a query and a chunk through their separate embeddings, a cross-encoder reads the query and each candidate together and scores true relevance, which is far more accurate but too expensive to run over a whole corpus. So you retrieve wide and cheap first, then rerank the shortlist. It runs on top of any vector database and any embedding model.

The one job

40 loose chunks into the 3-5 that answer.

Given a query and a pile of loosely-relevant candidates, return them reordered by how well each actually answers the query, so you can keep only the top few. It is the narrowing step that turns noisy recall into a clean context window.

Reach for it when

Skip it when

A minimal look

Query plus documents, ordered out.

// retrieve wide first, then rerank the shortlist for precision
const res = await fetch("https://api.cohere.com/v2/rerank", {
  method: "POST",
  headers: { Authorization: `Bearer ${apiKey}` },
  body: JSON.stringify({ model: "rerank-v3.5", query, documents, top_n: 5 }),
});
const { results } = await res.json();
// results are ordered by relevance: [{ index, relevance_score }, ...]
const top = results.map((r) => documents[r.index]);

The principle it teaches

Course principle

Retrieve wide, then narrow. Recall and precision are two separate steps: cheap embedding search casts a wide net for recall, and reranking is the narrowing that buys precision. That split is exactly Lab 2's rerank stage.

Where it fits your labs

This is a Week 2 tool. In Lab 2 you retrieve a wide candidate set from pgvector, then rerank it down to the handful of chunks that actually answer the query before they reach the model.

Use in
Lab 2 (hybrid RAG), as the rerank step after retrieval.
week 2
Pairs with
Any vector database, since rerank runs on top of its results. Alternatives: bge-reranker and Voyage rerank.