Creates a new HerokuEmbeddingModel instance.
The Heroku embedding model identifier (e.g., "cohere-embed-multilingual")
Your Heroku AI API key for embeddings
The base URL for the Heroku embeddings API
ReadonlyspecificationThe embedding model must specify which embedding model interface version it implements. This will allow us to evolve the embedding model interface and retain backwards compatibility. The different implementation versions can be handled as a discriminated union on our side.
ReadonlyproviderName of the provider for logging purposes.
ReadonlymodelProvider-specific model ID for logging purposes.
ReadonlymaxLimit of how many embeddings can be generated in a single API call.
Use Infinity for models that do not have a limit.
ReadonlysupportsTrue if the model can handle multiple embedding calls in parallel.
Generate embeddings for the provided text values.
This method implements the AI SDK v5 EmbeddingModelV2 interface, providing seamless integration with the Vercel AI SDK's embedding functions.
Configuration object containing values to embed and optional settings
Array of text strings to generate embeddings for
OptionalabortSignal?: AbortSignalOptional AbortSignal for request cancellation
OptionalproviderOptions?: SharedV2ProviderOptionsOptionalheaders?: Record<string, string | undefined>Optional additional HTTP headers
Promise resolving to embedding results with usage information
Basic embedding generation:
const result = await model.doEmbed({
values: ["Hello, world!", "How are you?"]
});
console.log(result.embeddings.length); // 2
console.log(result.embeddings[0].length); // 1024 (embedding dimension)
console.log(result.usage?.tokens); // Token count used
With abort signal for cancellation:
const controller = new AbortController();
// Cancel after 5 seconds
setTimeout(() => controller.abort(), 5000);
try {
const result = await model.doEmbed({
values: ["Long text to embed..."],
abortSignal: controller.signal
});
} catch (error) {
if (error.name === 'AbortError') {
console.log('Request was cancelled');
}
}
Generate embedding for a single text string.
This is a convenience method that wraps doEmbed for single-text use cases.
The text string to generate an embedding for
Promise resolving to the embedding vector
Generate embeddings for multiple texts with automatic chunking.
This method automatically splits large batches into smaller chunks to respect API limits and processes them sequentially.
Array of text strings to generate embeddings for
Maximum number of texts to process in each API call
Promise resolving to all embedding vectors
Heroku embedding model implementation compatible with AI SDK v5.
This class provides embedding generation capabilities using Heroku's AI infrastructure, specifically designed to work seamlessly with the Vercel AI SDK's embedding functions.
HerokuEmbeddingModel
Example
Basic usage with AI SDK:
Example
Direct model usage: