> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mixedbread AI integration

> Integrate with the Mixedbread AI embedding model using LangChain JavaScript.

The `MixedbreadAIEmbeddings` class uses the [Mixedbread AI](https://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:

<Tip>
  See [this section for general instructions on installing LangChain packages](/oss/javascript/langchain/install).
</Tip>

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/mixedbread-ai @langchain/core
```

## Initialization

First, sign up on the Mixedbread AI website and get your [API key from Mixedbread AI](https://mixedbread.ai/). You can then use this key to initialize the `MixedbreadAIEmbeddings` 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 of `MixedbreadAIEmbeddings`:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { MixedbreadAIEmbeddings } from "@langchain/mixedbread-ai";

const embeddings = new MixedbreadAIEmbeddings({
  apiKey: "YOUR_API_KEY",
  // Optionally specify model
  // model: "mixedbread-ai/mxbai-embed-large-v1",
});
```

If the `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 the `embedQuery` method:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const embedding = await embeddings.embedQuery(
  "Represent this sentence for searching relevant passages: Is baking fun?"
);
console.log(embedding);
```

### Embedding multiple documents

To generate embeddings for multiple documents, use the `embedDocuments` method. This method handles batching automatically based on the `batchSize` parameter:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const documents = ["Baking bread is fun", "I love baking"];

const embeddingsArray = await embeddings.embedDocuments(documents);
console.log(embeddingsArray);
```

## Customizing requests

You can customize the SDK by passing additional parameters.

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const customEmbeddings = new MixedbreadAIEmbeddings({
  apiKey: "YOUR_API_KEY",
  baseUrl: "...",
  maxRetries: 6,
});
```

## Error handling

If the API key is not provided and cannot be found in the environment variables, an error will be thrown:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
try {
  const embeddings = new MixedbreadAIEmbeddings();
} catch (error) {
  console.error(error);
}
```

## Related

* Embedding model [conceptual guide](/oss/javascript/integrations/embeddings)
* Embedding model [how-to guides](/oss/javascript/integrations/embeddings)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/embeddings/mixedbread_ai.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
