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
@@ -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) => {
|
||||
|
||||
Reference in new issue
Block a user