vrushket commited on
Commit
b830065
Β·
verified Β·
1 Parent(s): 922cfb4

Upload AgentRank model

Browse files
Files changed (1) hide show
  1. README.md +153 -22
README.md CHANGED
@@ -9,55 +9,186 @@ tags:
9
  - memory
10
  - retrieval
11
  - rag
 
12
  library_name: transformers
13
  pipeline_tag: text-classification
14
  ---
15
 
16
- # AgentRank Reranker
17
 
18
- Cross-encoder reranker for AI agent memory retrieval.
19
 
20
- ## Overview
 
 
21
 
22
- Use in a two-stage pipeline:
23
- 1. AgentRank embedder retrieves top-50 (fast)
24
- 2. This reranker scores and reorders to top-10 (accurate)
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- ## Model Details
27
 
28
- | Property | Value |
29
- |----------|-------|
30
- | Base Model | ModernBERT-base |
31
- | Parameters | ~149M |
32
- | Validation Accuracy | 89.11% |
 
 
33
 
34
- ## Quick Start
 
 
 
 
 
 
 
 
 
 
35
 
36
  `python
37
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
38
  import torch
39
 
 
40
  model = AutoModelForSequenceClassification.from_pretrained("vrushket/agentrank-reranker")
41
  tokenizer = AutoTokenizer.from_pretrained("vrushket/agentrank-reranker")
 
42
 
 
43
  query = "What did we discuss about Python?"
44
- memory = "User prefers Python for backend"
45
 
46
- inputs = tokenizer(query, memory, return_tensors="pt", truncation=True)
47
  with torch.no_grad():
48
  score = torch.sigmoid(model(**inputs).logits).item()
49
- print(f"Score: {score:.4f}")
 
50
  `
51
 
52
- ## Links
53
 
54
- - GitHub: github.com/vmore2/AgentRank-base
55
- - PyPI: pip install agentrank
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- ## Author
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- Vrushket More (vrushket2604@gmail.com)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- ## License
62
 
63
  Apache 2.0
 
9
  - memory
10
  - retrieval
11
  - rag
12
+ - transformers
13
  library_name: transformers
14
  pipeline_tag: text-classification
15
  ---
16
 
17
+ # 🧠 AgentRank Reranker
18
 
19
+ **Cross-encoder reranker for AI agent memory retrieval β€” the second stage of a two-stage retrieval pipeline.**
20
 
