feat(recommendation): extend Score with ContextualMatchScore + ContextWeight
This commit is contained in:
@@ -8,12 +8,15 @@ import (
|
||||
)
|
||||
|
||||
// ScoringInputs are the per-track facts the score function consumes.
|
||||
// Sub-plan #3 (contextual scoring) extends this with ContextualMatchScore.
|
||||
// ContextualMatchScore is in [0, 1] — max similarity between the user's
|
||||
// current session vector and any non-seed contextual_like row for this
|
||||
// track. Set by LoadCandidates after a bulk fetch.
|
||||
type ScoringInputs struct {
|
||||
IsGeneralLiked bool
|
||||
LastPlayedAt *time.Time // nil = never played
|
||||
PlayCount int // total play_events
|
||||
SkipCount int // play_events with was_skipped=true
|
||||
IsGeneralLiked bool
|
||||
LastPlayedAt *time.Time // nil = never played
|
||||
PlayCount int // total play_events
|
||||
SkipCount int // play_events with was_skipped=true
|
||||
ContextualMatchScore float64 // [0, 1]; 0 when no signal
|
||||
}
|
||||
|
||||
// ScoringWeights are the operator-tunable knobs. Defaults live in
|
||||
@@ -24,6 +27,7 @@ type ScoringWeights struct {
|
||||
RecencyWeight float64
|
||||
SkipPenalty float64
|
||||
JitterMagnitude float64
|
||||
ContextWeight float64
|
||||
}
|
||||
|
||||
// Score computes the weighted-shuffle score per spec §6:
|
||||
@@ -32,6 +36,7 @@ type ScoringWeights struct {
|
||||
// + (is_general_liked ? LikeBoost : 0)
|
||||
// + recency_decay * RecencyWeight
|
||||
// - skip_ratio * SkipPenalty
|
||||
// + contextual_match_score * ContextWeight
|
||||
// + small_random_jitter
|
||||
//
|
||||
// Higher score = more likely to surface. rng is a function returning a
|
||||
@@ -44,6 +49,7 @@ func Score(in ScoringInputs, w ScoringWeights, now time.Time, rng func() float64
|
||||
}
|
||||
s += recencyDecay(in.LastPlayedAt, now) * w.RecencyWeight
|
||||
s -= skipRatio(in.PlayCount, in.SkipCount) * w.SkipPenalty
|
||||
s += in.ContextualMatchScore * w.ContextWeight
|
||||
s += (rng()*2 - 1) * w.JitterMagnitude
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user