{"id":8168,"library":"flashrank","title":"FlashRank","description":"FlashRank is an ultra-lite and super-fast Python library designed to add re-ranking capabilities to existing search and retrieval pipelines. Leveraging state-of-the-art LLMs and cross-encoders, it provides both pairwise (cross-encoder based) and listwise (LLM-based) re-ranking. As of version 0.2.10, FlashRank is known for its speed and efficiency, particularly on CPU, making it suitable for cost-effective serverless deployments. The library maintains an active development pace with frequent updates and bug fixes.","status":"active","version":"0.2.10","language":"en","source_language":"en","source_url":"https://github.com/PrithivirajDamodaran/FlashRank","tags":["re-ranking","nlp","search","retrieval-augmented-generation","RAG","cross-encoder","LLM"],"install":[{"cmd":"pip install flashrank","lang":"bash","label":"Install core (pairwise rerankers)"},{"cmd":"pip install flashrank[llm]","lang":"bash","label":"Install with LLM-based listwise rerankers"}],"dependencies":[{"reason":"Used for efficient cross-encoder model inference.","package":"onnxruntime","optional":false}],"imports":[{"symbol":"Ranker","correct":"from flashrank.Ranker import Ranker"},{"symbol":"RerankRequest","correct":"from flashrank.RerankRequest import RerankRequest"}],"quickstart":{"code":"from flashrank.Ranker import Ranker\nfrom flashrank.RerankRequest import RerankRequest\n\n# Initialize the ranker with a default or specified model\n# 'ms-marco-TinyBERT-L-2-v2' (~4MB) is the default and fastest.\n# 'ms-marco-MiniLM-L-12-v2' (~34MB) offers better performance.\n# For LLM-based rerankers, use 'rank_zephyr_7b_v1_full' (requires flashrank[llm])\nranker = Ranker(model_name=\"ms-marco-MiniLM-L-12-v2\")\n\nquery = \"What is the capital of France?\"\npassages = [\n    {\"id\": \"1\", \"text\": \"Paris is the capital and most populous city of France.\"},\n    {\"id\": \"2\", \"text\": \"The Eiffel Tower is in Paris.\"},\n    {\"id\": \"3\", \"text\": \"Berlin is the capital of Germany.\"}\n]\n\n# Create a RerankRequest object\nrerank_request = RerankRequest(query=query, passages=passages)\n\n# Perform reranking\nresults = ranker.rerank(rerank_request)\n\n# Print reranked results (sorted by score in descending order)\nfor result in results:\n    print(f\"ID: {result['id']}, Text: {result['text']}, Score: {result['score']:.4f}\")","lang":"python","description":"This example demonstrates how to initialize a FlashRank `Ranker` with a specified model and then re-rank a list of passages for a given query. The `RerankRequest` object encapsulates the query and passages. The `rerank` method returns passages sorted by their relevance score."},"warnings":[{"fix":"Ensure the user has write permissions to the cache directory (default is an OS-specific temp directory). For persistent storage or specific control, initialize the Ranker with `cache_dir=path/to/cache`: `ranker = Ranker(model_name='ms-marco-MiniLM-L-12-v2', cache_dir='/path/to/models')`.","message":"FlashRank downloads models on first use and caches them. If the default cache directory is not writable or accessible, or if a specific model path is incorrectly configured, this can lead to 'NO_SUCHFILE' errors. Ensure appropriate permissions for the cache directory, or explicitly set `cache_dir` in the Ranker initialization.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `from flashrank.Ranker import Ranker` is imported *before* `from langchain.retrievers.document_compressors import FlashrankRerank`. The correct import order is crucial for Pydantic to resolve type annotations. No manual `model_rebuild()` is necessary if the order is correct.","message":"When integrating with LangChain's `FlashrankRerank` compressor, a `PydanticUndefinedAnnotation: name 'Ranker' is not defined` error can occur if `flashrank.Ranker` is not imported before `langchain.retrievers.document_compressors.FlashrankRerank`. This is due to Pydantic's validation order.","severity":"breaking","affected_versions":"Versions integrating with LangChain >=0.2.0 (Pydantic v2)"},{"fix":"Explicitly specify a currently supported model using the `model_name` parameter during `Ranker` initialization. Refer to the official FlashRank GitHub repository for the latest list of recommended models. For example: `ranker = Ranker(model_name='ms-marco-MiniLM-L-12-v2')`.","message":"Default models or older specified models may become unavailable or get superseded, leading to model loading failures (e.g., `ONNXRuntimeError: NO_SUCHFILE`). This often happens without explicit code changes on the user's part.","severity":"gotcha","affected_versions":"All versions, particularly with new releases or model updates"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure your `model_name` is correct and supported. If using a custom `cache_dir`, verify its path and permissions. Updating to a newer, explicitly named model (e.g., `model_name='ms-marco-MiniLM-L-12-v2'`) can often resolve this by forcing a fresh download.","cause":"The specified model file could not be found in the expected cache directory. This often happens if the model was not downloaded successfully, the cache was cleared, or the model name/path has changed or is incorrect.","error":"[ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from /tmp/ms-marco-MultiBERT-L-12/flashrank-MultiBERT-L12_Q.onnx failed:Load model /tmp/ms-marco-MultiBERT-L-12/flashrank-MultiBERT-L12_Q.onnx failed. File doesn't exist."},{"fix":"Move `from flashrank.Ranker import Ranker` to appear *before* any imports or instantiations of `FlashrankRerank` (e.g., `from langchain.retrievers.document_compressors import FlashrankRerank`).","cause":"This error occurs when using `FlashrankRerank` with LangChain and the `Ranker` class from `flashrank` is not imported or not imported in the correct order (before the LangChain component that references it). Pydantic attempts to validate the `FlashrankRerank` class before `Ranker` is available in the global scope.","error":"PydanticUndefinedAnnotation: name 'Ranker' is not defined"},{"fix":"Specify a valid, existing directory on your Windows system for caching models using the `cache_dir` parameter during `Ranker` initialization. For example: `ranker = Ranker(model_name=\"ms-marco-MiniLM-L-12-v2\", cache_dir='C:/Users/YourUser/FlashRankModels')`.","cause":"This error typically occurs on Windows systems when FlashRank attempts to use a default cache directory that is usually found on Unix-like systems (like '/opt'). Windows does not have a '/opt' directory by default.","error":"[WinError 2] The system cannot find the file specified: '\\opt'"}]}