Samples
Rerank search results
Improve search relevance by reordering results:Limit results with top_n
Return only the most relevant documents:Use in a search pipeline
Combine vector search with reranking:Arguments
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
model | TEXT | - | ✔ | The Cohere reranking model (e.g., rerank-english-v3.0) |
query | TEXT | - | ✔ | The search query |
documents | TEXT[] | - | ✔ | Array of documents to rerank |
api_key | TEXT | NULL | ✖ | Cohere API key. If not provided, uses configured secret |
api_key_name | TEXT | NULL | ✖ | Name of the secret containing the API key |
top_n | INT | NULL | ✖ | Return only the top N most relevant documents |
max_tokens_per_doc | INT | NULL | ✖ | Maximum tokens per document (for truncation) |
verbose | BOOLEAN | FALSE | ✖ | Enable verbose logging for debugging |
Returns
TABLE: A table with the following columns:
| Column | Type | Description |
|---|---|---|
index | INT | Original index of the document in the input array (0-based) |
document | TEXT | The document text |
relevance_score | FLOAT8 | Relevance score (0.0 to 1.0, higher is more relevant) |
Related functions
cohere_rerank(): full API response with additional metadatacohere_embed(): generate embeddings for vector search