MixedbreadAIEmbeddings class uses the Mixedbread AI API to generate text embeddings. This guide will walk you through setting up and using the MixedbreadAIEmbeddings class, helping you integrate it into your project effectively.
Installation
To install the@langchain/mixedbread-ai package, use the following command:
npm
Initialization
First, sign up on the Mixedbread AI website and get your API key from here. You can then use this key to initialize theMixedbreadAIEmbeddings class.
You can pass the API key directly to the constructor or set it as an environment variable (MXBAI_API_KEY).
Basic Usage
Here’s how to create an instance ofMixedbreadAIEmbeddings:
apiKey is not provided, it will be read from the MXBAI_API_KEY environment variable.
Generating Embeddings
Embedding a Single Query
To generate embeddings for a single text query, use theembedQuery method:
Embedding Multiple Documents
To generate embeddings for multiple documents, use theembedDocuments method. This method handles batching automatically based on the batchSize parameter:
Customizing Requests
You can customize the SDK by passing additional parameters.Error Handling
If the API key is not provided and cannot be found in the environment variables, an error will be thrown:Related
- Embedding model conceptual guide
- Embedding model how-to guides
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.