Skip to main content

Mixedbread AI 重新排序

¥Mixedbread AI reranking

概述

¥Overview

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

¥This guide will help you integrate and use the 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

要开始使用,请安装 @langchain/mixedbread-ai 包:

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

npm install @langchain/mixedbread-ai

身份验证

¥Authentication

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

¥Obtain your API key by signing up at 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

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

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

  1. 导入类:首先,从包中导入 MixedbreadAIReranker 类。

    ¥Import the Class: First, import the MixedbreadAIReranker class from the package.

import { MixedbreadAIReranker } from "@langchain/mixedbread-ai";
  1. 实例化类:使用你的 API 密钥创建 MixedbreadAIReranker 实例。

    ¥Instantiate the Class: Create an instance of MixedbreadAIReranker with your API key.

const reranker = new MixedbreadAIReranker({ apiKey: "your-api-key" });
  1. 重新排序文档:使用 rerankDocuments 方法根据查询对文档进行重新排序。

    ¥Rerank Documents: Use the rerankDocuments method to reorder documents based on a query.

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

更多信息,请访问 重新排序 API 文档

¥For more information, refer to the Reranking API documentation.