21
+ [![Model](https://img.shields.io/badge/πŸ€—_HuggingFace-Model-yellow)](https://huggingface.co/vrushket/agentrank-reranker)
22
+ [![GitHub](https://img.shields.io/badge/GitHub-Repository-black)](https://github.com/vmore2/AgentRank-base)
23
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
24
 
25
+ ---
26
+
27
+ ## 🎯 What is This?
28
+
29
+ AgentRank Reranker is a **cross-encoder** that scores query-memory pairs for relevance. Use it after fast vector retrieval to **rerank** candidates for higher accuracy.
30
+
31
+ ### Two-Stage Pipeline
32
+
33
+ | Stage | Model | Speed | Accuracy |
34
+ |-------|-------|-------|----------|
35
+ | **1. Retrieve** | [agentrank-base](https://huggingface.co/vrushket/agentrank-base) | ⚑ Fast | Good |
36
+ | **2. Rerank** | **This model** | 🐒 Slower | **Best** |
37
+
38
+ ---
39
 
40
+ ## πŸ“Š Performance
41
 
42
+ | Metric | Value |
43
+ |--------|-------|
44
+ | **Validation Accuracy** | 89.11% |
45
+ | **Best Val Loss** | 0.2554 |
46
+ | **Base Model** | ModernBERT-base |
47
+ | **Parameters** | ~149M |
48
+ | **Training Samples** | 500K |
49
 
50
+ ---
51
+
52
+ ## πŸš€ Quick Start
53
+
54
+ ### Installation
55
+
56
+ `ash
57
+ pip install transformers torch
58
+ `
59
+
60
+ ### Score a Query-Memory Pair
61
 
62
  `python
63
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
64
  import torch
65
 
66
+ # Load model
67
  model = AutoModelForSequenceClassification.from_pretrained("vrushket/agentrank-reranker")
68
  tokenizer = AutoTokenizer.from_pretrained("vrushket/agentrank-reranker")
69
+ model.eval()
70
 
71
+ # Score relevance
72
  query = "What did we discuss about Python?"
73
+ memory = "User mentioned they prefer Python for backend development"
74
 
75
+ inputs = tokenizer(query, memory, return_tensors="pt", truncation=True, max_length=512)
76
  with torch.no_grad():
77
  score = torch.sigmoid(model(**inputs).logits).item()
78
+
79
+ print(f"Relevance: {score:.2%}") # e.g., "Relevance: 94.23%"
80
  `
81
 
82
+ ### Rerank Top-K Candidates
83
 
84
+ `python
85
+ def rerank(query: str, candidates: list[str], top_k: int = 10) -> list[tuple[float, str]]:
86
+ scores = []
87
+ for memory in candidates:
88
+ inputs = tokenizer(query, memory, return_tensors="pt", truncation=True)
89
+ with torch.no_grad():
90
+ score = torch.sigmoid(model(**inputs).logits).item()
91
+ scores.append((score, memory))
92
+
93
+ # Sort by score descending
94
+ return sorted(scores, reverse=True)[:top_k]
95
+
96
+ # Example
97
+ top_50_from_vector_db = [...] # Retrieved via agentrank-base
98
+ top_10 = rerank("What's my Python preference?", top_50_from_vector_db)
99
+ `
100
+
101
+ ---
102
+
103
+ ## πŸ”§ Full Two-Stage Pipeline
104
+
105
+ `python
106
+ from agentrank import AgentRankEmbedder
107
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
108
+ import torch
109
 
110
+ # Stage 1: Fast retrieval with embedder
111
+ embedder = AgentRankEmbedder.from_pretrained("vrushket/agentrank-base")
112
+ query_embedding = embedder.encode(["What's my Python preference?"])
113
+ # ... search vector DB for top-50 candidates ...
114
+
115
+ # Stage 2: Accurate reranking
116
+ reranker = AutoModelForSequenceClassification.from_pretrained("vrushket/agentrank-reranker")
117
+ tokenizer = AutoTokenizer.from_pretrained("vrushket/agentrank-reranker")
118
+
119
+ scored = []
120
+ for memory in top_50_candidates:
121
+ inputs = tokenizer(query, memory, return_tensors="pt", truncation=True)
122
+ with torch.no_grad():
123
+ score = torch.sigmoid(reranker(**inputs).logits).item()
124
+ scored.append((score, memory))
125
+
126
+ # Return top-10
127
+ final_results = sorted(scored, reverse=True)[:10]
128
+ `
129
 
130
+ ---
131
+
132
+ ## πŸ“ Related Models
133
+
134
+ | Model | Type | HuggingFace | Use Case |
135
+ |-------|------|-------------|----------|
136
+ | **AgentRank-Base** | Embedder | [vrushket/agentrank-base](https://huggingface.co/vrushket/agentrank-base) | Fast retrieval (768-dim) |
137
+ | **AgentRank-Small** | Embedder | [vrushket/agentrank-small](https://huggingface.co/vrushket/agentrank-small) | Lightweight (384-dim) |
138
+ | **AgentRank-Reranker** | Cross-encoder | This model | Accurate reranking |
139
+
140
+ ---
141
+
142
+ ## πŸ‹οΈ Training Details
143
+
144
+ - **Base Model**: ModernBERT-base
145
+ - **Epochs**: 3
146
+ - **Batch Size**: 16
147
+ - **Learning Rate**: 2e-5
148
+ - **Optimizer**: AdamW
149
+ - **Loss**: Binary Cross-Entropy
150
+ - **Hardware**: 2x RTX 6000 Ada (48GB)
151
+
152
+ ---
153
+
154
+ ## πŸ“¦ Installation via PyPI
155
+
156
+ `ash
157
+ pip install agentrank
158
+ `
159
+
160
+ ---
161
+
162
+ ## πŸ”— Links
163
+
164
+ - **GitHub**: [github.com/vmore2/AgentRank-base](https://github.com/vmore2/AgentRank-base)
165
+ - **PyPI**: [pypi.org/project/agentrank](https://pypi.org/project/agentrank)
166
+ - **CogniHive** (Multi-agent memory): [pypi.org/project/cognihive](https://pypi.org/project/cognihive)
167
+
168
+ ---
169
+
170
+ ## πŸ“§ Contact
171
+
172
+ - **Author**: Vrushket More
173
+ - **Email**: vrushket2604@gmail.com
174
+ - **LinkedIn**: [linkedin.com/in/vrushket-more](https://linkedin.com/in/vrushket-more)
175
+
176
+ ---
177
+
178
+ ## πŸ“„ Citation
179
+
180
+ `ibtex
181
+ @misc{agentrank2024,
182
+ author = {More, Vrushket},
183
+ title = {AgentRank: Temporal-Aware Embeddings for AI Agent Memory},
184
+ year = {2024},
185
+ publisher = {HuggingFace},
186
+ url = {https://huggingface.co/vrushket/agentrank-reranker}
187
+ }
188
+ `
189
+
190
+ ---
191
 
192
+ ## πŸ“œ License
193
 
194
  Apache 2.0