
# Embed Text in Batch

When working with large datasets or multiple pieces of text, processing embeddings one at a time can be inefficient. Batch embedding allows you to convert multiple text inputs into embeddings simultaneously, significantly improving performance and reducing API calls. This is particularly useful when processing documents, chat messages, or any collection of text that needs to be vectorized.

This example shows how to embed multiple text inputs in a single operation using the AI SDK. For single text embedding, see our [Embed Text](/cookbook/node/embed-text) example, or for a practical application, check out our [RAG example](/cookbook/node/retrieval-augmented-generation) which demonstrates how batch embeddings can be used in a document retrieval system.

```ts
import { embedMany } from 'ai';
import 'dotenv/config';

async function main() {
  const { embeddings, usage } = await embedMany({
    model: 'openai/text-embedding-3-small',
    values: [
      'sunny day at the beach',
      'rainy afternoon in the city',
      'snowy night in the mountains',
    ],
  });

  console.log(embeddings);
  console.log(usage);
}

main().catch(console.error);
```


## Navigation

- [Generate Text](/v5/cookbook/node/generate-text)
- [Retrieval Augmented Generation](/v5/cookbook/node/retrieval-augmented-generation)
- [Knowledge Base Agent](/v5/cookbook/node/knowledge-base-agent)
- [Generate Text with Chat Prompt](/v5/cookbook/node/generate-text-with-chat-prompt)
- [Generate Text with Image Prompt](/v5/cookbook/node/generate-text-with-image-prompt)
- [Stream Text](/v5/cookbook/node/stream-text)
- [Stream Text with Chat Prompt](/v5/cookbook/node/stream-text-with-chat-prompt)
- [Stream Text with Image Prompt](/v5/cookbook/node/stream-text-with-image-prompt)
- [Stream Text with File Prompt](/v5/cookbook/node/stream-text-with-file-prompt)
- [Generate Object with a Reasoning Model](/v5/cookbook/node/generate-object-reasoning)
- [Generate Object](/v5/cookbook/node/generate-object)
- [Stream Object](/v5/cookbook/node/stream-object)
- [Stream Object with Image Prompt](/v5/cookbook/node/stream-object-with-image-prompt)
- [Record Token Usage After Streaming Object](/v5/cookbook/node/stream-object-record-token-usage)
- [Record Final Object after Streaming Object](/v5/cookbook/node/stream-object-record-final-object)
- [Call Tools](/v5/cookbook/node/call-tools)
- [Call Tools with Image Prompt](/v5/cookbook/node/call-tools-with-image-prompt)
- [Call Tools in Multiple Steps](/v5/cookbook/node/call-tools-multiple-steps)
- [Model Context Protocol (MCP) Tools](/v5/cookbook/node/mcp-tools)
- [Manual Agent Loop](/v5/cookbook/node/manual-agent-loop)
- [Web Search Agent](/v5/cookbook/node/web-search-agent)
- [Model Context Protocol (MCP) Elicitation](/v5/cookbook/node/mcp-elicitation)
- [Embed Text](/v5/cookbook/node/embed-text)
- [Embed Text in Batch](/v5/cookbook/node/embed-text-batch)
- [Intercepting Fetch Requests](/v5/cookbook/node/intercept-fetch-requests)
- [Local Caching Middleware](/v5/cookbook/node/local-caching-middleware)


[Full Sitemap](/sitemap.md)
