/v1/rerank endpoint takes a query and a list of documents, then returns those documents sorted by relevance score. Reranking is typically used as a second-stage filter after an initial vector search retrieves a broad set of candidate documents. The reranker produces more precise relevance signals than embedding similarity alone, which improves the quality of context passed to a language model.
Authentication
Include your API key in every request:Send a rerank request
Provide aquery string, a documents array, and a model. TokModel returns the documents re-ordered from most to least relevant, each annotated with a relevance_score.
Example response
Theresults array is sorted by relevance_score in descending order. The index field refers to the position of the document in the original input array.
relevance_score to decide how many documents to forward to the language model. A common pattern is to keep only results above a threshold (e.g. 0.5) or to take the top-k regardless of score.
Key parameters
| Parameter | Type | Description |
|---|---|---|
model | string | The reranking model to use, e.g. cohere/rerank-english-v3.0. |
query | string | The search query to rank documents against. |
documents | array | List of strings (or objects with a text key) to rank. |
top_n | integer | Return only the top N results. Defaults to all documents. |
return_documents | boolean | Include document text in the response. Default true. |
Use reranking in a RAG pipeline
A typical RAG pipeline retrieves more documents than it can fit in the context window, then reranks them to keep only the most relevant ones.python
