From ed1bd315548220ae19ca12c47a8c45be8a9763d3 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Wed, 4 Feb 2026 19:34:52 -0600 Subject: [PATCH] fix(suggestions): improve pool management and artist identity validation - Increase pool sizes (INITIAL_POOL 18->30, EXPANDED_POOL 60->100, MAX_POOL 120->200) - Add auto-refresh when available tracks fall below threshold (MIN_AVAILABLE_THRESHOLD=12) - Add artist identity validation to filter incompatible genres (prevents merengue in metal playlists) - Log when artists are skipped due to incompatible disambiguation - Increase backend defaults (max_artists 20->30, tracks_per_artist 5->6, max_pool_size 100->150) --- package-lock.json | 4 +- src-tauri/src/artist_vectors/suggestions.rs | 6 +-- .../src/commands/playlist_suggestions.rs | 43 ++++++++++++++++++- src/lib/components/PlaylistSuggestions.svelte | 19 ++++++-- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index e1dcb59d2..69943842d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "qbz-nix", - "version": "1.1.7", + "version": "1.1.8-rc-5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "qbz-nix", - "version": "1.1.7", + "version": "1.1.8-rc-5", "license": "MIT", "dependencies": { "@tauri-apps/api": "^2", diff --git a/src-tauri/src/artist_vectors/suggestions.rs b/src-tauri/src/artist_vectors/suggestions.rs index 61f8db52e..f22f4c685 100644 --- a/src-tauri/src/artist_vectors/suggestions.rs +++ b/src-tauri/src/artist_vectors/suggestions.rs @@ -41,9 +41,9 @@ pub struct SuggestionConfig { impl Default for SuggestionConfig { fn default() -> Self { Self { - max_artists: 20, - tracks_per_artist: 5, - max_pool_size: 100, + max_artists: 30, // Increased from 20 for more variety + tracks_per_artist: 6, // Increased from 5 + max_pool_size: 150, // Increased from 100 vector_max_age_days: 7, min_similarity: 0.1, skip_vector_build: false, diff --git a/src-tauri/src/commands/playlist_suggestions.rs b/src-tauri/src/commands/playlist_suggestions.rs index b731ad69f..a2beb8925 100644 --- a/src-tauri/src/commands/playlist_suggestions.rs +++ b/src-tauri/src/commands/playlist_suggestions.rs @@ -24,6 +24,28 @@ pub struct PlaylistArtist { pub qobuz_id: Option, } +/// Genres that are typically incompatible with rock/metal playlists +/// Used to filter out false positives from name-only matching +const INCOMPATIBLE_GENRE_KEYWORDS: &[&str] = &[ + "merengue", "reggaeton", "salsa", "bachata", "cumbia", "vallenato", + "k-pop", "kpop", "j-pop", "jpop", "mandopop", "cantopop", + "schlager", "volksmusi", "chanson", + "country singer", "country music", + "gospel singer", "christian music", + "children", "nursery", +]; + +/// Check if an artist's disambiguation suggests an incompatible genre +fn has_incompatible_disambiguation(disambiguation: Option<&str>) -> bool { + match disambiguation { + Some(d) => { + let lower = d.to_lowercase(); + INCOMPATIBLE_GENRE_KEYWORDS.iter().any(|kw| lower.contains(kw)) + } + None => false, + } +} + /// Input for generating suggestions #[derive(Debug, Clone, serde::Deserialize)] pub struct SuggestionsInput { @@ -100,12 +122,22 @@ pub async fn get_playlist_suggestions_v2( if mb_state.client.is_enabled().await { match mb_state.client.search_artist(&artist.name).await { Ok(response) => { + // Find best match: high score AND compatible genre + // This prevents "Martín Méndez" (Opeth bassist) matching "Martin Mendez" (merengue singer) if let Some(mb_artist) = response .artists .iter() - .find(|a| a.score.unwrap_or(0) >= 90) + .filter(|a| a.score.unwrap_or(0) >= 90) + .find(|a| !has_incompatible_disambiguation(a.disambiguation.as_deref())) { let mbid = mb_artist.id.clone(); + log::debug!( + "[Suggestions] Resolved '{}' -> {} (score={}, disambiguation={:?})", + artist.name, + mb_artist.name, + mb_artist.score.unwrap_or(0), + mb_artist.disambiguation + ); // Cache the resolved artist let resolved = ResolvedArtist { mbid: Some(mbid.clone()), @@ -123,6 +155,15 @@ pub async fn get_playlist_suggestions_v2( artist_info.push((mbid, artist.name.clone())); resolved_count += 1; continue; + } else if let Some(skipped) = response.artists.iter().find(|a| { + a.score.unwrap_or(0) >= 90 && has_incompatible_disambiguation(a.disambiguation.as_deref()) + }) { + log::info!( + "[Suggestions] Skipped incompatible artist for '{}': {} (disambiguation: {:?})", + artist.name, + skipped.name, + skipped.disambiguation + ); } } Err(e) => { diff --git a/src/lib/components/PlaylistSuggestions.svelte b/src/lib/components/PlaylistSuggestions.svelte index 3775f3fd6..0c45f0d6e 100644 --- a/src/lib/components/PlaylistSuggestions.svelte +++ b/src/lib/components/PlaylistSuggestions.svelte @@ -113,9 +113,10 @@ // Configuration const VISIBLE_COUNT = 6; - const INITIAL_POOL = 18; // 3 pages worth - const EXPANDED_POOL = 60; // Full pool on demand - const MAX_POOL = 120; // Maximum pool for "load more variety" + const INITIAL_POOL = 30; // 5 pages worth (increased from 18) + const EXPANDED_POOL = 100; // Full pool on demand (increased from 60) + const MAX_POOL = 200; // Maximum pool for "load more variety" (increased from 120) + const MIN_AVAILABLE_THRESHOLD = 12; // Auto-refresh when available tracks fall below this // Track user interaction to detect when they want more variety let completedCycles = $state(0); // How many times user cycled through all pages @@ -177,6 +178,18 @@ } }); + // Auto-refresh when available tracks fall below threshold (pool exhaustion fix) + $effect(() => { + const availableCount = filteredPool.length; + const isPoolLow = availableCount < MIN_AVAILABLE_THRESHOLD && availableCount > 0; + const canExpand = hasLoadedOnce && !loading && !loadingMore && pool.length < MAX_POOL; + + if (isPoolLow && canExpand) { + log(`Pool running low (${availableCount} available), auto-expanding...`); + void handleLoadMoreVariety(); + } + }); + async function loadSuggestions(expanded: boolean) { if (loading) { log('Already loading, skipping');