{"id":26799523,"url":"https://github.com/DataScienceUIBK/rankify","last_synced_at":"2025-03-29T20:02:17.255Z","repository":{"id":276692444,"uuid":"929986832","full_name":"DataScienceUIBK/Rankify","owner":"DataScienceUIBK","description":"🔥 Rankify: A Comprehensive Python Toolkit for Retrieval, Re-Ranking, and Retrieval-Augmented Generation 🔥. Our toolkit integrates 40 pre-retrieved benchmark datasets and supports 7+ retrieval techniques, 24+ state-of-the-art Reranking models, and multiple RAG methods.","archived":false,"fork":false,"pushed_at":"2025-03-27T18:18:11.000Z","size":5310,"stargazers_count":227,"open_issues_count":2,"forks_count":23,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-27T19:27:46.124Z","etag":null,"topics":["agent","ai","chatgpt","information-retrieval","llm","nlp","question-answering","rag","ranked-retrieval","reranking","retrieval","retrival-augmented-generation"],"latest_commit_sha":null,"homepage":"https://rankify.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DataScienceUIBK.png","metadata":{"files":{"readme":"README-PyPI.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-09T21:03:29.000Z","updated_at":"2025-03-27T18:18:15.000Z","dependencies_parsed_at":"2025-03-13T01:27:11.272Z","dependency_job_id":"ce41e42e-39e0-45b0-9e09-afc6a96647fa","html_url":"https://github.com/DataScienceUIBK/Rankify","commit_stats":null,"previous_names":["datascienceuibk/rankify"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataScienceUIBK%2FRankify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataScienceUIBK%2FRankify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataScienceUIBK%2FRankify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataScienceUIBK%2FRankify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DataScienceUIBK","download_url":"https://codeload.github.com/DataScienceUIBK/Rankify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246237428,"owners_count":20745348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","ai","chatgpt","information-retrieval","llm","nlp","question-answering","rag","ranked-retrieval","reranking","retrieval","retrival-augmented-generation"],"created_at":"2025-03-29T20:01:29.114Z","updated_at":"2025-03-29T20:02:17.242Z","avatar_url":"https://github.com/DataScienceUIBK.png","language":"Python","funding_links":[],"categories":["知识库 RAG"],"sub_categories":[],"readme":"\n\n\n### \u003cdiv align=\"center\"\u003e🔥 Rankify: A Comprehensive Python Toolkit for Retrieval, Re-Ranking, and Retrieval-Augmented Generation 🔥\u003cdiv\u003e\n\n\n\u003cdiv align=\"center\"\u003e\n\u003ca href=\"https://arxiv.org/abs/2502.02464\" target=\"_blank\"\u003e\u003cimg src=https://img.shields.io/badge/arXiv-b5212f.svg?logo=arxiv\u003e\u003c/a\u003e\n\u003ca href=\"https://huggingface.co/datasets/abdoelsayed/reranking-datasets\" target=\"_blank\"\u003e\u003cimg src=https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace%20Datasets-27b3b4.svg\u003e\u003c/a\u003e\n\u003ca href=\"https://huggingface.co/datasets/abdoelsayed/reranking-datasets-light\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace%20Datasets%20light-orange.svg\"\u003e\u003c/a\u003e\n\u003ca\u003e\u003cimg alt=\"Static Badge\" src=\"https://img.shields.io/badge/Python-3.10_3.11-blue\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/license/apache-2-0\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?label=License\u0026message=Apache-2.0\u0026color=red\"\u003e\u003c/a\u003e\n \u003ca href=\"https://pepy.tech/projects/rankify\"\u003e\u003cimg src=\"https://static.pepy.tech/badge/rankify\" alt=\"PyPI Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/DataScienceUIBK/rankify/releases\"\u003e\u003cimg alt=\"GitHub release\" src=\"https://img.shields.io/github/release/DataScienceUIBK/rankify.svg?label=Version\u0026color=orange\"\u003e\u003c/a\u003e    \n\u003c/div\u003e\n\n\n_A modular and efficient retrieval, reranking  and RAG  framework designed to work with state-of-the-art models for retrieval, ranking and rag tasks._\n\n_Rankify is a Python toolkit designed for unified retrieval, re-ranking, and retrieval-augmented generation (RAG) research. Our toolkit integrates 40 pre-retrieved benchmark datasets and supports 7 retrieval techniques, 24 state-of-the-art re-ranking models, and multiple RAG methods. Rankify provides a modular and extensible framework, enabling seamless experimentation and benchmarking across retrieval pipelines. Comprehensive documentation, open-source implementation, and pre-built evaluation tools make Rankify a powerful resource for researchers and practitioners in the field._\n\n\n\n## ✨ Features\n\n- **Comprehensive Retrieval \u0026 Reranking Framework**: Rankify unifies retrieval, re-ranking, and retrieval-augmented generation (RAG) into a single modular Python toolkit, enabling seamless experimentation and benchmarking.  \n\n- **Extensive Dataset Support**: Includes **40 benchmark datasets** with **pre-retrieved documents**, covering diverse domains such as **question answering, dialogue, entity linking, and fact verification**.  \n\n- **Diverse Retriever Integration**: Supports **7 retrieval techniques**, including **BM25, DPR, ANCE, BPR, ColBERT, BGE, and Contriever**, providing flexibility for various retrieval strategies.  \n\n- **Advanced Re-ranking Models**: Implements **24 primary re-ranking models** with **41 sub-methods**, covering **pointwise, pairwise, and listwise** re-ranking approaches for enhanced ranking performance.  \n\n- **Prebuilt Retrieval Indices**: Provides **precomputed Wikipedia and MS MARCO corpora** for multiple retrieval models, eliminating indexing overhead and accelerating experiments.  \n\n- **Seamless RAG Integration**: Bridges retrieval and generative models (e.g., **GPT, LLAMA, T5**), enabling retrieval-augmented generation with **zero-shot**, **Fusion-in-Decoder (FiD)**, and **in-context learning** strategies.  \n\n- **Modular \u0026 Extensible Design**: Easily integrates custom datasets, retrievers, re-rankers, and generation models using Rankify’s structured Python API.  \n\n- **Comprehensive Evaluation Suite**: Offers **automated performance evaluation** with **retrieval, ranking, and RAG metrics**, ensuring reproducible benchmarking.  \n\n- **User-Friendly Documentation**: Detailed **[📖 online documentation](http://rankify.readthedocs.io/)**, example notebooks, and tutorials for easy adoption.  \n\n## 🔍 Roadmap  \n\n**Rankify** is still under development, and this is our first release (**v0.1.0**). While it already supports a wide range of retrieval, re-ranking, and RAG techniques, we are actively enhancing its capabilities by adding more retrievers, rankers, datasets, and features.  \n\n### 🚀 Planned Improvements  \n\n- **Retrievers**  \n  - [x] Support for **BM25, DPR, ANCE, BPR, ColBERT, BGE, and Contriever**  \n  - [ ] Add missing retrievers: **Spar, MSS, MSS-DPR**  \n  - [ ] Enable **custom index loading** and support for user-defined retrieval corpora  \n\n- **Re-Rankers**  \n  - [x] 24 primary re-ranking models with 41 sub-methods  \n  - [ ] Expand the list by adding **more advanced ranking models** \n\n- **Datasets**  \n  - [x] 40 benchmark datasets for retrieval, ranking, and RAG  \n  - [ ] Add **more datasets**  \n  - [ ] Support for **custom dataset integration**  \n\n- **Retrieval-Augmented Generation (RAG)**  \n  - [x] Integration with **GPT, LLAMA, and T5**  \n  - [ ] Extend support for **more generative models**   \n\n- **Evaluation \u0026 Usability**  \n  - [x] Standard retrieval and ranking evaluation metrics (Top-K, EM, Recall, ...)\n  - [ ] Add **advanced evaluation metrics** (NDCG, MAP for retriever )  \n\n- **Pipeline Integration**  \n  - [ ] **Add a pipeline module** for streamlined retrieval, re-ranking, and RAG workflows \n\n## 🔧 Installation  \n\n#### Set up the virtual environment\nFirst, create and activate a conda environment with Python 3.10:\n\n```bash\nconda create -n rankify python=3.10\nconda activate rankify\n```\n#### Install PyTorch 2.5.1\nwe recommend installing Rankify with PyTorch 2.5.1 for Rankify. Refer to the [PyTorch installation page](https://pytorch.org/get-started/previous-versions/) for platform-specific installation commands. \n\nIf you have access to GPUs, it's recommended to install the CUDA version 12.4 or 12.6 of PyTorch, as many of the evaluation metrics are optimized for GPU use.\n\nTo install Pytorch 2.5.1 you can install it from the following cmd\n```bash\npip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124\n```\n\n\n#### Basic Installation\n\nTo install **Rankify**, simply use **pip** (requires Python 3.10+):  \n```base\npip install rankify\n```\n\nOr, to install from **GitHub** for the latest development version:  \n\n```bash\ngit clone https://github.com/DataScienceUIBK/rankify.git\ncd rankify\npip install -e .\n# For full functionality we recommend installing Rankify with all dependencies:\npip install -e \".[all]\"\n# Install dependencies for retrieval only (BM25, DPR, ANCE, etc.)\npip install -e \".[retriever]\"\n# Install dependencies for base re-ranking only (excluding vLLM)\npip install -e \".[base]\"\n# Install base re-ranking with vLLM support for `FirstModelReranker`, `LiT5ScoreReranker`, `LiT5DistillReranker`, `VicunaReranker`, and `ZephyrReranker'.\npip install -e \".[reranking]\"\n# Install dependencies for retrieval-augmented generation (RAG)\npip install -e \".[rag]\"\n```\nThis will install the base functionality required for retrieval, re-ranking, and retrieval-augmented generation (RAG).  \n\n\n#### Recommended Installation  \n\nFor full functionality, we **recommend installing Rankify with all dependencies**:\n```bash\npip install \"rankify[all]\"\n```\nThis ensures you have all necessary modules, including retrieval, re-ranking, and RAG support.\n\n#### Optional Dependencies\n\nIf you prefer to install only specific components, choose from the following:\n```bash\n# Install dependencies for retrieval only (BM25, DPR, ANCE, etc.)\npip install \"rankify[retriever]\"\n\n# Install dependencies for base re-ranking only (excluding vLLM)\npip install \"rankify[base]\"\n\n# Install base re-ranking with vLLM support for `FirstModelReranker`, `LiT5ScoreReranker`, `LiT5DistillReranker`, `VicunaReranker`, and `ZephyrReranker'.\npip install \"rankify[reranking]\"\n\n# Install dependencies for retrieval-augmented generation (RAG)\npip install \"rankify[rag]\"\n```\n#### Using ColBERT Retriever  \n\nIf you want to use **ColBERT Retriever**, follow these additional setup steps:\n```bash\n# Install GCC and required libraries\nconda install -c conda-forge gcc=9.4.0 gxx=9.4.0\nconda install -c conda-forge libstdcxx-ng\n```\n```bash\n# Export necessary environment variables\nexport LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH\nexport CC=gcc\nexport CXX=g++\nexport PATH=$CONDA_PREFIX/bin:$PATH\n\n# Clear cached torch extensions\nrm -rf ~/.cache/torch_extensions/*\n```\n\n---\n\n## 🚀 Quick Start\n\n### **1️⃣. Pre-retrieved Datasets**  \n\nWe provide **1,000 pre-retrieved documents per dataset**, which you can download from:  \n\n🔗 **[Hugging Face Dataset Repository](https://huggingface.co/datasets/abdoelsayed/reranking-datasets-light)**  \n\n#### **Dataset Format**  \n\nThe pre-retrieved documents are structured as follows:\n```json\n[\n    {\n        \"question\": \"...\",\n        \"answers\": [\"...\", \"...\", ...],\n        \"ctxs\": [\n            {\n                \"id\": \"...\",         // Passage ID from database TSV file\n                \"score\": \"...\",      // Retriever score\n                \"has_answer\": true|false  // Whether the passage contains the answer\n            }\n        ]\n    }\n]\n```\n\n\n#### **Access Datasets in Rankify**  \n\nYou can **easily download and use pre-retrieved datasets** through **Rankify**.  \n\n#### **List Available Datasets**  \n\nTo see all available datasets:\n```python\nfrom rankify.dataset.dataset import Dataset \n\n# Display available datasets\nDataset.avaiable_dataset()\n```\n\n**BM25 Retriever**\n```python\nfrom rankify.dataset.dataset import Dataset\n# Download BM25-retrieved documents for nq-dev\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"nq-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for 2wikimultihopqa-dev\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"2wikimultihopqa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for archivialqa-dev\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"archivialqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for archivialqa-test\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"archivialqa-test\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for chroniclingamericaqa-test\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"chroniclingamericaqa-test\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for chroniclingamericaqa-dev\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"chroniclingamericaqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for entityquestions-test\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"entityquestions-test\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for ambig_qa-dev\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"ambig_qa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for ambig_qa-train\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"ambig_qa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for arc-test\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"arc-test\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BM25-retrieved documents for arc-dev\ndataset = Dataset(retriever=\"bm25\", dataset_name=\"arc-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n```\n\n**BGE Retriever**\n```python\nfrom rankify.dataset.dataset import Dataset\n# Download BGE-retrieved documents for nq-dev\ndataset = Dataset(retriever=\"bge\", dataset_name=\"nq-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BGE-retrieved documents for 2wikimultihopqa-dev\ndataset = Dataset(retriever=\"bge\", dataset_name=\"2wikimultihopqa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download BGE-retrieved documents for archivialqa-dev\ndataset = Dataset(retriever=\"bge\", dataset_name=\"archivialqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n```\n\n**ColBERT Retriever**\n\n\n```python\nfrom rankify.dataset.dataset import Dataset\n# Download ColBERT-retrieved documents for nq-dev\ndataset = Dataset(retriever=\"colbert\", dataset_name=\"nq-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download ColBERT-retrieved documents for 2wikimultihopqa-dev\ndataset = Dataset(retriever=\"colbert\", dataset_name=\"2wikimultihopqa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download ColBERT-retrieved documents for archivialqa-dev\ndataset = Dataset(retriever=\"colbert\", dataset_name=\"archivialqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n```\n\n**MSS-DPR Retriever**\n\n\n```python\nfrom rankify.dataset.dataset import Dataset\n# Download MSS-DPR-retrieved documents for nq-dev\ndataset = Dataset(retriever=\"mss-dpr\", dataset_name=\"nq-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download MSS-DPR-retrieved documents for 2wikimultihopqa-dev\ndataset = Dataset(retriever=\"mss-dpr\", dataset_name=\"2wikimultihopqa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download MSS-DPR-retrieved documents for archivialqa-dev\ndataset = Dataset(retriever=\"mss-dpr\", dataset_name=\"archivialqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n```\n\n**MSS Retriever**\n\n```python\nfrom rankify.dataset.dataset import Dataset\n# Download MSS-retrieved documents for nq-dev\ndataset = Dataset(retriever=\"mss\", dataset_name=\"nq-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download MSS-retrieved documents for 2wikimultihopqa-dev\ndataset = Dataset(retriever=\"mss\", dataset_name=\"2wikimultihopqa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download MSS-retrieved documents for archivialqa-dev\ndataset = Dataset(retriever=\"mss\", dataset_name=\"archivialqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n```\n\n**Contriever Retriever**\n\n```python\nfrom rankify.dataset.dataset import Dataset\n# Download MSS-retrieved documents for nq-dev\ndataset = Dataset(retriever=\"contriever\", dataset_name=\"nq-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download MSS-retrieved documents for 2wikimultihopqa-dev\ndataset = Dataset(retriever=\"contriever\", dataset_name=\"2wikimultihopqa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download MSS-retrieved documents for archivialqa-dev\ndataset = Dataset(retriever=\"contriever\", dataset_name=\"archivialqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n```\n\n\n**ANCE Retriever**\n\n```python\nfrom rankify.dataset.dataset import Dataset\n# Download ANCE-retrieved documents for nq-dev\ndataset = Dataset(retriever=\"ance\", dataset_name=\"nq-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download ANCE-retrieved documents for 2wikimultihopqa-dev\ndataset = Dataset(retriever=\"ance\", dataset_name=\"2wikimultihopqa-train\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n# Download ANCE-retrieved documents for archivialqa-dev\ndataset = Dataset(retriever=\"ance\", dataset_name=\"archivialqa-dev\", n_docs=100)\ndocuments = dataset.download(force_download=False)\n```\n\n**Load Pre-retrieved Dataset from File**  \n\nIf you have already downloaded a dataset, you can load it directly:\n```python\nfrom rankify.dataset.dataset import Dataset\n\n# Load pre-downloaded BM25 dataset for WebQuestions\ndocuments = Dataset.load_dataset('./tests/out-datasets/bm25/web_questions/test.json', 100)\n```\nNow, you can integrate **retrieved documents** with **re-ranking** and **RAG** workflows! 🚀  \n\n---\n\n### 2️⃣. Running Retrieval\nTo perform retrieval using **Rankify**, you can choose from various retrieval methods such as **BM25, DPR, ANCE, Contriever, ColBERT, and BGE**.  \n\n**Example: Running Retrieval on Sample Queries**  \n```python\nfrom rankify.dataset.dataset import Document, Question, Answer, Context\nfrom rankify.retrievers.retriever import Retriever\n\n# Sample Documents\ndocuments = [\n    Document(question=Question(\"the cast of a good day to die hard?\"), answers=Answer([\n            \"Jai Courtney\",\n            \"Sebastian Koch\",\n            \"Radivoje Bukvić\",\n            \"Yuliya Snigir\",\n            \"Sergei Kolesnikov\",\n            \"Mary Elizabeth Winstead\",\n            \"Bruce Willis\"\n        ]), contexts=[]),\n    Document(question=Question(\"Who wrote Hamlet?\"), answers=Answer([\"Shakespeare\"]), contexts=[])\n]\n```\n\n```python\n# BM25 retrieval on Wikipedia\nbm25_retriever_wiki = Retriever(method=\"bm25\", n_docs=5, index_type=\"wiki\")\n\n# BM25 retrieval on MS MARCO\nbm25_retriever_msmacro = Retriever(method=\"bm25\", n_docs=5, index_type=\"msmarco\")\n\n\n# DPR (multi-encoder) retrieval on Wikipedia\ndpr_retriever_wiki = Retriever(method=\"dpr\", model=\"dpr-multi\", n_docs=5, index_type=\"wiki\")\n\n# DPR (multi-encoder) retrieval on MS MARCO\ndpr_retriever_msmacro = Retriever(method=\"dpr\", model=\"dpr-multi\", n_docs=5, index_type=\"msmarco\")\n\n# DPR (single-encoder) retrieval on Wikipedia\ndpr_retriever_wiki = Retriever(method=\"dpr\", model=\"dpr-single\", n_docs=5, index_type=\"wiki\")\n\n# DPR (single-encoder) retrieval on MS MARCO\ndpr_retriever_msmacro = Retriever(method=\"dpr\", model=\"dpr-single\", n_docs=5, index_type=\"msmarco\")\n\n# ANCE retrieval on Wikipedia\nance_retriever_wiki = Retriever(method=\"ance\", model=\"ance-multi\", n_docs=5, index_type=\"wiki\")\n\n# ANCE retrieval on MS MARCO\nance_retriever_msmacro = Retriever(method=\"ance\", model=\"ance-multi\", n_docs=5, index_type=\"msmarco\")\n\n\n# Contriever retrieval on Wikipedia\ncontriever_retriever_wiki = Retriever(method=\"contriever\", model=\"facebook/contriever-msmarco\", n_docs=5, index_type=\"wiki\")\n\n# Contriever retrieval on MS MARCO\ncontriever_retriever_msmacro = Retriever(method=\"contriever\", model=\"facebook/contriever-msmarco\", n_docs=5, index_type=\"msmarco\")\n\n\n# ColBERT retrieval on Wikipedia\ncolbert_retriever_wiki = Retriever(method=\"colbert\", model=\"colbert-ir/colbertv2.0\", n_docs=5, index_type=\"wiki\")\n\n# ColBERT retrieval on MS MARCO\ncolbert_retriever_msmacro = Retriever(method=\"colbert\", model=\"colbert-ir/colbertv2.0\", n_docs=5, index_type=\"msmarco\")\n\n\n# BGE retrieval on Wikipedia\nbge_retriever_wiki = Retriever(method=\"bge\", model=\"BAAI/bge-large-en-v1.5\", n_docs=5, index_type=\"wiki\")\n\n# BGE retrieval on MS MARCO\nbge_retriever_msmacro = Retriever(method=\"bge\", model=\"BAAI/bge-large-en-v1.5\", n_docs=5, index_type=\"msmarco\")\n```\n\n**Running Retrieval**\n\nAfter defining the retriever, you can retrieve documents using:\n```python\nretrieved_documents = bm25_retriever_wiki.retrieve(documents)\n\nfor i, doc in enumerate(retrieved_documents):\n    print(f\"\\nDocument {i+1}:\")\n    print(doc)\n```\n\n---\n## 3️⃣. Running Reranking\nRankify provides support for multiple reranking models. Below are examples of how to use each model.  \n\n** Example: Reranking a Document**  \n```python\nfrom rankify.dataset.dataset import Document, Question, Answer, Context\nfrom rankify.models.reranking import Reranking\n\n# Sample document setup\nquestion = Question(\"When did Thomas Edison invent the light bulb?\")\nanswers = Answer([\"1879\"])\ncontexts = [\n    Context(text=\"Lightning strike at Seoul National University\", id=1),\n    Context(text=\"Thomas Edison tried to invent a device for cars but failed\", id=2),\n    Context(text=\"Coffee is good for diet\", id=3),\n    Context(text=\"Thomas Edison invented the light bulb in 1879\", id=4),\n    Context(text=\"Thomas Edison worked with electricity\", id=5),\n]\ndocument = Document(question=question, answers=answers, contexts=contexts)\n\n# Initialize the reranker\nreranker = Reranking(method=\"monot5\", model_name=\"monot5-base-msmarco\")\n\n# Apply reranking\nreranker.rank([document])\n\n# Print reordered contexts\nfor context in document.reorder_contexts:\n    print(f\"  - {context.text}\")\n```\n\n\n**Examples of Using Different Reranking Models**  \n```python\n# UPR\nmodel = Reranking(method='upr', model_name='t5-base')\n\n# API-Based Rerankers\nmodel = Reranking(method='apiranker', model_name='voyage', api_key='your-api-key')\nmodel = Reranking(method='apiranker', model_name='jina', api_key='your-api-key')\nmodel = Reranking(method='apiranker', model_name='mixedbread.ai', api_key='your-api-key')\n\n# Blender Reranker\nmodel = Reranking(method='blender_reranker', model_name='PairRM')\n\n# ColBERT Reranker\nmodel = Reranking(method='colbert_ranker', model_name='Colbert')\n\n# EchoRank\nmodel = Reranking(method='echorank', model_name='flan-t5-large')\n\n# First Ranker\nmodel = Reranking(method='first_ranker', model_name='base')\n\n# FlashRank\nmodel = Reranking(method='flashrank', model_name='ms-marco-TinyBERT-L-2-v2')\n\n# InContext Reranker\nReranking(method='incontext_reranker', model_name='llamav3.1-8b')\n\n# InRanker\nmodel = Reranking(method='inranker', model_name='inranker-small')\n\n# ListT5\nmodel = Reranking(method='listt5', model_name='listt5-base')\n\n# LiT5 Distill\nmodel = Reranking(method='lit5distill', model_name='LiT5-Distill-base')\n\n# LiT5 Score\nmodel = Reranking(method='lit5score', model_name='LiT5-Distill-base')\n\n# LLM Layerwise Ranker\nmodel = Reranking(method='llm_layerwise_ranker', model_name='bge-multilingual-gemma2')\n\n# LLM2Vec\nmodel = Reranking(method='llm2vec', model_name='Meta-Llama-31-8B')\n\n# MonoBERT\nmodel = Reranking(method='monobert', model_name='monobert-large')\n\n# MonoT5\nReranking(method='monot5', model_name='monot5-base-msmarco')\n\n# RankGPT\nmodel = Reranking(method='rankgpt', model_name='llamav3.1-8b')\n\n# RankGPT API\nmodel = Reranking(method='rankgpt-api', model_name='gpt-3.5', api_key=\"gpt-api-key\")\nmodel = Reranking(method='rankgpt-api', model_name='gpt-4', api_key=\"gpt-api-key\")\nmodel = Reranking(method='rankgpt-api', model_name='llamav3.1-8b', api_key=\"together-api-key\")\nmodel = Reranking(method='rankgpt-api', model_name='claude-3-5', api_key=\"claude-api-key\")\n\n# RankT5\nmodel = Reranking(method='rankt5', model_name='rankt5-base')\n\n# Sentence Transformer Reranker\nmodel = Reranking(method='sentence_transformer_reranker', model_name='all-MiniLM-L6-v2')\nmodel = Reranking(method='sentence_transformer_reranker', model_name='gtr-t5-base')\nmodel = Reranking(method='sentence_transformer_reranker', model_name='sentence-t5-base')\nmodel = Reranking(method='sentence_transformer_reranker', model_name='distilbert-multilingual-nli-stsb-quora-ranking')\nmodel = Reranking(method='sentence_transformer_reranker', model_name='msmarco-bert-co-condensor')\n\n# SPLADE\nmodel = Reranking(method='splade', model_name='splade-cocondenser')\n\n# Transformer Ranker\nmodel = Reranking(method='transformer_ranker', model_name='mxbai-rerank-xsmall')\nmodel = Reranking(method='transformer_ranker', model_name='bge-reranker-base')\nmodel = Reranking(method='transformer_ranker', model_name='bce-reranker-base')\nmodel = Reranking(method='transformer_ranker', model_name='jina-reranker-tiny')\nmodel = Reranking(method='transformer_ranker', model_name='gte-multilingual-reranker-base')\nmodel = Reranking(method='transformer_ranker', model_name='nli-deberta-v3-large')\nmodel = Reranking(method='transformer_ranker', model_name='ms-marco-TinyBERT-L-6')\nmodel = Reranking(method='transformer_ranker', model_name='msmarco-MiniLM-L12-en-de-v1')\n\n# TwoLAR\nmodel = Reranking(method='twolar', model_name='twolar-xl')\n\n# Vicuna Reranker\nmodel = Reranking(method='vicuna_reranker', model_name='rank_vicuna_7b_v1')\n\n# Zephyr Reranker\nmodel = Reranking(method='zephyr_reranker', model_name='rank_zephyr_7b_v1_full')\n```\n---\n\n## 4️⃣. Using Generator Module\nRankify provides a **Generator Module** to facilitate **retrieval-augmented generation (RAG)** by integrating retrieved documents into generative models for producing answers. Below is an example of how to use different generator methods.  \n\n```python\nfrom rankify.dataset.dataset import Document, Question, Answer, Context\nfrom rankify.generator.generator import Generator\n\n# Define question and answer\nquestion = Question(\"What is the capital of France?\")\nanswers = Answer([\"Paris\"])\ncontexts = [\n    Context(id=1, title=\"France\", text=\"The capital of France is Paris.\", score=0.9),\n    Context(id=2, title=\"Germany\", text=\"Berlin is the capital of Germany.\", score=0.5)\n]\n\n# Construct document\ndoc = Document(question=question, answers=answers, contexts=contexts)\n\n# Initialize Generator (e.g., Meta Llama)\ngenerator = Generator(method=\"in-context-ralm\", model_name='meta-llama/Llama-3.1-8B')\n\n# Generate answer\ngenerated_answers = generator.generate([doc])\nprint(generated_answers)  # Output: [\"Paris\"]\n```\n\n---\n## 5️⃣ Evaluating with Metrics  \n\nRankify provides built-in **evaluation metrics** for **retrieval, re-ranking, and retrieval-augmented generation (RAG)**. These metrics help assess the quality of retrieved documents, the effectiveness of ranking models, and the accuracy of generated answers.  \n\n**Evaluating Generated Answers**  \n\nYou can evaluate the quality of **retrieval-augmented generation (RAG) results** by comparing generated answers with ground-truth answers.\n```python\nfrom rankify.metrics.metrics import Metrics\nfrom rankify.dataset.dataset import Dataset\n\n# Load dataset\ndataset = Dataset('bm25', 'nq-test', 100)\ndocuments = dataset.download(force_download=False)\n\n# Initialize Generator\ngenerator = Generator(method=\"in-context-ralm\", model_name='meta-llama/Llama-3.1-8B')\n\n# Generate answers\ngenerated_answers = generator.generate(documents)\n\n# Evaluate generated answers\nmetrics = Metrics(documents)\nprint(metrics.calculate_generation_metrics(generated_answers))\n```\n\n**Evaluating Retrieval Performance**  \n\n```python\n# Calculate retrieval metrics before reranking\nmetrics = Metrics(documents)\nbefore_ranking_metrics = metrics.calculate_retrieval_metrics(ks=[1, 5, 10, 20, 50, 100], use_reordered=False)\n\nprint(before_ranking_metrics)\n```\n\n**Evaluating Reranked Results**  \n```python\n# Calculate retrieval metrics after reranking\nafter_ranking_metrics = metrics.calculate_retrieval_metrics(ks=[1, 5, 10, 20, 50, 100], use_reordered=True)\nprint(after_ranking_metrics)\n```\n\n## 📜 Supported Models\n\n\n### **1️⃣ Retrievers**  \n- ✅ **BM25**\n- ✅ **DPR** \n- ✅ **ColBERT**   \n- ✅ **ANCE**\n- ✅ **BGE** \n- ✅ **Contriever** \n- ✅ **BPR** \n---\n\n### **2️⃣ Rerankers**  \n\n- ✅ **Cross-Encoders** \n- ✅ **RankGPT**\n- ✅ **RankGPT-API** \n- ✅ **MonoT5**\n- ✅ **MonoBert**\n- ✅ **RankT5** \n- ✅ **ListT5** \n- ✅ **LiT5Score**\n- ✅ **LiT5Dist**\n- ✅ **Vicuna Reranker**\n- ✅ **Zephyr Reranker**\n- ✅ **Sentence Transformer-based** \n- ✅ **FlashRank Models**  \n- ✅ **API-Based Rerankers**  \n- ✅ **ColBERT Reranker**\n- ✅ **LLM Layerwise Ranker** \n- ✅ **Splade Reranker**\n- ✅ **ColBERT Reranker**\n- ✅ **UPR Reranker**\n- ✅ **Inranker Reranker**\n- ✅ **Transformer Reranker**\n- ✅ **FIRST Reranker**\n- ✅ **Blender Reranker**\n- ✅ **LLM2VEC Reranker**\n- ✅ **ECHO Reranker**\n- ✅ **Incontext Reranker**\n---\n\n### **3️⃣ Generators**  \n- ✅ **Fusion-in-Decoder (FiD) with T5**\n- ✅ **In-Context Learning RLAM** \n---\n\n## 📖 Documentation\n\nFor full API documentation, visit the [Rankify Docs](http://rankify.readthedocs.io/).\n\n---\n\n## 💡 Contributing\n\n\nFollow these steps to get involved:\n\n1. **Fork this repository** to your GitHub account.\n\n2. **Create a new branch** for your feature or fix:\n\n   ```bash\n   git checkout -b feature/YourFeatureName\n   ```\n\n3. **Make your changes** and **commit them**:\n\n   ```bash\n   git commit -m \"Add YourFeatureName\"\n   ```\n\n4. **Push the changes** to your branch:\n\n   ```bash\n   git push origin feature/YourFeatureName\n   ```\n\n5. **Submit a Pull Request** to propose your changes.\n\nThank you for helping make this project better!\n\n---\n\n\n## 🔖 License\n\nRankify is licensed under the Apache-2.0 License - see the [LICENSE](https://opensource.org/license/apache-2-0) file for details.\n\n## 🌟 Citation\n\nPlease kindly cite our paper if helps your research:\n\n```BibTex\n@article{abdallah2025rankify,\n  title={Rankify: A Comprehensive Python Toolkit for Retrieval, Re-Ranking, and Retrieval-Augmented Generation},\n  author={Abdallah, Abdelrahman and Mozafari, Jamshid and Piryani, Bhawna and Ali, Mohammed and Jatowt, Adam},\n  journal={arXiv preprint arXiv:2502.02464},\n  year={2025}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDataScienceUIBK%2Frankify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDataScienceUIBK%2Frankify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDataScienceUIBK%2Frankify/lists"}