Creates a new HerokuMiaEmbeddings instance.
Optional
fields: HerokuMiaEmbeddingsFieldsOptional configuration options for the Heroku embeddings model
Protected
modelProtected
Optional
apiProtected
Optional
apiProtected
maxProtected
Optional
timeoutProtected
additionalGet the model name for identification.
The string "HerokuMiaEmbeddings"
Get additional parameters for serialization.
true to indicate this class is serializable
Private
invocationInternal
Get the parameters used to invoke the embeddings model.
This method combines constructor parameters with runtime options to create the final request parameters for the Heroku Embeddings API.
Optional
options: HerokuMiaEmbeddingsCallOptionsOptional runtime parameters that override constructor defaults
Combined parameters for the embeddings API request (excluding input)
Private
validateInternal
Validates input constraints for Heroku embeddings API.
The Heroku embeddings API has specific limitations that this method enforces:
Array of strings to validate
Private
makeInternal
Makes a request to the Heroku embeddings API with retry logic.
This method handles the actual HTTP request to the Heroku API, including:
The complete request payload for the embeddings API
Promise resolving to the embeddings API response
Embeds a single text query.
This method is optimized for embedding search queries and single pieces of text. It automatically sets the input_type to "search_query" unless overridden in options.
The text to embed
Optional
options: HerokuMiaEmbeddingsCallOptionsOptional call-time parameters to customize the embedding request
Promise resolving to an array of numbers representing the embedding vector
const embeddings = new HerokuMiaEmbeddings({ model: "cohere-embed-multilingual" });
// Basic query embedding
const queryVector = await embeddings.embedQuery("machine learning algorithms");
console.log("Embedding dimensions:", queryVector.length);
// With custom options
const customQueryVector = await embeddings.embedQuery(
"natural language processing",
{
input_type: "classification",
encoding_format: "base64"
}
);
Embeds multiple documents.
This method is optimized for embedding multiple documents for indexing or similarity search. It automatically sets the input_type to "search_document" unless overridden in options. Input validation ensures compliance with API constraints before making any network calls.
Array of text documents to embed (max 96 documents, 2048 chars each)
Optional
options: HerokuMiaEmbeddingsCallOptionsOptional call-time parameters to customize the embedding request
Promise resolving to an array of embedding vectors, one per input document
const embeddings = new HerokuMiaEmbeddings({ model: "openai-text-embedding-3-large" });
const documents = [
"Heroku is a cloud platform for building and running applications.",
"LangChain is a framework for developing applications powered by language models.",
"Vector databases enable semantic search and similarity matching."
];
// Basic document embedding
const documentVectors = await embeddings.embedDocuments(documents);
console.log(`Generated ${documentVectors.length} embeddings`);
// With custom options for clustering
const clusteringVectors = await embeddings.embedDocuments(documents, {
input_type: "clustering",
embedding_type: "int8",
truncate: "START"
});
Private
_Internal
Internal method to embed documents.
This method performs the actual embedding work after validation has been completed in the public embedDocuments method. It constructs the API request and processes the response.
Array of validated text documents to embed
Optional
options: HerokuMiaEmbeddingsCallOptionsOptional call-time parameters
Promise resolving to an array of embedding vectors
HerokuMiaEmbeddings - Heroku Managed Inference Embeddings Integration
A LangChain-compatible embeddings class that interfaces with Heroku's Managed Inference API for generating text embeddings. This class provides access to various embedding models hosted on Heroku's infrastructure, supporting both single query embedding and batch document embedding operations with automatic retry logic and proper error handling.
The class supports different input types (search queries, documents, classification, clustering), encoding formats, and embedding types to match your specific use case requirements.
Example
Example
Example
See