Embed Chunk Array
After chunking documents, you need to convert the text chunks into numerical vectors that can be used for similarity search. The embed
method transforms text chunks into embeddings using your chosen provider and model. This example shows how to generate embeddings for an array of text chunks.
import { MDocument, embed } from "@mastra/rag";
const doc = MDocument.fromText("Your text content...");
const chunks = await doc.chunk();
const { embeddings } = await embed(chunks, {
provider: "OPEN_AI",
model: "text-embedding-ada-002",
maxRetries: 3,
});
View Example on GitHub