Skip to main content

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

Each factor produces a value between 0 and 1. The weights control how much each factor matters.

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
This is the primary signal — a highly relevant old fact beats a recent irrelevant one.

2. Recency Decay

How recently the memory was created or last referenced. Uses an exponential decay function with a configurable half-life:
With the default half-life of 14 days:
  • Today → 1.0
  • 14 days ago → 0.5
  • 28 days ago → 0.25
  • 56 days ago → 0.0625
Old memories aren’t excluded — they just need higher semantic relevance to surface.

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
Importance acts as a floor — a critical fact from months ago still surfaces if it’s important enough.

ScoringWeights Interface

The defaults (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:
This is useful when building custom recall pipelines or debugging why a particular memory did or didn’t surface.

How recall() Uses Scoring

When buildContext() assembles the memory context before a run, it calls recall() on each enabled store. Here’s the flow:
  1. Candidate retrieval — each store returns its candidates (facts, entities, learnings)
  2. Embedding — the current conversation is embedded for semantic comparison
  3. Scoring — each candidate is scored using computeCompositeScore
  4. Ranking — candidates across all stores are merged and sorted by composite score
  5. 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: You can override importance for specific facts via the curator:

Scoring Configuration Reference

Weights should sum to 1.0. If they don’t, they’re normalized internally.

Cross-References