ExamplesRAGEmbed Text with Cohere

Embed Text with Cohere

When working with alternative embedding providers, you need a way to generate vectors that match your chosen model’s specifications. The embed method supports multiple providers, allowing you to switch between different embedding services. This example shows how to generate embeddings using Cohere’s embedding model.

import { MDocument, embed } from "@mastra/rag";
 
const doc = MDocument.fromText("Your text content...");
 
const chunks = await doc.chunk();
 
const { embeddings } = await embed(chunks, {
  provider: "COHERE",
  model: "embed-english-v3.0",
  maxRetries: 3,
});





View Example on GitHub

MIT 2025 © Nextra.