embed
Embed a single string into a vector.
Turns one string into a vector for similarity search, clustering, or
classification. For more than one value use
embedMany, which batches.
let result = try await embed(
model: OpenAIEmbeddingModel("text-embedding-3-small"),
value: "swift concurrency"
)
print(result.embedding.count)Signature
func embed(
model: any EmbeddingModel,
value: String,
maxRetries: Int = 2
) async throws -> EmbedResultDefined in Sources/AI/Core/Embeddings.swift.
Parameters
| Parameter | Type | Default |
|---|---|---|
model | any EmbeddingModel | required |
value | String | required |
maxRetries | Int | 2 |
Returns
EmbedResult with the embedding vector and usage.