FlashRank
rankify.models.flashrank
HF_PRE_DEFIND_MODELS = {'upr': {'t5-small': 'google/t5-small-lm-adapt', 't5-base': 'google/t5-base-lm-adapt', 't5-large': 'google/t5-large-lm-adapt', 't0-3b': 'bigscience/T0_3B', 't0-11b': 'bigscience/T0', 'gpt-neo-2.7b': 'EleutherAI/gpt-neo-2.7B', 'gpt-j-6b': 'EleutherAI/gpt-j-6b', 'gpt2': 'openai-community/gpt2', 'gpt2-medium': 'openai-community/gpt2-medium', 'gpt2-large': 'openai-community/gpt2-large', 'gpt2-xl': 'openai-community/gpt2-xl', 'flan-t5-xl': 'google/flan-t5-xl'}, 'rankgpt-api': {'gpt-3.5': 'gpt-3.5', 'gpt-4': 'gpt-4o', 'gpt-4-mini': 'gpt-4o-mini', 'llamav3.1-8b': 'llamav3.1-8b', 'llamav3.1-70b': 'llamav3.1-70b', 'claude-3-5': 'claude-3-5'}, 'rankgpt': {'llamav3.1-8b': 'meta-llama/Meta-Llama-3.1-8B-Instruct', 'llamav3.1-70b': 'meta-llama/Llama-3.1-70B-Instruct', 'Llama-3.2-1B': 'meta-llama/Llama-3.2-1B-Instruct', 'Llama-3.2-3B': 'meta-llama/Llama-3.2-3B-Instruct', 'Qwen2.5-7B': 'Qwen/Qwen2.5-7B', 'Mistral-7B-Instruct-v0.2': 'mistralai/Mistral-7B-Instruct-v0.2', 'Mistral-7B-Instruct-v0.3': 'mistralai/Mistral-7B-Instruct-v0.3'}, 'flashrank': {'ms-marco-TinyBERT-L-2-v2': 'ms-marco-TinyBERT-L-2-v2', 'ms-marco-MiniLM-L-12-v2': 'ms-marco-MiniLM-L-12-v2', 'ms-marco-MultiBERT-L-12': 'ms-marco-MultiBERT-L-12', 'rank-T5-flan': 'rank-T5-flan', 'ce-esci-MiniLM-L12-v2': 'ce-esci-MiniLM-L12-v2', 'rank_zephyr_7b_v1_full': 'rank_zephyr_7b_v1_full', 'miniReranker_arabic_v1': 'miniReranker_arabic_v1'}, 'flashrank-model-file': {'ms-marco-TinyBERT-L-2-v2': 'flashrank-TinyBERT-L-2-v2.onnx', 'ms-marco-MiniLM-L-12-v2': 'flashrank-MiniLM-L-12-v2_Q.onnx', 'ms-marco-MultiBERT-L-12': 'flashrank-MultiBERT-L12_Q.onnx', 'rank-T5-flan': 'flashrank-rankt5_Q.onnx', 'ce-esci-MiniLM-L12-v2': 'flashrank-ce-esci-MiniLM-L12-v2_Q.onnx', 'rank_zephyr_7b_v1_full': 'rank_zephyr_7b_v1_full.Q4_K_M.gguf', 'miniReranker_arabic_v1': 'miniReranker_arabic_v1.onnx'}, 'monot5': {'monot5-base-msmarco': 'castorini/monot5-base-msmarco', 'monot5-base-msmarco-10k': 'castorini/monot5-base-msmarco-10k', 'monot5-large-msmarco': 'castorini/monot5-large-msmarco', 'monot5-large-msmarco-10k': 'castorini/monot5-large-msmarco-10k', 'monot5-base-med-msmarco': 'castorini/monot5-base-med-msmarco', 'monot5-3b-med-msmarco': 'castorini/monot5-3b-med-msmarco', 'monot5-3b-msmarco-10k': 'castorini/monot5-3b-msmarco-10k', 'mt5-base-en-msmarco': 'unicamp-dl/mt5-base-en-msmarco', 'ptt5-base-pt-msmarco-10k-v2': 'unicamp-dl/ptt5-base-pt-msmarco-10k-v2', 'ptt5-base-pt-msmarco-100k-v2': 'unicamp-dl/ptt5-base-pt-msmarco-100k-v2', 'ptt5-base-en-pt-msmarco-100k-v2': 'unicamp-dl/ptt5-base-en-pt-msmarco-100k-v2', 'mt5-base-en-pt-msmarco-v2': 'unicamp-dl/mt5-base-en-pt-msmarco-v2', 'mt5-base-mmarco-v2': 'unicamp-dl/mt5-base-mmarco-v2', 'mt5-base-en-pt-msmarco-v1': 'unicamp-dl/mt5-base-en-pt-msmarco-v1', 'mt5-base-mmarco-v1': 'unicamp-dl/mt5-base-mmarco-v1', 'ptt5-base-pt-msmarco-10k-v1': 'unicamp-dl/ptt5-base-pt-msmarco-10k-v1', 'ptt5-base-pt-msmarco-100k-v1': 'unicamp-dl/ptt5-base-pt-msmarco-100k-v1', 'ptt5-base-en-pt-msmarco-10k-v1': 'unicamp-dl/ptt5-base-en-pt-msmarco-10k-v1', 'mt5-3B-mmarco-en-pt': 'unicamp-dl/mt5-3B-mmarco-en-pt', 'mt5-13b-mmarco-100k': 'unicamp-dl/mt5-13b-mmarco-100k', 'monoptt5-small': 'unicamp-dl/monoptt5-small', 'monoptt5-base': 'unicamp-dl/monoptt5-base', 'monoptt5-large': 'unicamp-dl/monoptt5-large', 'monoptt5-3b': 'unicamp-dl/monoptt5-3b'}, 'rankt5': {'rankt5-base': 'Soyoung97/RankT5-base', 'rankt5-large': 'Soyoung97/RankT5-large', 'rankt5-3b': 'Soyoung97/RankT5-3b'}, 'listt5': {'listt5-base': 'Soyoung97/ListT5-base', 'listt5-3b': 'Soyoung97/ListT5-3b'}, 'inranker': {'inranker-small': 'unicamp-dl/InRanker-small', 'inranker-base': 'unicamp-dl/InRanker-base', 'inranker-3b': 'unicamp-dl/InRanker-3B'}, 'apiranker': {'cohere': 'cohere', 'jina': 'jina', 'voyage': 'voyage', 'mixedbread.ai': 'mixedbread.ai'}, 'transformer_ranker': {'mxbai-rerank-xsmall': 'mixedbread-ai/mxbai-rerank-xsmall-v1', 'mxbai-rerank-base': 'mixedbread-ai/mxbai-rerank-base-v1', 'mxbai-rerank-large': 'mixedbread-ai/mxbai-rerank-large-v1', 'bge-reranker-base': 'BAAI/bge-reranker-base', 'bge-reranker-large': 'BAAI/bge-reranker-large', 'bge-reranker-v2-m3': 'BAAI/bge-reranker-v2-m3', 'bce-reranker-base': 'maidalun1020/bce-reranker-base_v1', 'jina-reranker-tiny': 'jinaai/jina-reranker-v1-tiny-en', 'jina-reranker-turbo': 'jinaai/jina-reranker-v1-turbo-en', 'jina-reranker-base-multilingual': 'jinaai/jina-reranker-v2-base-multilingual', 'gte-multilingual-reranker-base': 'Alibaba-NLP/gte-multilingual-reranker-base', 'camembert-base-mmarcoFR': 'antoinelouis/crossencoder-camembert-base-mmarcoFR', 'camembert-large-mmarcoFR': 'antoinelouis/crossencoder-camembert-large-mmarcoFR', 'camemberta-base-mmarcoFR': 'antoinelouis/crossencoder-camemberta-base-mmarcoFR', 'distilcamembert-mmarcoFR': 'antoinelouis/crossencoder-distilcamembert-mmarcoFR', 'cross-encoder-mmarco-mMiniLMv2-L12-H384-v1': 'corrius/cross-encoder-mmarco-mMiniLMv2-L12-H384-v1', 'nli-deberta-v3-large': 'cross-encoder/nli-deberta-v3-large', 'ms-marco-MiniLM-L-12-v2': 'cross-encoder/ms-marco-MiniLM-L-12-v2', 'ms-marco-MiniLM-L-6-v2': 'cross-encoder/ms-marco-MiniLM-L-6-v2', 'ms-marco-MiniLM-L-4-v2': 'cross-encoder/ms-marco-MiniLM-L-4-v2', 'ms-marco-MiniLM-L-2-v2': 'cross-encoder/ms-marco-MiniLM-L-2-v2', 'ms-marco-TinyBERT-L-2-v2': 'cross-encoder/ms-marco-TinyBERT-L-2-v2', 'ms-marco-electra-base': 'cross-encoder/ms-marco-electra-base', 'ms-marco-TinyBERT-L-6': 'cross-encoder/ms-marco-TinyBERT-L-6', 'ms-marco-TinyBERT-L-4': 'cross-encoder/ms-marco-TinyBERT-L-4', 'ms-marco-TinyBERT-L-2': 'cross-encoder/ms-marco-TinyBERT-L-2', 'msmarco-MiniLM-L12-en-de-v1': 'cross-encoder/msmarco-MiniLM-L12-en-de-v1', 'msmarco-MiniLM-L6-en-de-v1': 'cross-encoder/msmarco-MiniLM-L6-en-de-v1'}, 'llm_layerwise_ranker': {'bge-multilingual-gemma2': 'BAAI/bge-multilingual-gemma2', 'bge-reranker-v2-gemma': 'BAAI/bge-reranker-v2-gemma', 'bge-reranker-v2-minicpm-layerwise': 'BAAI/bge-reranker-v2-minicpm-layerwise', 'bge-reranker-v2.5-gemma2-lightweight': 'BAAI/bge-reranker-v2.5-gemma2-lightweight'}, 'first_ranker': {'First-Model': 'rryisthebest/First_Model', 'Llama-3-8B': 'meta-llama/Meta-Llama-3-8B-Instruct'}, 'lit5dist': {'LiT5-Distill-base': 'castorini/LiT5-Distill-base', 'LiT5-Distill-large': 'castorini/LiT5-Distill-large', 'LiT5-Distill-xl': 'castorini/LiT5-Distill-xl', 'LiT5-Distill-base-v2': 'castorini/LiT5-Distill-base-v2', 'LiT5-Distill-large-v2': 'castorini/LiT5-Distill-large-v2', 'LiT5-Distill-xl-v2': 'castorini/LiT5-Distill-xl-v2'}, 'lit5score': {'LiT5-Score-base': 'castorini/LiT5-Score-base', 'LiT5-Score-large': 'castorini/LiT5-Score-large', 'LiT5-Score-xl': 'castorini/LiT5-Score-xl'}, 'vicuna_reranker': {'rank_vicuna_7b_v1': 'castorini/rank_vicuna_7b_v1', 'rank_vicuna_7b_v1_noda': 'castorini/rank_vicuna_7b_v1_noda', 'rank_vicuna_7b_v1_fp16': 'castorini/rank_vicuna_7b_v1_fp16', 'rank_vicuna_7b_v1_noda_fp16': 'castorini/rank_vicuna_7b_v1_noda_fp16'}, 'zephyr_reranker': {'rank_zephyr_7b_v1_full': 'castorini/rank_zephyr_7b_v1_full'}, 'blender_reranker': {'PairRM': 'llm-blender/PairRM'}, 'splade_reranker': {'splade-cocondenser': 'naver/splade-cocondenser-ensembledistil'}, 'sentence_transformer_reranker': {'all-MiniLM-L6-v2': 'all-MiniLM-L6-v2', 'gtr-t5-base': 'sentence-transformers/gtr-t5-base', 'gtr-t5-large': 'sentence-transformers/gtr-t5-large', 'gtr-t5-xl': 'sentence-transformers/gtr-t5-xl', 'gtr-t5-xxl': 'sentence-transformers/gtr-t5-xxl', 'sentence-t5-base': 'sentence-transformers/sentence-t5-base', 'sentence-t5-xl': 'sentence-transformers/sentence-t5-xl', 'sentence-t5-xxl': 'sentence-transformers/sentence-t5-xxl', 'sentence-t5-large': 'sentence-transformers/sentence-t5-large', 'distilbert-multilingual-nli-stsb-quora-ranking': 'sentence-transformers/distilbert-multilingual-nli-stsb-quora-ranking', 'msmarco-bert-co-condensor': 'sentence-transformers/msmarco-bert-co-condensor', 'msmarco-roberta-base-v2': 'sentence-transformers/msmarco-roberta-base-v2'}, 'colbert_ranker': {'colbertv2.0': 'colbert-ir/colbertv2.0', 'FranchColBERT': 'bclavie/FraColBERTv2', 'JapanColBERT': 'bclavie/JaColBERTv2', 'SpanishColBERT': 'AdrienB134/ColBERTv2.0-spanish-mmarcoES', 'jina-colbert-v1-en': 'jinaai/jina-colbert-v1-en', 'ArabicColBERT-250k': 'akhooli/arabic-colbertv2-250k-norm', 'ArabicColBERT-711k': 'akhooli/arabic-colbertv2-711k-norm', 'BengaliColBERT': 'turjo4nis/colbertv2.0-bn', 'mxbai-colbert-large-v1': 'mixedbread-ai/mxbai-colbert-large-v1'}, 'monobert': {'monobert-large': 'castorini/monobert-large-msmarco'}, 'llm2vec': {'Meta-Llama-31-8B': 'McGill-NLP/LLM2Vec-Meta-Llama-31-8B-Instruct-mntp', 'Meta-Llama-3-8B': 'McGill-NLP/LLM2Vec-Meta-Llama-3-8B-Instruct-mntp', 'Mistral-7B': 'McGill-NLP/LLM2Vec-Mistral-7B-Instruct-v2-mntp', 'Llama-2-7B': 'McGill-NLP/LLM2Vec-Llama-2-7b-chat-hf-mntp', 'Sheared-LLaMA': 'McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp'}, 'twolar': {'twolar-xl': 'Dundalia/TWOLAR-xl', 'twolar-large': 'Dundalia/TWOLAR-large'}, 'duot5': {'duot5-base-msmarco': 'castorini/duot5-base-msmarco', 'duot5-3b-msmarco': 'castorini/duot5-3b-msmarco', 'duot5-large-msmarco': 'castorini/duot5-large-msmarco-10k'}, 'rankllama': {'rankllama-v1-7b-lora-passage': 'castorini/rankllama-v1-7b-lora-passage'}, 'dear_reranker': {'dear-3b-reranker-ce-v1': 'abdoelsayed/dear-3b-reranker-ce-v1', 'dear-3b-reranker-ranknet-v1': 'abdoelsayed/dear-3b-reranker-ranknet-v1', 'dear-3b-reranker-ce-lora-v1': 'abdoelsayed/dear-3b-reranker-ce-lora-v1', 'dear-8b-reranker-ce-v1': 'abdoelsayed/dear-8b-reranker-ce-v1'}, 'echorank': {'flan-t5-large': 'google/flan-t5-large', 'flan-t5-xl': 'google/flan-t5-xl'}, 'incontext_reranker': {'llamav3.1-8b': 'meta-llama/Meta-Llama-3.1-8B-Instruct', 'llamav3.1-70b': 'meta-llama/Llama-3.1-70B-Instruct', 'Mistral-7B-Instruct-v0.2': 'mistralai/Mistral-7B-Instruct-v0.2'}, 'tart': {'tart-full-flan-t5-xl': 'facebook/tart-full-flan-t5-xl', 'tart-dual-flan-t5-xl': 'facebook/tart-dual-flan-t5-xl'}, 'prp': {'llamav3.1-8b': 'meta-llama/Meta-Llama-3.1-8B-Instruct', 'llamav3.1-70b': 'meta-llama/Llama-3.1-70B-Instruct', 'Llama-3.2-1B': 'meta-llama/Llama-3.2-1B-Instruct', 'Llama-3.2-3B': 'meta-llama/Llama-3.2-3B-Instruct', 'Mistral-7B-Instruct-v0.3': 'mistralai/Mistral-7B-Instruct-v0.3'}, 'prp-api': {'gpt-3.5': 'gpt-3.5-turbo', 'gpt-4': 'gpt-4o', 'gpt-4-mini': 'gpt-4o-mini', 'llamav3.1-8b': 'llamav3.1-8b', 'llamav3.1-70b': 'llamav3.1-70b'}, 'rankgemma': {'gemma-2-2b': 'google/gemma-2-2b-it', 'gemma-2-9b': 'google/gemma-2-9b-it', 'gemma-2-27b': 'google/gemma-2-27b-it'}, 'rankmistral': {'mistral-7b': 'mistralai/Mistral-7B-Instruct-v0.3', 'mistral-7b-v0.2': 'mistralai/Mistral-7B-Instruct-v0.2', 'mixtral-8x7b': 'mistralai/Mixtral-8x7B-Instruct-v0.1'}}
module-attribute
Document
Represents a document consisting of a question, answers, and contexts.
Attributes:
| Name | Type | Description |
|---|---|---|
question |
Question
|
The question associated with the document. |
answers |
Answer
|
The answers to the question. |
contexts |
list[Context]
|
A list of related contexts. |
reorder_contexts |
list[Context] or None
|
A reordered list of contexts based on relevance. |
Source code in rankify/dataset/dataset.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
__init__(question, answers, contexts=None, id=None)
Initializes a Document instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
Question
|
The question associated with the document. |
required |
answers
|
Answer
|
The answers to the question. |
required |
contexts
|
list[Context]
|
A list of contexts related to the question. |
None
|
Example
q = Question("What is the capital of France?")
a = Answer(["Paris"])
c1 = Context(score=0.9, has_answer=True, id=1, title="Paris", text="The capital of France is Paris.")
c2 = Context(score=0.5, has_answer=False, id=2, title="Berlin", text="Berlin is the capital of Germany.")
d = Document(question=q, answers=a, contexts=[c1, c2])
print(d)
Source code in rankify/dataset/dataset.py
from_dict(data, n_docs=100)
classmethod
Creates a Document instance from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the question, answers, and contexts. |
required |
n_docs
|
int
|
The number of contexts to include. Defaults to 100. |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
Document |
Document
|
A new Document instance. |
Example
data = {
"question": "What is the capital of France?",
"answers": ["Paris"],
"ctxs": [
{"score": 0.9, "has_answer": True, "id": 1, "title": "Paris", "text": "The capital of France is Paris."},
{"score": 0.5, "has_answer": False, "id": 2, "title": "Berlin", "text": "Berlin is the capital of Germany."}
]
}
d = Document.from_dict(data)
print(d.question)
Source code in rankify/dataset/dataset.py
to_dict()
Converts the document into a dictionary representation.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Optional[object]]
|
A dictionary containing the question, answers, and contexts. |
Source code in rankify/dataset/dataset.py
__str__()
Returns a string representation of the Document instance.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The formatted document information. |
Source code in rankify/dataset/dataset.py
BaseRanking
Bases: ABC
An abstract base class for implementing different ranking models.
This class defines the interface for all ranking models, ensuring that all subclasses implement the required methods.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
str
|
The name of the ranking method. |
model_name |
str
|
The name of the model being used for ranking. |
api_key |
str
|
An optional API key for accessing remote models or services. |
Source code in rankify/models/base.py
__init__(method=None, model_name=None, api_key=None, **kwargs)
abstractmethod
Initializes the base ranking model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The name of the ranking method. Defaults to None. |
None
|
model_name
|
str
|
The name of the model being used for ranking. Defaults to None. |
None
|
api_key
|
str
|
An optional API key for accessing remote models or services. Defaults to None. |
None
|
Example
Source code in rankify/models/base.py
rank(documents)
abstractmethod
Abstract method to rank a list of documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
list[Document]
|
A list of Document instances that need to be ranked. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Example
Source code in rankify/models/base.py
FlashRanker
Bases: BaseRanking
Implements FlashRank, a fast and efficient reranking model supporting pairwise cross-encoding (ONNX) and listwise ranking with LLMs (GGUF models).
FlashRank efficiently reranks passages for a given query using either: - ONNX-based pairwise reranking (cross-encoder) for fast inference. - LLM-based listwise reranking using RankGPT.
This method is optimized for speed and accuracy while maintaining scalability.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
str
|
The reranking method name. |
model_name |
str
|
The name of the model used for reranking. |
api_key |
str
|
API key for accessing remote models (if applicable). |
cache_dir |
Path
|
Directory where models are cached. |
model_dir |
Path
|
Directory containing the specific model. |
session |
InferenceSession
|
The ONNX runtime session for inference (used for pairwise reranking). |
tokenizer |
Tokenizer
|
The tokenizer for text processing. |
llm_model |
Llama
|
If using an LLM-based reranker, this holds the model instance. |
References
- Damodaran, P. (2023). FlashRank, Lightest and Fastest 2nd Stage Reranker for search pipelines.
Paper
Examples:
from rankify.dataset.dataset import Document, Question, Answer, Context
from rankify.models.reranking import Reranking
question = Question("What is the capital of France?")
answers = Answer(["Paris is the capital of France."])
contexts = [
Context(text="Berlin is the capital of Germany.", id=0),
Context(text="Paris is the capital of France.", id=1),
Context(text="Madrid is the capital of Spain.", id=2),
]
document = Document(question=question, answers=answers, contexts=contexts)
# Initialize Reranking with FlashRanker
model = Reranking(method="flashrank", model_name="ms-marco-TinyBERT-L-2-v2")
model.rank([document])
# Print reordered contexts
print("Reordered Contexts:")
for context in document.reorder_contexts:
print(context.text)
Notes
- FlashRank supports ONNX models for cross-encoder-based reranking.
- LLM-based reranking is supported using GGUF models.
- Integrated into the
Rerankingclass, so useRerankinginstead ofFlashRankerdirectly.
Source code in rankify/models/flashrank.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
__init__(method=None, model_name=None, api_key=None, **kwargs)
Initializes the FlashRanker model for reranking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The reranking method name. |
None
|
model_name
|
str
|
The name of the reranking model to be used. |
None
|
model_dir
|
str
|
Path to a custom model directory if the user provides their own model. |
required |
api_key
|
str
|
API key for remote access (if applicable). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid model name is provided or model files are missing. |
Source code in rankify/models/flashrank.py
rank(documents)
Reranks a list of documents using FlashRank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
A list of Document instances to rerank. |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List[Document]: Documents with updated |