Skip to main content

Module scoring

Module scoring 

Source
Expand description

Composite memory scoring — ported from the archived internal service (v1 archive).

Provides a fully-tunable scoring pipeline:

  1. ScoringConfig — all knobs, all pub, all serde-friendly for agent sweeps.
  2. calculate_score — multiplicative formula: w_rel × relevance × (1 + w_temp × recency) × (1 + w_imp × salience).
  3. ScoreAdjustment — declarative conditional rules applied after the base formula.
  4. normalize_rrf_scores / normalize_rank_fusion_scores — RRF and raw-cosine normalization.
  5. normalize_min_score — dual-scale input (0.0–1.0 fraction or 0–100 integer).
  6. is_meaningful_query — noise gate before embedding compute.
  7. contains_cjk — CJK routing decision.
  8. needs_multilingual — broad multilingual routing gate (non-ASCII alphabetic script).

Structs§

CandidateContext
Context passed to condition evaluation — properties of the candidate + query.
ScoreAdjustment
A conditional score adjustment: if condition matches, apply operation.
ScoreInput
Input data for calculate_score — groups per-candidate fields to stay within clippy’s 7-argument limit.
ScoringConfig
Complete, tunable scoring configuration for the memory recall pipeline. DoS caps: max_recall_candidates≤500, default_token_budget≤16000, default_recall_limit≤200.
ScoringWeights
Weights for the combined memory score: score = w_rel × relevance × (1 + w_temp × recency) × (1 + w_imp × salience).

Enums§

AdjustmentCondition
A condition that determines whether a score adjustment applies to a candidate.
AdjustmentOp
The operation to apply when a condition matches.

Constants§

ENTITY_POSTERIOR_CLAMP_MAX
Upper bound of the per-entity posterior multiplier — the term can never move a score up by more than 15%.
ENTITY_POSTERIOR_CLAMP_MIN
Lower bound of the per-entity posterior multiplier — the term can never move a score down by more than 15%.
ENTITY_POSTERIOR_WEIGHT
Default weight for the per-entity posterior term. Chosen so the clamp bounds below are exactly reachable at posterior means of 0.0 and 1.0 (1 + 0.3 * (0.0 - 0.5) = 0.85, 1 + 0.3 * (1.0 - 0.5) = 1.15).
MAX_AUTO_ENTITY_NAMES
Maximum number of auto-extracted entity-name candidates per query. EntityMatch (see default_adjustments above) applies its multiplier to any candidate memory that contains any one of the extracted names — this constant does not limit how many memories can receive the boost (one generic name can still match many memories). It only bounds the extracted-name list length and, transitively, the number of contains_at_word_boundary scans EntityMatch performs per note.
MAX_RECALL_CANDIDATES
Maximum candidates a caller may request (server-side cap).
MAX_RECALL_LIMIT
Maximum result limit a caller may request (server-side cap).
MAX_TOKEN_BUDGET
Maximum token budget a caller may request (server-side cap).

Functions§

calculate_score
Composite score for a single memory candidate.
contains_cjk
Returns true when >15% of the query’s characters are CJK.
default_adjustments
Default score adjustments: episodic recency bonus, semantic age penalty, entity boost.
entity_posterior_term
clamp(1 + w_ent * (entity_posterior_mean - 0.5), 0.85, 1.15).
extract_entity_candidates
Auto-extract entity-name candidates from a recall query when the caller does not supply entity_names explicitly.
is_cjk_char
Returns true if c is a CJK character (Unified, Extension A/B, Hiragana, Katakana, Hangul).
is_meaningful_query
Returns true if the query has enough semantic content for meaningful recall.
needs_multilingual
Returns true when text should be routed to the multilingual embedding model for dense retrieval.
normalize_min_score
Normalize min_score: 0–1 passes through, 1–100 divides by 100, others return Err.
normalize_rank_fusion_scores
Normalize raw-cosine or BM25 scores (single-source) into a calibrated relevance band.
normalize_rrf_scores
Normalize RRF-fused scores (dual-source) into a calibrated relevance band.