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

# Mixedbread AI 重排序集成

> 使用 LangChain 集成 Mixedbread AI 文档排序器。

## 概述

本指南将帮助您集成和使用 [Mixedbread AI](https://mixedbread.ai/) 重新排序 API。重新排序 API 允许您根据给定的查询对文档列表进行排序，从而提高搜索结果或任何排序列表的相关性。

## 安装

开始使用前，请安装 `@langchain/mixedbread-ai` 包：

> [!TIP]
>
> 请参阅 [有关安装 LangChain 包的通用说明部分](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/install.md)。

```bash theme={null}
npm install @langchain/mixedbread-ai
```

## 认证

通过在 [Mixedbread AI](https://mixedbread.ai/) 注册来获取您的 API 密钥。然后，您可以将 `MXBAI_API_KEY` 环境变量设置为您的 Mixedbread AI API 密钥，或在构建类时直接将其作为 `apiKey` 选项传递。

## 使用重新排序

`MixedbreadAIReranker` 类提供了对重新排序 API 的访问。以下是使用方法：

1. **导入类**：首先，从包中导入 `MixedbreadAIReranker` 类。

```typescript theme={null}
import { MixedbreadAIReranker } from "@langchain/mixedbread-ai";
```

2. **实例化类**：使用您的 API 密钥创建 `MixedbreadAIReranker` 的实例。

```typescript theme={null}
const reranker = new MixedbreadAIReranker({ apiKey: "your-api-key" });
```

3. **重新排序文档**：使用 `rerankDocuments` 方法根据查询对文档进行排序。

```typescript theme={null}
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);
```

## 其他资源

有关更多信息，请参阅 [重新排序 API 文档](https://www.mixedbread.ai/docs/reranking/overview)。

***

> 官方原文：[src/oss/javascript/integrations/document\_compressors/mixedbread\_ai.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/javascript/integrations/document_compressors/mixedbread_ai.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.