feat(recommendation): add ContextualMatchScore (max over non-seed likes)

This commit is contained in:
2026-04-27 20:20:53 -04:00
parent a7211aacff
commit 347884bc2b
2 changed files with 88 additions and 0 deletions
+25
View File
@@ -74,3 +74,28 @@ func setJaccardSlice(a, b []string) float64 {
}
return float64(intersect) / float64(union)
}
// ContextualMatchScore returns the maximum Similarity between the current
// session vector and any non-seed entry in likes. Returns 0 when:
// - current.Seed is true (no meaningful current context)
// - likes is empty after filtering out Seed=true entries
//
// The "max" semantics means a single strong contextual match dominates
// over many weak ones — we want to surface the track because it was liked
// in *some* matching context, not because it was vaguely-liked in many.
func ContextualMatchScore(current SessionVector, likes []SessionVector, w SimilarityWeights) float64 {
if current.Seed {
return 0.0
}
best := 0.0
for _, l := range likes {
if l.Seed {
continue
}
s := Similarity(current, l, w)
if s > best {
best = s
}
}
return best
}