Composite Scoring
When the agent’s memory contains hundreds of facts, entities, and learnings, not everything belongs in the context window. Composite scoring ranks each memory item by blending three signals — semantic relevance, recency, and importance — into a single score used to select the most useful context.The Scoring Formula
Three Factors
1. Semantic Similarity
How closely the memory matches the current conversation context. Computed via cosine similarity between the embedding of the current query/conversation and the stored memory embedding.- 1.0 = exact semantic match
- 0.0 = completely unrelated
2. Recency Decay
How recently the memory was created or last referenced. Uses an exponential decay function with a configurable half-life:- Today →
1.0 - 14 days ago →
0.5 - 28 days ago →
0.25 - 56 days ago →
0.0625
3. Importance
A 0–1 score assigned during LLM extraction that reflects how significant the memory is likely to be. The extraction model assigns importance based on:- High (0.8–1.0): Critical facts — medical conditions, security credentials, business-critical decisions
- Medium (0.5–0.7): Useful preferences — timezone, communication style, project context
- Low (0.1–0.4): Casual mentions — favorite color, small talk topics
ScoringWeights Interface
0.4, 0.3, 0.3) are tuned for general-purpose assistants where relevance matters most but recency and importance both contribute meaningfully.
Configuration
Tuning for Different Use Cases
Using computeCompositeScore
You can compute scores directly for custom ranking logic:
How recall() Uses Scoring
When buildContext() assembles the memory context before a run, it calls recall() on each enabled store. Here’s the flow:
- Candidate retrieval — each store returns its candidates (facts, entities, learnings)
- Embedding — the current conversation is embedded for semantic comparison
- Scoring — each candidate is scored using
computeCompositeScore - Ranking — candidates across all stores are merged and sorted by composite score
- Truncation — the top-N results are selected to fit the token budget
How Importance Is Assigned
During background extraction, the extraction model assigns an importance score to each extracted memory. The prompt instructs the model to consider:| Signal | Effect on Importance |
|---|---|
| User explicitly says something is important | High (0.8–1.0) |
| Professional/business context | Medium-high (0.6–0.8) |
| Preferences and recurring patterns | Medium (0.4–0.6) |
| Casual, one-off mentions | Low (0.1–0.3) |
| Contradicts/updates existing fact | Inherits previous fact’s importance (minimum) |
Scoring Configuration Reference
| Property | Type | Default | Description |
|---|---|---|---|
weights.semantic | number | 0.4 | Weight for semantic similarity (0–1) |
weights.recency | number | 0.3 | Weight for recency decay score (0–1) |
weights.importance | number | 0.3 | Weight for importance score (0–1) |
recencyHalfLifeDays | number | 14 | Days until recency score drops to 0.5 |
maxContextItems | number | 20 | Max scored items injected into context |
minScore | number | 0.1 | Minimum composite score to include in context |
Cross-References
- Memory Overview — Unified memory system
- Temporal Awareness — How
validFromandinvalidatedAtaffect scoring - Graph Memory — Scoring applies to graph node/edge retrieval too
- Memory Curator — Override importance scores