Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Reranking with Cohere

When retrieving documents for RAG, initial vector similarity search may miss important semantic matches.

Cohere's reranking service helps improve result relevance by reordering documents using multiple scoring factors.

import {
rerankWithScorer as rerank,
CohereRelevanceScorer
} from "@mastra/rag";

const results = rerank({
results: searchResults,
query: "deployment configuration",
scorer: new CohereRelevanceScorer('rerank-v3.5'),
{
topK: 5,
weights: {
semantic: 0.4,
vector: 0.4,
position: 0.2,
},
},
);

On this page