Exclude all previously recommended songs from new discoveries - no more repeats

This commit is contained in:
root
2026-03-31 19:29:52 -05:00
parent 34eabf0fae
commit 5773870c91

View File

@@ -138,6 +138,14 @@ async def generate_recommendations(
profile = build_taste_profile(all_tracks) profile = build_taste_profile(all_tracks)
taste_context = f"Taste profile from {len(all_tracks)} tracks:\n{json.dumps(profile, indent=2)}" taste_context = f"Taste profile from {len(all_tracks)} tracks:\n{json.dumps(profile, indent=2)}"
# Load ALL previously recommended songs to exclude duplicates
prev_recs_result = await db.execute(
select(Recommendation.artist, Recommendation.title).where(
Recommendation.user_id == user.id,
)
)
previously_recommended = {f"{r.artist} - {r.title}".lower() for r in prev_recs_result.all()}
# Load disliked artists to exclude # Load disliked artists to exclude
disliked_result = await db.execute( disliked_result = await db.execute(
select(Recommendation.artist).where( select(Recommendation.artist).where(
@@ -204,6 +212,9 @@ IMPORTANT: If the user mentions specific artists or songs in their request, do N
Already in their library (do NOT recommend these): Already in their library (do NOT recommend these):
{', '.join(list(existing_tracks)[:50]) if existing_tracks else 'None provided'} {', '.join(list(existing_tracks)[:50]) if existing_tracks else 'None provided'}
ALREADY RECOMMENDED BEFORE (do NOT repeat any of these — every recommendation must be NEW):
{', '.join(list(previously_recommended)[:100]) if previously_recommended else 'None yet'}
{disliked_instruction} {disliked_instruction}
{exclude_instruction} {exclude_instruction}