Mixedbread AI reranking
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-ai
Authenticationβ
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
MixedbreadAIReranker
class from the package.
import { MixedbreadAIReranker } from "@langchain/mixedbread-ai";
- Instantiate the Class: Create an instance of
MixedbreadAIReranker
with your API key.
const reranker = new MixedbreadAIReranker({ apiKey: "your-api-key" });
- 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β
For more information, refer to the Reranking API documentation.