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",
|
"name": "qbz-nix",
|
||||||
"version": "1.1.7",
|
"version": "1.1.8-rc-5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "qbz-nix",
|
"name": "qbz-nix",
|
||||||
"version": "1.1.7",
|
"version": "1.1.8-rc-5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^2",
|
"@tauri-apps/api": "^2",
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ pub struct SuggestionConfig {
|
|||||||
impl Default for SuggestionConfig {
|
impl Default for SuggestionConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
max_artists: 20,
|
max_artists: 30, // Increased from 20 for more variety
|
||||||
tracks_per_artist: 5,
|
tracks_per_artist: 6, // Increased from 5
|
||||||
max_pool_size: 100,
|
max_pool_size: 150, // Increased from 100
|
||||||
vector_max_age_days: 7,
|
vector_max_age_days: 7,
|
||||||
min_similarity: 0.1,
|
min_similarity: 0.1,
|
||||||
skip_vector_build: false,
|
skip_vector_build: false,
|
||||||
|
|||||||
@@ -24,6 +24,28 @@ pub struct PlaylistArtist {
|
|||||||
pub qobuz_id: Option<u64>,
|
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
|
/// Input for generating suggestions
|
||||||
#[derive(Debug, Clone, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Deserialize)]
|
||||||
pub struct SuggestionsInput {
|
pub struct SuggestionsInput {
|
||||||
@@ -100,12 +122,22 @@ pub async fn get_playlist_suggestions_v2(
|
|||||||
if mb_state.client.is_enabled().await {
|
if mb_state.client.is_enabled().await {
|
||||||
match mb_state.client.search_artist(&artist.name).await {
|
match mb_state.client.search_artist(&artist.name).await {
|
||||||
Ok(response) => {
|
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
|
if let Some(mb_artist) = response
|
||||||
.artists
|
.artists
|
||||||
.iter()
|
.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();
|
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
|
// Cache the resolved artist
|
||||||
let resolved = ResolvedArtist {
|
let resolved = ResolvedArtist {
|
||||||
mbid: Some(mbid.clone()),
|
mbid: Some(mbid.clone()),
|
||||||
@@ -123,6 +155,15 @@ pub async fn get_playlist_suggestions_v2(
|
|||||||
artist_info.push((mbid, artist.name.clone()));
|
artist_info.push((mbid, artist.name.clone()));
|
||||||
resolved_count += 1;
|
resolved_count += 1;
|
||||||
continue;
|
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) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -113,9 +113,10 @@
|
|||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
const VISIBLE_COUNT = 6;
|
const VISIBLE_COUNT = 6;
|
||||||
const INITIAL_POOL = 18; // 3 pages worth
|
const INITIAL_POOL = 30; // 5 pages worth (increased from 18)
|
||||||
const EXPANDED_POOL = 60; // Full pool on demand
|
const EXPANDED_POOL = 100; // Full pool on demand (increased from 60)
|
||||||
const MAX_POOL = 120; // Maximum pool for "load more variety"
|
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
|
// Track user interaction to detect when they want more variety
|
||||||
let completedCycles = $state(0); // How many times user cycled through all pages
|
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) {
|
async function loadSuggestions(expanded: boolean) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
log('Already loading, skipping');
|
log('Already loading, skipping');
|
||||||
|
|||||||
Reference in new issue
Block a user