Class Introduction
Function
Re-ranks BM25 and dense vector hybrid retrieval results. It inherits the abstract class Reranker.
Prototype
from mx_rag.reranker.local import MixRetrieveReranker MixRetrieveReranker(k, baseline, amplitude, slope, midpoint)
Parameters
Parameter |
Data Type |
Required/Optional |
Description |
|---|---|---|---|
k |
Integer |
Optional |
The most relevant k results after re-ranking. The value range is [1, 10000]. The default value is 100. |
baseline |
Float |
Optional |
Basic value of the weight calculation formula. The value range is [0.0, 1.0]. The default value is 0.4. |
amplitude |
Float |
Optional |
Amplitude of the weight calculation formula. The value range is [0.0, 1.0]. The default value is 0.3. |
slope |
Float |
Optional |
Transition steepness. The value is greater than 0. The default value is 1. |
midpoint |
Float |
Optional |
Query length when the function value reaches the middle point between the basic value and the maximum value. The value is greater than 0. The default value is 6. |
Note: The weight calculation formula is as follows. Ensure that the calculation result is in the range of [0, 1].

Return Value
MixRetrieveReranker object.
Example
from langchain_core.documents import Document
from mx_rag.reranker.local import MixRetrieveReranker
doc_1 = Document(
page_content="document1",
metadata={
"score": 1.0,
"retrieval_type": "dense",
}
)
doc_2 = Document(
page_content="document2",
metadata={
"score": 2.0,
"retrieval_type": "sparse",
}
)
docs = [doc_1, doc_2]
query = "This is a question."
reranker = MixRetrieveReranker(k=100, baseline=0.4, amplitude=0.3, slope=1, midpoint=6)
res = reranker.rerank(query, docs)