Skip to content

Conversation

@adityaiiitmk
Copy link

This PR introduces the MixedbreadAICrossEncoder, a new cross-encoder integration that leverages the mixedbread-ai/mxbai-rerank-base-v2 model for reranking documents.
It provides a standardized interface for computing similarity scores between queries and documents, with optional score normalization.

Key Changes

  • Added new class: MixedbreadAICrossEncoder

    • Inherits from BaseCrossEncoder.
    • Supports configurable model_name, model_kwargs, and normalize_scores.
    • Provides score() method to compute relevance scores for query-document pairs.
    • Includes normalization utility for scaling scores to [0, 1].
  • Handles ImportError with a clear message and installation instruction for mxbai-rerank.

  • Default model: mixedbread-ai/mxbai-rerank-base-v2.

Example Usage

from langchain_community.cross_encoders.mixedbreadai import MixedbreadAICrossEncoder

model_name = "mixedbread-ai/mxbai-rerank-base-v2"
model_kwargs = {'top_k': 10}
mb = MixedbreadAICrossEncoder(
    model_name=model_name,
    model_kwargs=model_kwargs
)

text_pairs = [
    ("What is climate change?", "Climate change leads to droughts and floods."),
    ("What is climate change?", "It refers to shifts in weather patterns.")
]
scores = mb.score(text_pairs)
print(scores)

Why This Change?

  • Provides a seamless integration of Mixedbread’s reranker into the LangChain ecosystem.
  • Enables more accurate document reranking in retrieval and search pipelines.
  • Enhances flexibility with support for top_k, custom kwargs, and optional score normalization.

Dependencies

adityaiiitmk and others added 6 commits August 29, 2025 09:43
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
…edbreadai.py

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants