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)
This commit is contained in:
1 parent
1bb9fc8382
commit
ed1bd31554
4 files changed
+63
-9
No files matched your search
Generated
+2
-2
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -24,6 +24,28 @@ pub struct PlaylistArtist {
|
||||
pub qobuz_id: Option<u64>,
|
||||
}
|
||||
|
||||
/// 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) => {
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user