Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

embedMany

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.

How it works

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.

Syntax

embedMany({ model, values })

Parameters

NameTypeDescription
modelEmbeddingModelThe embedding model to use.
valuesArray<VALUE>The values to embed; the type depends on the model.

Returns

A promise resolving to an object containing the generated embeddings.

Key points

  • embedMany generates an embedding for each supplied value in one operation.
  • The function handles provider batch-size limits by splitting large requests automatically.
  • Batching can be triggered by a model's maximum number of embeddings per request.
  • Batching can also be triggered by the maximum UTF-8 input size supported by the model.
  • Pass the embedding model through the model parameter.
  • Pass the items to vectorize through the values parameter.

Common mistakes

  • Large inputs may be split into multiple provider requests when model limits are exceeded.
  • The values must use the type expected by the selected embedding model.

Example: Embed multiple values

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.

When to use it

Batch indexing

Create vectors for multiple documents before storing them in a vector database.

RAG preparation

Convert document chunks into vectors for retrieval-augmented generation.

Bulk semantic encoding

Generate embeddings for a collection of text inputs in one operation.

  • embed
  • EmbeddingModel
  • embeddings

Source: embedMany. Checked 2026-10-15.