Skip to main content

Overview

embed_many is the primary embedding function for processing multiple text values efficiently. It provides automatic batching respecting the provider’s max_batch_size limit, retry logic with exponential back-off, and unified return objects.

Basic usage

embed_many.py

Parameters

Return value

EmbedManyResult exposes:
  • embeddings: List of embedding vectors (list of lists of floats)
  • values: The original input texts
  • usage: Token usage statistics (if available)
  • provider_metadata: Provider-specific metadata

Examples

Basic batch embedding

With custom retry settings

Large batch processing

Error handling

With custom parameters

Custom providers

Implement the EmbeddingModel ABC to bring your own model:

Performance considerations

  • Batching: embed_many automatically batches requests based on the provider’s max_batch_size
  • Retries: Built-in exponential backoff retry logic for reliability
  • Memory: For very large datasets, consider processing in chunks
  • Rate limits: Respects provider rate limits automatically

Use cosine_similarity(vec_a, vec_b) for quick similarity checks between embeddings.