Retriever
rankify.retrievers.retriever
METHOD_MAP = {'bm25': BM25Retriever, 'dpr-multi': DenseRetriever, 'dpr-single': DenseRetriever, 'ance-multi': ANCERetriever, 'bpr-single': DenseRetriever, 'bge': BGERetriever, 'colbert': ColBERTRetriever, 'contriever': ContrieverRetriever, 'online': OnlineRetriever, 'hyde': HydeRetriever, 'diver-dense': DiverDenseRetriever, 'diver-bm25': DiverBM25Retriever, 'reasonir': ReasonIRRetriever, 'reason-embed': ReasonEmbedRetriever, 'bge-reasoner-embed': BgeReasonerRetriever, 'unicoil': UniCOILRetriever, 'unicoil-noexp': UniCOILRetriever, 'splade-v2': SpladeV2Retriever, 'openai-embedding': APIEmbeddingRetriever, 'cohere-embedding': APIEmbeddingRetriever, 'voyage-embedding': APIEmbeddingRetriever}
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
BaseRetriever
Bases: ABC
Abstract base class for all retrieval methods in the rankify framework.
This class defines the common interface that all retrievers must implement, ensuring consistency across different retrieval methods (BM25, DPR, etc.).
Source code in rankify/retrievers/base_retriever.py
__init__(n_docs=10, batch_size=36, threads=30, **kwargs)
Initialize the base retriever.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_docs
|
int
|
Number of documents to retrieve per query |
10
|
batch_size
|
int
|
Number of queries to process in a batch |
36
|
threads
|
int
|
Number of parallel threads for retrieval |
30
|
**kwargs
|
Additional parameters specific to each retriever |
{}
|
Source code in rankify/retrievers/base_retriever.py
retrieve(documents)
abstractmethod
Retrieve relevant contexts for the given documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
List of documents containing queries |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List[Document]: Documents updated with retrieved contexts |
Source code in rankify/retrievers/base_retriever.py
BM25Retriever
Bases: BaseRetriever
BM25 retriever implementation using Pyserini's LuceneSearcher.
Implements probabilistic ranking model BM25 for document retrieval.
Source code in rankify/retrievers/bm25_retriever.py
12 13 14 15 16 17 18 19 20 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 | |
retrieve(documents)
Retrieve relevant contexts using BM25.
Source code in rankify/retrievers/bm25_retriever.py
DenseRetriever
Bases: BaseRetriever
Dense retriever implementation supporting DPR, ANCE, and BPR models.
Uses FAISS indexes for efficient dense vector retrieval.
Source code in rankify/retrievers/dense_retriever.py
15 16 17 18 19 20 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 | |
retrieve(documents)
Retrieve relevant contexts using dense retrieval.
Source code in rankify/retrievers/dense_retriever.py
ANCERetriever
Bases: BaseRetriever
ANCE retriever implementation following the exact same pattern as DenseRetriever.
Supports both prebuilt and custom indices using FaissSearcher like DPR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_type
|
str
|
Type of prebuilt index ("wiki", "msmarco"). |
'wiki'
|
index_folder
|
str
|
Path to custom ANCE index folder. |
None
|
encoder_name
|
str
|
ANCE model name (auto-detected if not provided). |
None
|
method
|
str
|
Method variant ("ance", "ance-multi", "ance-msmarco"). |
'ance-multi'
|
n_docs
|
int
|
Number of documents to retrieve per query. |
required |
batch_size
|
int
|
Number of queries to process in a batch. |
required |
threads
|
int
|
Number of parallel threads for processing. |
required |
device
|
str
|
Device to use for encoding ("cpu" or "cuda"). |
'cuda'
|
Source code in rankify/retrievers/ance_retriever.py
18 19 20 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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
retrieve(documents)
Retrieve relevant contexts using ANCE (following DenseRetriever pattern exactly).
Source code in rankify/retrievers/ance_retriever.py
BGERetriever
Bases: BaseRetriever
BGE retriever implementation using precomputed embeddings and FAISS indexing.
Implements BGE (Beijing Academy of Artificial Intelligence General Embedding) model for dense passage retrieval with efficient FAISS-based search.
Source code in rankify/retrievers/bge_retriever.py
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 | |
retrieve(documents)
Retrieve relevant contexts using BGE.
Source code in rankify/retrievers/bge_retriever.py
ColBERTRetriever
Bases: BaseRetriever
ColBERT retriever with backward compatibility for prebuilt indices.
Supports two modes: 1. Prebuilt indices (wiki, msmarco) - Original format with passages.tsv 2. Custom indices - New format with collection.tsv + ID mappings
Source code in rankify/retrievers/colbert_retriever.py
18 19 20 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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
retrieve(documents)
Retrieve relevant contexts using ColBERT.
Source code in rankify/retrievers/colbert_retriever.py
ContrieverRetriever
Bases: BaseRetriever
FIXED Contriever retriever implementation with proper string ID handling.
Key fixes: - Handles both string and integer document IDs - Robust ID mapping and lookup - Better error handling for missing documents
Source code in rankify/retrievers/contriever_retriever.py
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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
retrieve(documents)
Retrieve relevant contexts using Contriever.
Source code in rankify/retrievers/contriever_retriever.py
OnlineRetriever
Source code in rankify/retrievers/online_retriever.py
HydeRetriever
Bases: BaseRetriever
Hypothetical Document Embedding (HyDE) Retriever implementation.
HyDE enhances document retrieval by generating hypothetical documents using an LLM and averaging their embeddings with the query embedding for improved search performance.
The retrieval process: 1. Generate hypothetical documents using an LLM based on the query 2. Encode both the original query and generated documents 3. Average the embeddings to obtain a refined query representation 4. Retrieve top documents using the averaged embedding
References
- Luyu Gao, Xueguang Ma, Jimmy Lin, and Jamie Callan. (2022): Precise Zero-Shot Dense Retrieval without Relevance Labels. https://arxiv.org/abs/2212.10496
Source code in rankify/retrievers/hyde_retriever.py
13 14 15 16 17 18 19 20 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 | |
retrieve(documents)
Retrieve contexts using HyDE-based query expansion.
The process involves: 1. Generating hypothetical documents using an LLM 2. Encoding both the original query and generated documents 3. Averaging the embeddings to obtain a refined query representation 4. Retrieving top documents using FAISS-based search
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
List of Document objects containing queries |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List of Document objects with retrieved contexts |
Source code in rankify/retrievers/hyde_retriever.py
DiverDenseRetriever
Bases: BaseRetriever
Comprehensive Diver-style retriever supporting: - SentenceTransformers (bge, sbert, nomic, instructor) - HF AutoModels (sf, qwen, e5, rader, contriever, m2) - GritLM (grit)
Source code in rankify/retrievers/diver_dense_retriever.py
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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
DiverBM25Retriever
Bases: BaseRetriever
Diver-style BM25 retriever using Gensim's LuceneBM25Model.
Source code in rankify/retrievers/diver_bm25_retriever.py
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 | |
ReasonIRRetriever
Bases: BaseRetriever
Rankify retriever wrapper for ReasonIR (uses model.encode with instructions) - caches doc embeddings in cache_dir/doc_emb/corpus_id/reasonir/0.npy - encodes queries - cosine similarity + top-k
Source code in rankify/retrievers/reasonir_retriever.py
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 | |
ReasonEmbedRetriever
Bases: BaseRetriever
A dense retriever that leverages ReasonEmbed models for reasoning-heavy retrieval tasks.
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
Identifier for the embedding backbone (e.g. 'qwen3-8b', 'llama-8b'). |
encode_batch_size |
int
|
Batch size for embedding generation. |
device |
str
|
Device to run the model on ('cuda' or 'cpu'). |
Source code in rankify/retrievers/reasonembed_retriever.py
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 | |
BgeReasonerRetriever
Bases: BaseRetriever
Retriever for the BGE-Reasoner-Embed-Qwen3-8B model. - caches doc embeddings in cache_dir/doc_emb/corpus_id/bge-reasoner-embed/0.npy - encodes queries - cosine similarity + top-k
Source code in rankify/retrievers/bge_reasoner_retriever.py
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 | |
UniCOILRetriever
Bases: BaseRetriever
UniCOIL learned sparse retriever using Pyserini's LuceneImpactSearcher.
UniCOIL (Unified COmpact Index with Learned sparse representation) learns term weights via a BERT model with a linear projection to a scalar weight per token position.
References
- Lin & Ma (2021): "A Few Brief Notes on DeepImpact, COIL, and a Conceptual Framework for Information Retrieval Techniques." https://arxiv.org/abs/2106.14807
- Model: castorini/unicoil-msmarco-passage
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_type
|
str
|
|
'msmarco'
|
index_folder
|
str
|
Path to a custom Lucene impact-index directory. |
None
|
corpus_path
|
str
|
JSONL file for passage text lookup
(fields: |
None
|
model_name
|
str
|
UniCOIL query encoder checkpoint. |
'castorini/unicoil-msmarco-passage'
|
device
|
str
|
|
'cpu'
|
Example
Source code in rankify/retrievers/unicoil_retriever.py
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 | |
retrieve(documents)
Retrieve passages for each document using the UniCOIL sparse index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
Documents whose |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List[Document]: Documents with populated |
Source code in rankify/retrievers/unicoil_retriever.py
SpladeV2Retriever
Bases: BaseRetriever
SPLADE-v2 learned sparse retriever using Pyserini's LuceneImpactSearcher.
SPLADE learns sparse, high-dimensional representations by predicting importance weights over the vocabulary for each token position, enabling efficient inverted-index retrieval with neural relevance signals.
References
- Formal et al. (2022): "From Distillation to Hard Negative Sampling" https://arxiv.org/abs/2205.04733
- Prebuilt index:
msmarco-v1-passage.splade-pp-ed
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_type
|
str
|
Prebuilt index alias. One of:
Pass |
'splade-pp-ed'
|
index_folder
|
str
|
Path to a custom Lucene impact-index dir. |
None
|
corpus_path
|
str
|
JSONL file for passage text lookup
(fields: |
None
|
model_name
|
str
|
SPLADE query encoder checkpoint. |
None
|
device
|
str
|
|
'cpu'
|
Example
Source code in rankify/retrievers/splade_v2_retriever.py
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 | |
retrieve(documents)
Retrieve passages for each document using the SPLADE sparse index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
Documents whose |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List[Document]: Documents with populated |
Source code in rankify/retrievers/splade_v2_retriever.py
APIEmbeddingRetriever
Bases: BaseRetriever
Dense retriever backed by an external embedding API and a FAISS index.
Supported providers:
'openai'– usesopenai.OpenAIclient'cohere'– usescohere.Client'voyage'– usesvoyageai.Client
The corpus is embedded once and cached as a .npy file under
cache_dir. Subsequent runs load the cache automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
One of |
required |
api_key
|
str
|
API key for the chosen provider. |
required |
corpus_path
|
str
|
Path to a JSONL corpus file. Each line must
contain |
required |
model_name
|
str
|
Embedding model name. Defaults are
|
None
|
cache_dir
|
str
|
Directory for cached embeddings. |
'./cache'
|
embed_batch_size
|
int
|
Override the default API batch size. |
None
|
Example
Source code in rankify/retrievers/api_embedding_retriever.py
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 | |
retrieve(documents)
Retrieve passages for each document by embedding the query and searching the FAISS index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
Documents with query in |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List[Document]: Documents with populated |
Source code in rankify/retrievers/api_embedding_retriever.py
Retriever
Unified retriever interface for the rankify framework.
Provides a simple interface to access different retrieval methods (BM25, DPR, ANCE, BPR) with consistent parameters.
Example
# Initialize with BM25
retriever = Retriever(method="bm25", n_docs=10, index_type="wiki")
# Initialize with DPR
retriever = Retriever(method="dpr-multi", n_docs=5, index_type="msmarco")
# Initialize with ANCE (UPDATED - now works with index_type)
retriever = Retriever(method="ance", n_docs=10, index_type="wiki")
# Initialize with ANCE-Multi (uses prebuilt Wikipedia indices)
retriever = Retriever(method="ance-multi", n_docs=10, index_type="wiki")
# Initialize with custom index folder (works for all methods)
retriever = Retriever(method="ance", n_docs=10, index_folder="/path/to/index")
# Retrieve documents
retrieved_documents = retriever.retrieve(documents)
Source code in rankify/retrievers/retriever.py
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 | |
__init__(method, n_docs=10, index_type='wiki', index_folder=None, encoder_name=None, **kwargs)
Initialize the retriever.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Retrieval method ('bm25', 'dpr-multi', 'dpr-single', 'ance', 'ance-multi', 'bpr-single', etc.) |
required |
n_docs
|
int
|
Number of documents to retrieve per query |
10
|
index_type
|
str
|
Index type ('wiki', 'msmarco') - ignored if index_folder is provided |
'wiki'
|
index_folder
|
str
|
Path to custom index folder (optional) |
None
|
encoder_name
|
str
|
Model name for encoding (method-specific) |
None
|
**kwargs
|
Additional parameters passed to the specific retriever |
{}
|
Source code in rankify/retrievers/retriever.py
retrieve(documents)
Retrieve relevant contexts for the given documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
List of documents containing queries |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List[Document]: Documents updated with retrieved contexts |