feat: Improve radio algorithm to favor seed artist

- Increase weight for seed artist tracks from 3 to 6 (doubles probability)
- Reduce similar artists pool: 12 -> 8 artists, 40 -> 30 tracks per artist
- Force first track in artist radio to always be from the seed artist
- Force first track in track radio to always be the seed track itself
This commit is contained in:
vicrodh committed 2026-01-20 20:16:37 -06:00
1 parent 76d1ddd007
commit 484c27417a
3 files changed
+30 -8

No files matched your search

+27 -5
View File
@@ -52,10 +52,12 @@ pub async fn create_artist_radio(
let radio_engine = RadioEngine::new(radio_db);
let mut track_ids = Vec::new();
for _ in 0..15 {
// Generate up to 20 tracks to ensure we have options
for _ in 0..20 {
match radio_engine.next_track(&session_id) {
Ok(radio_track) => {
track_ids.push(radio_track.track_id);
track_ids.push((radio_track.track_id, radio_track.distance));
}
Err(e) => {
log::warn!("[Radio] Failed to get next radio track: {}", e);
@@ -63,7 +65,17 @@ pub async fn create_artist_radio(
}
}
}
Ok(track_ids)
// Ensure first track is from seed artist (distance 0)
if let Some(seed_idx) = track_ids.iter().position(|(_, dist)| *dist == 0) {
if seed_idx != 0 {
track_ids.swap(0, seed_idx);
log::info!("[Radio] Moved seed artist track to front (was at position {})", seed_idx);
}
}
// Take first 15 tracks and extract just the IDs
Ok(track_ids.into_iter().take(15).map(|(id, _)| id).collect())
}
})
.await
@@ -153,15 +165,25 @@ pub async fn create_track_radio(
// Generate track IDs from radio engine
let track_ids = task::spawn_blocking({
let session_id = session_id.clone();
let seed_track_id = track_id;
move || -> Result<Vec<u64>, String> {
let radio_db = crate::radio_engine::db::RadioDb::open_default()?;
let radio_engine = RadioEngine::new(radio_db);
let mut track_ids = Vec::new();
for _ in 0..15 {
// Start with the seed track itself
track_ids.push(seed_track_id);
log::info!("[Radio] First track will be the seed track: {}", seed_track_id);
// Generate 14 more tracks from the radio pool
for _ in 0..14 {
match radio_engine.next_track(&session_id) {
Ok(radio_track) => {
track_ids.push(radio_track.track_id);
// Skip if it's the seed track (already added)
if radio_track.track_id != seed_track_id {
track_ids.push(radio_track.track_id);
}
}
Err(e) => {
log::warn!("[Radio] Failed to get next radio track: {}", e);
+2 -2
View File
@@ -31,8 +31,8 @@ impl Default for BuildRadioOptions {
playlist_limit: 3,
playlist_track_limit: 200,
similar_artists_limit: 12,
similar_artist_tracks_limit: 40,
similar_artists_limit: 8,
similar_artist_tracks_limit: 30,
min_pool_size_for_second_degree: 80,
second_degree_artist_limit: 3,
+1 -1
View File
@@ -23,7 +23,7 @@ impl RadioEngine {
fn base_weight(distance: u8) -> u32 {
match distance {
0 => 3,
0 => 6,
1 => 3,
2 => 1,
_ => 0,