ExamplesRAGRe-ranking results with Cohere

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 { rerank } from "@mastra/rag";
 
const results = rerank(
  searchResults,
  "deployment configuration",
  cohere("rerank-v3.5"),
  {
    topK: 5,
    weights: {
      semantic: 0.4,
      vector: 0.4,
      position: 0.2
    }
  }
);