vrushket commited on
Commit
191850d
·
verified ·
1 Parent(s): 74c0ed5

Upload AgentRank model

Browse files
README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - sentence-transformers
7
+ - embeddings
8
+ - retrieval
9
+ - agents
10
+ - memory
11
+ - rag
12
+ - semantic-search
13
+ library_name: transformers
14
+ pipeline_tag: sentence-similarity
15
+ datasets:
16
+ - custom
17
+ metrics:
18
+ - mrr
19
+ - recall
20
+ - ndcg
21
+ model-index:
22
+ - name: agentrank-small
23
+ results:
24
+ - task:
25
+ type: retrieval
26
+ name: Agent Memory Retrieval
27
+ metrics:
28
+ - type: mrr
29
+ value: 0.6375
30
+ name: MRR
31
+ - type: recall
32
+ value: 0.4460
33
+ name: Recall@1
34
+ - type: recall
35
+ value: 0.9740
36
+ name: Recall@5
37
+ - type: ndcg
38
+ value: 0.6797
39
+ name: NDCG@10
40
+ ---
41
+
42
+ # AgentRank-Small: Embedding Model for AI Agent Memory Retrieval
43
+
44
+ <p align="center">
45
+ <img src="https://img.shields.io/badge/MRR-0.6375-brightgreen" alt="MRR">
46
+ <img src="https://img.shields.io/badge/Recall%405-97.4%25-blue" alt="Recall@5">
47
+ <img src="https://img.shields.io/badge/Parameters-33M-orange" alt="Parameters">
48
+ <img src="https://img.shields.io/badge/License-Apache%202.0-green" alt="License">
49
+ </p>
50
+
51
+ **AgentRank** is the first embedding model family specifically designed for AI agent memory retrieval. Unlike general-purpose embedders, AgentRank understands temporal context, memory types, and importance - critical for agents that need to remember past interactions.
52
+
53
+ ## 🚀 Key Results
54
+
55
+ | Model | MRR | Recall@1 | Recall@5 | NDCG@10 |
56
+ |-------|-----|----------|----------|---------|
57
+ | **AgentRank-Small** | **0.6375** | **0.4460** | **0.9740** | **0.6797** |
58
+ | all-MiniLM-L6-v2 | 0.5297 | 0.3720 | 0.7520 | 0.6370 |
59
+ | all-mpnet-base-v2 | 0.5351 | 0.3660 | 0.7960 | 0.6335 |
60
+
61
+ **+20% MRR improvement over base MiniLM model!**
62
+
63
+ ## 🎯 Why AgentRank?
64
+
65
+ AI agents need memory that understands:
66
+
67
+ | Challenge | General Embedders | AgentRank |
68
+ |-----------|-------------------|-----------|
69
+ | "What did I say **yesterday**?" | ❌ No temporal awareness | ✅ Temporal embeddings |
70
+ | "What's my **preference**?" | ❌ Mixes with events | ✅ Memory type awareness |
71
+ | "What's **most important**?" | ❌ No priority | ✅ Importance prediction |
72
+
73
+ ## 📦 Installation
74
+
75
+ ```bash
76
+ pip install transformers torch
77
+ ```
78
+
79
+ ## 💻 Usage
80
+
81
+ ### Basic Usage
82
+
83
+ ```python
84
+ from transformers import AutoModel, AutoTokenizer
85
+ import torch
86
+
87
+ # Load model
88
+ model = AutoModel.from_pretrained("vrushket/agentrank-small")
89
+ tokenizer = AutoTokenizer.from_pretrained("vrushket/agentrank-small")
90
+
91
+ def encode(texts):
92
+ inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")
93
+ with torch.no_grad():
94
+ outputs = model(**inputs)
95
+ embeddings = outputs.last_hidden_state.mean(dim=1)
96
+ embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)
97
+ return embeddings
98
+
99
+ # Encode memories and query
100
+ memories = [
101
+ "User prefers Python over JavaScript",
102
+ "User asked about machine learning yesterday",
103
+ "User is working on a web project",
104
+ ]
105
+ query = "What programming language does the user like?"
106
+
107
+ memory_embeddings = encode(memories)
108
+ query_embedding = encode([query])
109
+
110
+ # Compute similarities
111
+ similarities = torch.mm(query_embedding, memory_embeddings.T)
112
+ print(f"Most relevant: {memories[similarities.argmax()]}")
113
+ # Output: "User prefers Python over JavaScript"
114
+ ```
115
+
116
+ ### With Temporal & Memory Type Metadata (Full Power)
117
+
118
+ ```python
119
+ # For full AgentRank features including temporal awareness:
120
+ # pip install agentrank (coming soon!)
121
+
122
+ from agentrank import AgentRankEmbedder
123
+
124
+ model = AgentRankEmbedder.from_pretrained("vrushket/agentrank-small")
125
+
126
+ # Encode with metadata
127
+ embedding = model.encode(
128
+ "User mentioned they prefer morning meetings",
129
+ days_ago=3, # Memory is 3 days old
130
+ memory_type="semantic" # It's a preference, not an event
131
+ )
132
+ ```
133
+
134
+ ## 🏗️ Architecture
135
+
136
+ AgentRank-Small is based on `all-MiniLM-L6-v2` with novel additions:
137
+
138
+ ```
139
+ ┌─────────────────────────────────────────┐
140
+ │ MiniLM Transformer Encoder (6 layers) │
141
+ └─────────────────────────────────────────┘
142
+
143
+ ┌───────────────┼───────────────┐
144
+ ↓ ↓ ↓
145
+ ┌─────────┐ ┌──────────┐ ┌───────────┐
146
+ │ Temporal │ │ Memory │ │ Importance│
147
+ │ Position │ │ Type │ │ Prediction│
148
+ │ Embed │ │ Embed │ │ Head │
149
+ └─────────┘ └──────────┘ └───────────┘
150
+ │ │ │
151
+ └───────────────┼───────────────┘
152
+
153
+ ┌─────────────────┐
154
+ │ L2 Normalized │
155
+ │ 384-dim Embedding│
156
+ └─────────────────┘
157
+ ```
158
+
159
+ **Novel Features:**
160
+ - **Temporal Position Embeddings**: 10 learnable buckets (today, 1-3 days, week, month, etc.)
161
+ - **Memory Type Embeddings**: Episodic, Semantic, Procedural
162
+ - **Importance Prediction Head**: Auxiliary task during training
163
+
164
+ ## 🎓 Training
165
+
166
+ - **Dataset**: 500K synthetic agent memory samples
167
+ - **Memory Types**: Episodic (40%), Semantic (35%), Procedural (25%)
168
+ - **Loss**: Multiple Negatives Ranking Loss + Importance MSE
169
+ - **Hard Negatives**: 5 types (temporal, type confusion, topic drift, etc.)
170
+ - **Hardware**: NVIDIA RTX 6000 Ada (48GB) with FP16
171
+
172
+ ## 📊 Benchmarks
173
+
174
+ Evaluated on AgentMemBench (500 test samples, 8 candidates each):
175
+
176
+ | Metric | AgentRank-Small | MiniLM | Improvement |
177
+ |--------|-----------------|--------|-------------|
178
+ | MRR | 0.6375 | 0.5297 | **+20.4%** |
179
+ | Recall@1 | 0.4460 | 0.3720 | **+19.9%** |
180
+ | Recall@5 | 0.9740 | 0.7520 | **+29.5%** |
181
+ | NDCG@10 | 0.6797 | 0.6370 | **+6.7%** |
182
+
183
+ ## 🔜 Coming Soon
184
+
185
+ - **AgentRank-Base**: 110M params, even better performance
186
+ - **AgentRank-Reranker**: Cross-encoder for top-k refinement
187
+ - **Python Package**: `pip install agentrank`
188
+
189
+ ## 📚 Citation
190
+
191
+ ```bibtex
192
+ @misc{agentrank2024,
193
+ author = {Vrushket More},
194
+ title = {AgentRank: Embedding Models for AI Agent Memory Retrieval},
195
+ year = {2024},
196
+ publisher = {HuggingFace},
197
+ url = {https://huggingface.co/vrushket/agentrank-small}
198
+ }
199
+ ```
200
+
201
+ ## 📄 License
202
+
203
+ Apache 2.0 - Free for commercial use!
204
+
205
+ ## 🤝 Acknowledgments
206
+
207
+ Built on top of [sentence-transformers](https://www.sbert.net/) and [MiniLM](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2).
agentrank_components.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2116b40785efd6d5ad2e5303327afd730b089b4768e14f6c9d27524fa1fb17e
3
+ size 912924
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "dtype": "float32",
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 384,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 1536,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 6,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "transformers_version": "4.57.3",
22
+ "type_vocab_size": 2,
23
+ "use_cache": true,
24
+ "vocab_size": 30522
25
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fdb9fcdb851dbc7bba1f70a3ac3bf3bc1de46a4a8e0284d50b0270e8d69869f0
3
+ size 90864192
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "max_length": 128,
51
+ "model_max_length": 512,
52
+ "never_split": null,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "[PAD]",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "[SEP]",
58
+ "stride": 0,
59
+ "strip_accents": null,
60
+ "tokenize_chinese_chars": true,
61
+ "tokenizer_class": "BertTokenizer",
62
+ "truncation_side": "right",
63
+ "truncation_strategy": "longest_first",
64
+ "unk_token": "[UNK]"
65
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff