本页还没有译文
本页 15 段还没译成简体中文,下面显示的是英文原文。Mixedbread AI reranking integration
还没翻译译自英文(docs.langchain.com)本页 15 段都还没译
Overview
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
To get started, install the @langchain/mixedbread-ai package:
npm install @langchain/mixedbread-aiAuthentication
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
The MixedbreadAIReranker class provides access to the reranking API. Here’s how to use it:
- Import the Class: First, import the
MixedbreadAIRerankerclass from the package.
import { MixedbreadAIReranker } from "@langchain/mixedbread-ai";- Instantiate the Class: Create an instance of
MixedbreadAIRerankerwith your API key.
const reranker = new MixedbreadAIReranker({ apiKey: "your-api-key" });- Rerank Documents: Use the
rerankDocumentsmethod 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
For more information, refer to the Reranking API documentation.
AI 翻译查看英文原文