Instructions to use iamem/amem-reranker-minilm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use iamem/amem-reranker-minilm with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("iamem/amem-reranker-minilm") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
amem reranker (MiniLM)
A small cross-encoder that rescores the memories a coding agent's memory layer retrieved, so the fact that actually answers the developer's message comes first, and so "ok go ahead" gets nothing.
Fine-tuned from cross-encoder/ms-marco-MiniLM-L6-v2 (22M parameters) on iamem/amem-memory-queries, for amem (agent memory, anchored to your code).
Results
Measured the way amem would use it: for each query, amem's own retrieval returns its top 20 memories, and the model reorders them. A query counts only if the right fact is in that list and lands first (top-1) or in the first three (top-3).
Test split of amem-memory-queries (10 projects never seen in training, 1,497 queries, 80 vague prompts):
| Right fact first | In top 3 | Vague prompts given nothing | |
|---|---|---|---|
| amem retrieval alone | 32.6% | 52.1% | 96.3% (prompt hook) |
| Base MS MARCO MiniLM, not fine-tuned | 55.4% | 74.7% | 32.5% |
| This model | 68.8% | 82.3% | 98.8% |
The ceiling is 87.6%: how often the right fact is anywhere in amem's top 20.
amem retrieval benchmark (hand-written, never used for training; 32 questions, 8 vague prompts):
| Right fact first | In top 3 | Vague prompts given nothing | |
|---|---|---|---|
| amem retrieval alone | 81.3% | 93.8% | 100% (prompt hook) |
| This model | 93.8% | 100% | 100% |
The base model ties this model on the benchmark's top-1; the benchmark is small, so the test split is the better comparison. Fine-tuning's clearest gains are on harder, symptom-style questions and on staying quiet for vague prompts.
"Say nothing" threshold. A raw score below -0.353 (picked on the validation split to keep 97% of correct top answers) means no memory is relevant. With it, 98.8% of vague test prompts get nothing and top-1 is 67.3%.
Cost. About 33 ms on a laptop CPU to score 20 candidates; 91 MB.
Usage
from sentence_transformers import CrossEncoder
model = CrossEncoder("iamem/amem-reranker-minilm")
query = "how do I run training on multiple cards at once?"
memories = [
"Select distributed training with `trainer=ddp` and local debugging with `trainer=single_gpu`. [files: configs/trainer/ddp.yaml]",
"Datasets are versioned with DVC rather than stored in git. [files: dvc.yaml]",
]
scores = model.predict([(query, m) for m in memories])
ranked = sorted(zip(scores, memories), reverse=True)
relevant = [m for s, m in ranked if s >= -0.353]
Memories were formatted as the fact text followed by [files: path, path] during training; use the same format for best results.
Training
- Data: the train split of iamem/amem-memory-queries, 268,612 (query, memory) pairs from 180 synthetic projects. Each query comes with its correct facts, hard negatives that amem itself ranked high, and random negatives. Vague prompts contribute negatives only.
- Loss: binary cross-entropy with positives up-weighted (about 1 in 10 pairs is positive).
- 1 epoch, batch 64, learning rate 2e-5, max length 256, on Apple silicon (about 13 minutes).
- Code:
tools/reranker-datain the amem repo (gen.py,train.py,evaluate.py).
Limitations
- Trained on synthetic data written by language models; English only.
- It can only reorder what retrieval returns: if the right memory isn't in amem's top 20, the reranker can't find it.
- Tuned for short, file-anchored engineering facts, not long documents.
Links
- amem: https://github.com/sslugic/amem ยท https://getamem.com
- Training data: https://huggingface.co/datasets/iamem/amem-memory-queries
- Benchmark: https://huggingface.co/datasets/iamem/amem-retrieval-bench
- Try amem's search: https://huggingface.co/spaces/7bunnies/amem-demo
- Downloads last month
- -
Model tree for iamem/amem-reranker-minilm
Base model
microsoft/MiniLM-L12-H384-uncasedDataset used to train iamem/amem-reranker-minilm
Evaluation results
- Top-1 (right fact first) on amem memory queries (test split)test set self-reported0.688
- Top-3 on amem memory queries (test split)test set self-reported0.823