> ## 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 reranking integration

> Integrate with the Mixedbread AI reranking document compressor using LangChain JavaScript.

## Overview

This guide will help you integrate and use the [Mixedbread AI](https://mixedbread.ai/) reranking API. The reranking API allows you to reorder a list of documents based on a given query, improving the relevance of search results or any ranked list.

## Installation

To get started, install the `@langchain/mixedbread-ai` package:

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

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

## Authentication

Obtain your API key by signing up at [Mixedbread AI](https://mixedbread.ai/). You can then set the `MXBAI_API_KEY` environment variable to your Mixedbread AI API key or pass it directly as the `apiKey` option when constructing the class.

## Using reranking

The `MixedbreadAIReranker` class provides access to the reranking API. Here’s how to use it:

1. **Import the Class**: First, import the `MixedbreadAIReranker` class from the package.

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

2. **Instantiate the Class**: Create an instance of `MixedbreadAIReranker` with your API key.

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const reranker = new MixedbreadAIReranker({ apiKey: "your-api-key" });
```

3. **Rerank Documents**: Use the `rerankDocuments` method to reorder documents based on a query.

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const documents = [
  { pageContent: "To bake bread you need flour" },
  { pageContent: "To bake bread you need yeast" },
  { pageContent: "To eat bread you need nothing but good taste" },
];
const query = "What do you need to bake bread?";
const result = await reranker.compressDocuments(documents, query);
console.log(result);
```

## Additional resources

For more information, refer to the [Reranking API documentation](https://www.mixedbread.ai/docs/reranking/overview).

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to your agent of choice 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/document_compressors/mixedbread_ai.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
