embedMany
Embed many strings, batching automatically.
Embeds an array of strings, splitting into batches when the list exceeds what
the provider accepts in one request. Order is preserved, so the vector at index
i belongs to the value at index i.
Set maxBatchSize to stay under a provider's limit or to ease off a rate
limit.
let result = try await embedMany(
model: OpenAIEmbeddingModel("text-embedding-3-small"),
values: documents
)Signature
func embedMany(
model: any EmbeddingModel,
values: [String],
maxBatchSize: Int? = nil,
maxRetries: Int = 2
) async throws -> EmbedManyResultDefined in Sources/AI/Core/Embeddings.swift.
Parameters
| Parameter | Type | Default |
|---|---|---|
model | any EmbeddingModel | required |
values | [String] | required |
maxBatchSize | Int? | nil |
maxRetries | Int | 2 |
Returns
EmbedManyResult with embeddings in input order and combined usage.