Skip to main content

Module scoring

Module scoring 

Source
Expand description

Tunable composite scoring, normalization, adjustments, and language routing. See crates/khive-pack-memory/docs/api/scoring.md for the complete scoring model.

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 heuristic entity names per query; it bounds scans, not boosted memories.
MAX_ENTITY_LOOKUP_CANDIDATES
Maximum candidate strings sent to one batched KG entity-name lookup.
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_lookup_candidates
Build bounded strings for recall’s batched, case-insensitive KG entity lookup.
entity_posterior_term
clamp(1 + w_ent * (entity_posterior_mean - 0.5), 0.85, 1.15).
extract_entity_candidates
Extract capitalized, non-stopword entity names for the default entity boost.
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
Return whether more than 15% of alphabetic characters are non-ASCII.
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.