7d18a3c808
The taste recompute's tag facet now unions the cached track_tags (MusicBrainz/Last.fm folksonomy tags) alongside raw ID3 genre, so a coarse "Rock" gains "post-punk / shoegaze / melancholic". - taste_profile.sql: ListPlayEngagementInputsForUser + ListLikedTrackTasteInputsForUser now return track_id to key the enriched-tag lookup. - accumulate(): for each play, fold its track's enriched tags weighted by engagement × tag.weight × EnrichedTagScale; for each liked track, by the tag-like bonus × tag.weight × scale. A track with no cached tags contributes genre only (graceful). - New Config.EnrichedTagScale (default 0.5) — enriched tags augment the ID3 signal without swamping it; 0 = genre-only. Flows through recsettings.TasteConfig() (starts from DefaultConfig). Promoting it into the admin tuning lab is a small follow-up. Unit-tested the pure foldEnrichedTags helper (overlap accumulation + scale=0 disable). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
69 lines
2.4 KiB
SQL
69 lines
2.4 KiB
SQL
-- Taste profile (#796 phase 1). The daily build computes signed artist/tag
|
|
-- weights in Go (graded engagement + decay + like bonus) and atomic-replaces
|
|
-- them here. Read queries serve "top taste" lookups (used in phase 2).
|
|
|
|
-- name: ListPlayEngagementInputsForUser :many
|
|
-- One row per play in the decay-relevant window. completion is the play's
|
|
-- completion ratio (precomputed column when present, else duration_played /
|
|
-- track duration, clamped to [0,1]); age_days drives the time-decay. Genre
|
|
-- is split into tags in Go. Quarantined tracks are excluded.
|
|
SELECT
|
|
t.id AS track_id,
|
|
t.artist_id,
|
|
t.genre,
|
|
LEAST(GREATEST(
|
|
COALESCE(pe.completion_ratio,
|
|
pe.duration_played_ms::float8 / NULLIF(t.duration_ms, 0),
|
|
0), 0), 1)::float8 AS completion,
|
|
(EXTRACT(epoch FROM now() - pe.started_at) / 86400.0)::float8 AS age_days
|
|
FROM play_events pe
|
|
JOIN tracks t ON t.id = pe.track_id
|
|
WHERE pe.user_id = $1
|
|
AND pe.started_at > now() - ($2::float8 * INTERVAL '1 day')
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM lidarr_quarantine q
|
|
WHERE q.user_id = $1 AND q.track_id = t.id
|
|
);
|
|
|
|
-- name: ListLikedTrackTasteInputsForUser :many
|
|
-- (track_id, artist_id, genre) for each track the user has explicitly
|
|
-- liked. Feeds the track-like bonus into the liked track's artist and
|
|
-- tags; track_id keys the enriched track_tags lookup (#1490).
|
|
SELECT t.id AS track_id, t.artist_id, t.genre
|
|
FROM general_likes gl
|
|
JOIN tracks t ON t.id = gl.track_id
|
|
WHERE gl.user_id = $1;
|
|
|
|
-- name: ListLikedArtistIDsForUser :many
|
|
-- Artists the user has explicitly liked; feeds the artist-like bonus.
|
|
SELECT artist_id FROM general_likes_artists WHERE user_id = $1;
|
|
|
|
-- name: DeleteTasteProfileArtistsForUser :exec
|
|
DELETE FROM taste_profile_artists WHERE user_id = $1;
|
|
|
|
-- name: InsertTasteProfileArtist :exec
|
|
INSERT INTO taste_profile_artists (user_id, artist_id, weight)
|
|
VALUES ($1, $2, $3);
|
|
|
|
-- name: DeleteTasteProfileTagsForUser :exec
|
|
DELETE FROM taste_profile_tags WHERE user_id = $1;
|
|
|
|
-- name: InsertTasteProfileTag :exec
|
|
INSERT INTO taste_profile_tags (user_id, tag, weight)
|
|
VALUES ($1, $2, $3);
|
|
|
|
-- name: ListTasteProfileArtistsForUser :many
|
|
-- Top-weighted taste artists (phase-2 consumption + tests).
|
|
SELECT artist_id, weight
|
|
FROM taste_profile_artists
|
|
WHERE user_id = $1
|
|
ORDER BY weight DESC
|
|
LIMIT $2;
|
|
|
|
-- name: ListTasteProfileTagsForUser :many
|
|
SELECT tag, weight
|
|
FROM taste_profile_tags
|
|
WHERE user_id = $1
|
|
ORDER BY weight DESC
|
|
LIMIT $2;
|