Update README.md
Browse files
README.md
CHANGED
|
@@ -4,40 +4,92 @@ license: cc-by-nc-sa-4.0
|
|
| 4 |
pipeline_tag: text-ranking
|
| 5 |
---
|
| 6 |
|
|
|
|
|
|
|
| 7 |
# Contextual AI Reranker v2 6B
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
## Highlights
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
-
|
| 14 |
-
-
|
| 15 |
-
-
|
|
|
|
| 16 |
- Real-world use cases
|
| 17 |
|
| 18 |
<p align="center">
|
| 19 |
<img src="main_benchmark.png" width="1200"/>
|
| 20 |
<p>
|
| 21 |
|
| 22 |
-
For
|
| 23 |
|
| 24 |
## Overview
|
| 25 |
|
| 26 |
-
- Model Type
|
| 27 |
-
- Supported Languages
|
| 28 |
-
-
|
| 29 |
-
- Context Length
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
## Quickstart
|
| 33 |
|
| 34 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
```python
|
| 39 |
import os
|
| 40 |
-
os.environ['VLLM_USE_V1'] = '0' # v1 engine doesn
|
| 41 |
|
| 42 |
import torch
|
| 43 |
from vllm import LLM, SamplingParams
|
|
@@ -97,12 +149,26 @@ def infer_w_vllm(model_path: str, query: str, instruction: str, documents: list[
|
|
| 97 |
print(f"Instruction: {instruction}")
|
| 98 |
for score, doc_id, doc in results:
|
| 99 |
print(f"Score: {score:.4f} | Doc: {doc}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
```
|
| 101 |
|
| 102 |
|
| 103 |
-
### Transformers Usage
|
| 104 |
|
| 105 |
-
Requires transformers>=4.51.0 for BF16. Not supported for NVFP4.
|
| 106 |
|
| 107 |
```python
|
| 108 |
import torch
|
|
@@ -166,7 +232,7 @@ If you use this model, please cite:
|
|
| 166 |
```bibtex
|
| 167 |
@misc{ctxl_rerank_v2_instruct_multilingual,
|
| 168 |
title={Contextual AI Reranker v2},
|
| 169 |
-
author={George
|
| 170 |
year={2025},
|
| 171 |
url={https://contextual.ai/blog/rerank-v2},
|
| 172 |
}
|
|
@@ -178,4 +244,4 @@ Creative Commons Attribution Non Commercial Share Alike 4.0 (cc-by-nc-sa-4.0)
|
|
| 178 |
|
| 179 |
## Contact
|
| 180 |
|
| 181 |
-
For questions or issues, please open an issue on the model repository
|
|
|
|
| 4 |
pipeline_tag: text-ranking
|
| 5 |
---
|
| 6 |
|
| 7 |
+
<div align="center">
|
| 8 |
+
|
| 9 |
# Contextual AI Reranker v2 6B
|
| 10 |
|
| 11 |
+
<img src="Contextual_AI_Brand_Mark_Dark.png" width="10%" alt="Contextual_AI"/>
|
| 12 |
+
|
| 13 |
+
[](https://contextual.ai/blog/rerank-v2)
|
| 14 |
+
[](https://huggingface.co/collections/ContextualAI/contextual-ai-reranker-v2)
|
| 15 |
+
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
<hr>
|
| 19 |
+
|
| 20 |
## Highlights
|
| 21 |
|
| 22 |
+
Contextual AI's reranker is the **first instruction-following reranker** capable of handling retrieval conflicts and ranking with custom instructions (e.g., prioritizing recent information). It achieves state-of-the-art performance on BEIR and sits on the cost/performance Pareto frontier across:
|
| 23 |
+
|
| 24 |
+
- Instruction following
|
| 25 |
+
- Question answering
|
| 26 |
+
- Multilinguality (100+ languages)
|
| 27 |
+
- Product search & recommendation
|
| 28 |
- Real-world use cases
|
| 29 |
|
| 30 |
<p align="center">
|
| 31 |
<img src="main_benchmark.png" width="1200"/>
|
| 32 |
<p>
|
| 33 |
|
| 34 |
+
For detailed benchmarks, see our [blog post](https://contextual.ai/blog/rerank-v2).
|
| 35 |
|
| 36 |
## Overview
|
| 37 |
|
| 38 |
+
- **Model Type**: Text Reranking
|
| 39 |
+
- **Supported Languages**: 100+
|
| 40 |
+
- **Parameters**: 6B
|
| 41 |
+
- **Context Length**: up to 32K
|
| 42 |
+
|
| 43 |
+
## When to Use This Model
|
| 44 |
+
|
| 45 |
+
Use this reranker when you need to:
|
| 46 |
+
- Re-rank retrieved documents with custom instructions
|
| 47 |
+
- Handle conflicting information in retrieval results
|
| 48 |
+
- Prioritize documents by recency or other criteria
|
| 49 |
+
- Support multilingual search (100+ languages)
|
| 50 |
+
- Process long contexts (up to 32K tokens)
|
| 51 |
|
| 52 |
## Quickstart
|
| 53 |
|
| 54 |
+
### Basic Usage
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
# Choose vLLM (recommended for production) or Transformers (simpler setup)
|
| 58 |
+
# See full implementation in sections below
|
| 59 |
+
|
| 60 |
+
model_path = "ContextualAI/reranker_v2_6b"
|
| 61 |
|
| 62 |
+
query = "What are the health benefits of exercise?"
|
| 63 |
+
instruction = "Prioritize recent medical research"
|
| 64 |
+
documents = [
|
| 65 |
+
"Regular exercise reduces risk of heart disease and improves mental health.",
|
| 66 |
+
"A 2024 study shows exercise enhances cognitive function in older adults.",
|
| 67 |
+
"Ancient Greeks valued physical fitness for military training."
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
# Using vLLM (see full code below):
|
| 71 |
+
infer_w_vllm(model_path, query, instruction, documents)
|
| 72 |
+
|
| 73 |
+
# OR using Transformers (see full code below):
|
| 74 |
+
infer_w_hf(model_path, query, instruction, documents)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
**Expected Output:**
|
| 78 |
+
```
|
| 79 |
+
Query: What are the health benefits of exercise?
|
| 80 |
+
Instruction: Prioritize recent medical research
|
| 81 |
+
Score: 0.8542 | Doc: A 2024 study shows exercise enhances cognitive function in older adults.
|
| 82 |
+
Score: 0.7891 | Doc: Regular exercise reduces risk of heart disease and improves mental health.
|
| 83 |
+
Score: 0.4123 | Doc: Ancient Greeks valued physical fitness for military training.
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
### vLLM Usage (Recommended for Production)
|
| 87 |
+
|
| 88 |
+
Requires `vllm==0.10.0` for NVFP4 or `vllm>=0.8.5` for BF16.
|
| 89 |
|
| 90 |
```python
|
| 91 |
import os
|
| 92 |
+
os.environ['VLLM_USE_V1'] = '0' # v1 engine doesn't support logits processor yet
|
| 93 |
|
| 94 |
import torch
|
| 95 |
from vllm import LLM, SamplingParams
|
|
|
|
| 149 |
print(f"Instruction: {instruction}")
|
| 150 |
for score, doc_id, doc in results:
|
| 151 |
print(f"Score: {score:.4f} | Doc: {doc}")
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
# Example usage
|
| 155 |
+
if __name__ == "__main__":
|
| 156 |
+
model_path = "ContextualAI/reranker_v2_6b"
|
| 157 |
+
query = "What are the health benefits of exercise?"
|
| 158 |
+
instruction = "Prioritize recent medical research"
|
| 159 |
+
documents = [
|
| 160 |
+
"Regular exercise reduces risk of heart disease and improves mental health.",
|
| 161 |
+
"A 2024 study shows exercise enhances cognitive function in older adults.",
|
| 162 |
+
"Ancient Greeks valued physical fitness for military training."
|
| 163 |
+
]
|
| 164 |
+
|
| 165 |
+
infer_w_vllm(model_path, query, instruction, documents)
|
| 166 |
```
|
| 167 |
|
| 168 |
|
| 169 |
+
### Transformers Usage (Simpler Setup)
|
| 170 |
|
| 171 |
+
Requires `transformers>=4.51.0` for BF16. Not supported for NVFP4.
|
| 172 |
|
| 173 |
```python
|
| 174 |
import torch
|
|
|
|
| 232 |
```bibtex
|
| 233 |
@misc{ctxl_rerank_v2_instruct_multilingual,
|
| 234 |
title={Contextual AI Reranker v2},
|
| 235 |
+
author={Halal, George and Agrawal, Sheshansh},
|
| 236 |
year={2025},
|
| 237 |
url={https://contextual.ai/blog/rerank-v2},
|
| 238 |
}
|
|
|
|
| 244 |
|
| 245 |
## Contact
|
| 246 |
|
| 247 |
+
For questions or issues, please open an issue on the model repository.
|