feat(recommendation): add ContextualMatchScore (max over non-seed likes)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user