Document compressor that uses Mixedbread AI's rerank API.

This class utilizes Mixedbread AI's reranking model to reorder a set of documents based on their relevance to a given query. The reranked documents are then used for various applications like search results refinement.

const reranker = new MixedbreadAIReranker({ apiKey: 'your-api-key' });
const documents = [{ pageContent: "To bake bread you need flour" }, { pageContent: "To bake bread you need yeast" }];
const query = "What do you need to bake bread?";
const result = await reranker.compressDocuments(documents, query);
console.log(result);
const reranker = new MixedbreadAIReranker({
apiKey: 'your-api-key',
model: 'mixedbread-ai/mxbai-rerank-large-v1',
topK: 5,
rankFields: ["title", "content"],
returnInput: true,
maxRetries: 5
});
const documents = [{ title: "Bread Recipe", content: "To bake bread you need flour" }, { title: "Bread Recipe", content: "To bake bread you need yeast" }];
const query = "What do you need to bake bread?";
const result = await reranker.rerank(documents, query);
console.log(result);

Hierarchy (view full)

Constructors

  • Constructor for MixedbreadAIReranker.

    Parameters

    Returns MixedbreadAIReranker

    If the API key is not provided or found in the environment variables.

    const reranker = new MixedbreadAIReranker({
    apiKey: 'your-api-key',
    model: 'mixedbread-ai/mxbai-rerank-large-v1',
    maxRetries: 5
    });

Properties

maxRetries: number
requestParams: RerankingRequestWithoutInput

Methods

  • Compress documents using Mixedbread AI's reranking API.

    Parameters

    • documents: DocumentInterface[]

      A list of documents to compress.

    • query: string

      The query to use for compressing the documents.

    Returns Promise<DocumentInterface[]>

    A Promise that resolves to a list of compressed documents.

    const documents = [{ pageContent: "To bake bread you need flour" }, { pageContent: "To bake bread you need yeast" }];
    const query = "What do you need to bake bread?";
    const result = await reranker.compressDocuments(documents, query);
    console.log(result);
  • Reranks a list of documents based on their relevance to a query using the Mixedbread AI API. Returns an ordered list of documents sorted by their relevance to the provided query.

    Parameters

    • documents: string[] | DocumentInterface[] | Record<string, unknown>[]

      A list of documents as strings, DocumentInterfaces, or objects with a pageContent key.

    • query: string

      The query to use for reranking the documents.

    • Optionaloptions: RerankingRequestWithoutInput

      Optional parameters for reranking.

    Returns Promise<RankedDocument[]>

    A Promise that resolves to an ordered list of documents with relevance scores.

    const documents = ["To bake bread you need flour", "To bake bread you need yeast"];
    const query = "What do you need to bake bread?";
    const result = await reranker.rerank(documents, query);
    console.log(result);
""