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.

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 { cohere } from "@ai-sdk/cohere";
import { MDocument } from "@mastra/rag";
import { embedMany } from "ai";

const doc = MDocument.fromText("Your text content...");

const chunks = await doc.chunk();

const { embeddings } = await embedMany({
model: cohere.embedding("embed-english-v3.0"),
values: chunks.map((chunk) => chunk.text),
});





View source on GitHub