{"name":"rerankers: Unified API for Reranking and Cross-Encoder Models","description":"rerankers is a lightweight, low-dependency Python library that provides a unified API for various reranking and cross-encoder models. It simplifies the integration of different reranking approaches into retrieval architectures, offering a consistent interface for diverse models like cross-encoders, RankGPT, T5, and API-based rerankers. This library aims to make reranking more accessible and easier to implement for developers.","github":"https://github.com/AnswerDotAI/rerankers","url":"https://osrepos.com/repo/answerdotai-rerankers","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/answerdotai-rerankers","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/answerdotai-rerankers.md","json":"https://osrepos.com/repo/answerdotai-rerankers.json","topics":["Python","Reranking","NLP","Information Retrieval","Machine Learning","API","Cross-Encoder","LLM"],"keywords":["Python","Reranking","NLP","Information Retrieval","Machine Learning","API","Cross-Encoder","LLM"],"stars":null,"summary":"rerankers is a lightweight, low-dependency Python library that provides a unified API for various reranking and cross-encoder models. It simplifies the integration of different reranking approaches into retrieval architectures, offering a consistent interface for diverse models like cross-encoders, RankGPT, T5, and API-based rerankers. This library aims to make reranking more accessible and easier to implement for developers.","content":"## Introduction\n\n`rerankers` is a lightweight, low-dependency Python library developed by Answer.AI that offers a unified API for integrating various reranking and cross-encoder models into your applications. Its primary goal is to simplify the use of diverse reranking approaches, providing a consistent interface regardless of the underlying model architecture. This makes it easier for developers to experiment with and deploy different rerankers in their retrieval pipelines.\n\n## Installation\n\nThe core `rerankers` package is designed to be dependency-free by default, avoiding conflicts with your existing environment. You can then install specific dependencies based on the models you intend to use.\n\nsh\n# Core package only, will require other dependencies already installed\npip install rerankers\n\n# All transformers-based approaches (cross-encoders, t5, colbert)\npip install \"rerankers[transformers]\"\n\n# RankGPT\npip install \"rerankers[gpt]\"\n\n# API-based rerankers (Cohere, Jina, MixedBread, Pinecone, Isaacus)\npip install \"rerankers[api]\"\n\n# FlashRank rerankers (ONNX-optimised, very fast on CPU)\npip install \"rerankers[flashrank]\"\n\n# RankLLM rerankers (better RankGPT + support for local models such as RankZephyr and RankVicuna)\n# Note: RankLLM is only supported on Python 3.10+! This will not work with Python 3.9\npip install \"rerankers[rankllm]\"\n\n# To support Multi-Modal rerankers such as MonoQwen2-VL and other MonoVLM models, which require flash-attention, peft, accelerate, and recent versions of `transformers`\npip install \"rerankers[monovlm]\"\n\n# To support LLM-Layerwise rerankers (which need flash-attention installed)\npip install \"rerankers[llmlayerwise]\"\n\n# All of the above\npip install \"rerankers[all]\"\n\n\n## Examples\n\nUsing `rerankers` is straightforward. You can load any supported reranker with a single line of code and then use its `rank` method to reorder documents based on a query.\n\npython\nfrom rerankers import Reranker, Document\n\n# Load a default cross-encoder\nranker = Reranker('cross-encoder')\n\n# Load a specific cross-encoder model\nranker = Reranker('mixedbread-ai/mxbai-rerank-large-v1', model_type='cross-encoder')\n\n# Load an API-based reranker (e.g., Cohere)\n# ranker = Reranker(\"cohere\", lang='en', api_key = \"YOUR_API_KEY\")\n\n# Load RankGPT\n# ranker = Reranker(\"rankgpt\", api_key = \"YOUR_API_KEY\")\n\n# Define your query and documents\nquery = \"I love you\"\ndocs = [\n    Document(text=\"I really like you\", doc_id=0, metadata={'source': 'twitter'}),\n    Document(text=\"I hate you\", doc_id=1, metadata={'source': 'reddit'})\n]\n\n# Rank the documents\nresults = ranker.rank(query=query, docs=docs)\n\n# Print the ranked results\nprint(results)\n# Example output:\n# RankedResults(results=[Result(document=Document(text='I really like you', doc_id=0, metadata={'source': 'twitter'}), score=-2.453125, rank=1), Result(document=Document(text='I hate you', doc_id=1, metadata={'source': 'reddit'}), score=-4.14453125, rank=2)], query='I love you', has_scores=True)\n\n# Access top k results\ntop_result = results.top_k(1)[0]\nprint(top_result.text) # 'I really like you'\nprint(top_result.document.metadata) # {'source': 'twitter'}\n\n\n## Why use rerankers?\n\nRerankers are a crucial component in modern retrieval architectures, yet their implementation can often be complex and fragmented. Different reranking methods, from traditional cross-encoders to advanced LLM-based approaches like RankGPT, often reside in separate libraries with inconsistent APIs and varying levels of documentation. This creates a significant barrier to entry for developers and makes it challenging to compare and integrate different models.\n\n`rerankers` addresses these issues by providing a simple, unified API. It aims to be:\n\n*   **Lightweight**: Ships with only essential dependencies.\n*   **Easy-to-understand**: Offers a minimal set of calls to learn, enabling access to a wide range of models.\n*   **Easy-to-integrate**: Designed to fit seamlessly into existing pipelines with minimal code changes.\n*   **Easy-to-expand**: New reranking models can be added with little effort, requiring only a class with a `rank()` function.\n\nBy centralizing access to various reranking models, `rerankers` empowers developers to efficiently build and optimize their information retrieval systems.\n\n## Links\n\n*   **GitHub Repository**: [AnswerDotAI/rerankers](https://github.com/AnswerDotAI/rerankers)\n*   **arXiv Paper**: [rerankers: A Lightweight Python Library to Unify Ranking Methods](https://arxiv.org/abs/2408.17344)","metrics":{"detailViews":2,"githubClicks":1},"dates":{"published":null,"modified":"2026-07-04T11:31:06.000Z"}}