Batch indexing
Create vectors for multiple documents before storing them in a vector database.
AI Tools · Function
Embeds multiple values with an embedding model. Large requests are automatically split into smaller chunks when the model imposes embedding-count or UTF-8 input-byte limits.
Call embedMany with an embedding model and an array of values. The SDK can divide oversized input into provider-supported batches, then returns embeddings corresponding to the supplied values.
embedMany({ model, values })| Name | Type | Description |
|---|---|---|
model | EmbeddingModel | The embedding model to use. |
values | Array<VALUE> | The values to embed; the type depends on the model. |
A promise resolving to an object containing the generated embeddings.
import { embedMany } from 'ai';
import { openai } from '@ai-sdk/openai';
const { embeddings } = await embedMany({
model: openai.textEmbeddingModel('text-embedding-3-small'),
values: ['sunny day at the beach', 'rainy afternoon in the city'],
});
console.log(embeddings.length);Embeds two text values with an OpenAI embedding model and logs the number of returned vectors.
Create vectors for multiple documents before storing them in a vector database.
Convert document chunks into vectors for retrieval-augmented generation.
Generate embeddings for a collection of text inputs in one operation.
embedEmbeddingModelembeddings