Architecture · Ranking
Scoring and Ranking Memories by Relevance
Memory scoring ranks candidate memories by relevance, recency and importance so agents surface the right facts — not just the most similar embeddings — at each turn.
Ranking formula
Problem
Why similarity alone fails
Vector similarity measures embedding distance — not whether a memory is useful, current or scoped to the right user.
- Stale but similar — “user mentioned rain last Tuesday” ranks high for a dinner query
- Wrong scope — another user’s memory leaks without
user_idfilters - Low-salience match — small talk outranks core preferences on paraphrase overlap
Signals
Scoring signals
Production rankers combine semantic similarity, recency decay, importance boosts, memory-type weights and graph distance.
Park et al. (2023, Generative Agents): score = recency + importance + relevance (weighted sum, each normalized 0–1). Tune weights per use case — support bots may weight recency higher; assistants may weight importance for stable prefs.
| Signal | What it measures | Typical source |
|---|---|---|
| Relevance | Query–memory similarity | Embedding cosine |
| Recency | How fresh the memory is | Exponential time decay |
| Importance | Salience at write time | LLM score or heuristic |
| Type weight | Episodic vs semantic priority | Metadata tag |
| Graph distance | Entity relationship hops | Zep Graphiti traversal |
Recency
Recency decay
Memories lose rank as they age — exponentially, with a tunable half-life.
Park et al. (2023) use decay at 0.995 per hour since last access. Worked example: a fresh preference (recency 0.9) outranks week-old small talk (recency 0.3) when relevance is comparable. Hard-delete stale memories via forgetting and eviction; downrank when you may still need archival access.
Hybrid
Hybrid ranking with keyword and metadata
Pre-filter by user_id, session and tags — then combine BM25 keyword scores with vector similarity.
Hybrid search catches exact order numbers and SKUs vectors miss. Metadata filters prevent cross-user leakage before ranking runs.
Frameworks
Framework scoring approaches
- Engram — Weaviate hybrid search + metadata filters on memory collections
- Mem0 — relevance params on search API; LOCOMO J 66.9 with tuned retrieval (Chhikara et al., 2025)
- Zep — graph traversal + vector hybrid; temporal validity filters
- Custom — cross-encoder rerankers on top-k candidates (adds latency, improves precision)
FAQ
Frequently asked questions
How do you choose top-k for memory scoring?
Start with k = 5–10, tune on LOCOMO or your domain eval. Smaller k saves tokens; larger k improves recall. Mem0's selective retrieval uses far fewer tokens than full-context baselines (Chhikara et al., 2025).
Recency vs relevance — which to weight higher?
Depends on use case: support bots often weight recency for ticket context; personalization assistants weight importance for stable prefs. Park et al. (2023) uses equal 1.0 weights as a starting point.
Is a cross-encoder reranker worth it?
Yes when precision matters and you can afford extra latency — rerank top-20 vector hits down to top-5. Skip for latency-sensitive paths; metadata filters + recency often suffice.
How do you fix wrong memory retrieval?
Add recency/importance to scoring, tighten user_id filters, use hybrid search for exact IDs, invalidate stale facts. See scoring signals above.
How do you benchmark memory scoring?
LOCOMO and LongMemEval measure end-to-end recall. Ablate scoring weights and track hit rate + tokens injected. See evaluation hub.
How does scoring relate to context engineering?
Scoring decides which memories enter the prompt; context engineering formats and orders them under token budget. See context engineering.
What is the Park et al. memory scoring formula?
Weighted sum of recency + importance + relevance (each 0–1), with recency decaying at 0.995 per hour since last access (Park et al., 2023, Generative Agents).
Does Engram support hybrid memory scoring?
Yes — Weaviate hybrid search combines vector similarity with keyword/BM25 and metadata filters on memory collections. See Engram explained.