RerankClient#

Overview#

RerankClient provides a unified Reranker base interface, enabling the implementation of custom Rerank schemes by aligning with this interface. It provides an implementation of FlagRerank for users to call and for reference.

Characteristics#

  • Unified Interface: All clients inherit from RerankClientBase, providing a consistent calling method.

  • Local mode: Supports using FlagRerankModel to connect to locally deployed Rerank models

Basic Usage#

import asyncio
from evofabric.core.clients import FlagRerankModel

# FlagRerankModel
rerank_model = FlagRerankModel(
    model="your-model",
    top_n=1,
    devices="cpu"
)

asyncio.run(rerank_model.rank(query="The tallest mountain in the world", texts=["The tallest mountain in the world is Mount Everest", "The deepest ocean is the Mariana Trench"]))

Use in RetrievalMem#

from evofabric.core.clients import OpenAIEmbedClient, FlagRerankModel
from evofabric.core.vectorstore import ChromaDB

embed_client = OpenAIEmbedClient(
    api_key="your-api-key",
    base_url="your-base-url",
    model="qwen3_0.6B:latest",
)

# Embed_client acts as the component for the vectorstore, invoked implicitly
vectorstore = ChromaDB(
    collection_name="demo_collection",
    persist_directory="./demo_collection",
    embedding=embed_client,
)

# Example of using FlagRerankModel
rerank_model = FlagRerankModel(
    model="your-model",
    top_n=1,
    devices="cpu"
)

retrieval_mem = RetrievalMem(
    vectorstore=vectorstore,
    reranker=rerank_model,
    use_rerank=True
)