跳到主要内容

Mixedbread AI 重新排序

概述

本指南将帮助您集成和使用 Mixedbread AI 重新排序 API。重新排序 API 允许您根据给定的查询重新排列文档列表,从而提高搜索结果或任何排名列表的相关性。

安装

首先,安装 @langchain/mixedbread-ai

npm install @langchain/mixedbread-ai

身份验证

通过在 Mixedbread AI 注册获取您的 API 密钥。然后,您可以将 MXBAI_API_KEY 环境变量设置为您的 Mixedbread AI API 密钥,或者在构造类时直接将其作为 apiKey 选项传递。

使用重新排序

MixedbreadAIReranker 类提供对重新排序 API 的访问。以下是如何使用它

  1. 导入类:首先,从包中导入 MixedbreadAIReranker 类。
import { MixedbreadAIReranker } from "@langchain/mixedbread-ai";
  1. 实例化类:使用您的 API 密钥创建 MixedbreadAIReranker 的实例。
const reranker = new MixedbreadAIReranker({ apiKey: "your-api-key" });
  1. 重新排序文档:使用 rerankDocuments 方法根据查询重新排列文档。
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 文档


此页面对您有帮助吗?


您也可以留下详细的反馈 在 GitHub 上.