Skip to main content

Class: MixedbreadAIReranker

Node postprocessor that uses MixedbreadAI's rerank API.

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

Examples

const reranker = new MixedbreadAIReranker({ apiKey: 'your-api-key' });
const nodes = [{ node: new BaseNode('To bake bread you need flour') }, { node: new BaseNode('To bake bread you need yeast') }];
const query = "What do you need to bake bread?";
const result = await reranker.postprocessNodes(nodes, 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);

Implements

Constructors

new MixedbreadAIReranker()

new MixedbreadAIReranker(params): MixedbreadAIReranker

Constructor for MixedbreadRerank.

Parameters

params: Partial<MixedbreadAIRerankerParams>

An optional object with properties to configure the instance.

Returns

MixedbreadAIReranker

Throws

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

Defined in

packages/llamaindex/src/postprocessors/rerankers/MixedbreadAIReranker.ts:89

Properties

requestOptions

requestOptions: RequestOptions

Defined in

packages/llamaindex/src/postprocessors/rerankers/MixedbreadAIReranker.ts:80


requestParams

requestParams: RerankingRequestWithoutInput

Defined in

packages/llamaindex/src/postprocessors/rerankers/MixedbreadAIReranker.ts:79

Methods

postprocessNodes()

postprocessNodes(nodes, query?): Promise<NodeWithScore<Metadata>[]>

Reranks the nodes using the mixedbread.ai API.

Parameters

nodes: NodeWithScore<Metadata>[]

Array of nodes with scores.

query?: MessageContent

Query string.

Returns

Promise<NodeWithScore<Metadata>[]>

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

Throws

If query is undefined.

Example

const nodes = [{ node: new BaseNode('To bake bread you need flour') }, { node: new BaseNode('To bake bread you need yeast') }];
const query = "What do you need to bake bread?";
const result = await reranker.postprocessNodes(nodes, query);
console.log(result);

Implementation of

BaseNodePostprocessor.postprocessNodes

Defined in

packages/llamaindex/src/postprocessors/rerankers/MixedbreadAIReranker.ts:142


rerank()

rerank(nodes, query, options?): Promise<RankedDocument[]>

Returns an ordered list of documents sorted by their relevance to the provided query.

Parameters

nodes: string[] | BaseNode<Metadata>[] | 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.

options?: RerankingRequestWithoutInput

Optional parameters for reranking.

Returns

Promise<RankedDocument[]>

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

Example

const nodes = ["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(nodes, query);
console.log(result);

Defined in

packages/llamaindex/src/postprocessors/rerankers/MixedbreadAIReranker.ts:187