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 textsusage: 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 theEmbeddingModel ABC to bring your own model:
Performance considerations
- Batching:
embed_manyautomatically batches requests based on the provider’smax_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