/
/
/
1"""Module-level constants for the Sonic Similarity plugin."""
2
3from __future__ import annotations
4
5from music_assistant_models.enums import ProviderFeature
6
7USEARCH_INDEX_FILENAME_TPL = "sonic_signatures_{domain}_v{version}.usearch"
8USEARCH_INDEX_FILENAME_GLOB = "sonic_signatures_{domain}_v*.usearch"
9
10# Source AA provider; hardcoded since manifest depends_on already forecloses any other.
11AA_PROVIDER_DOMAIN = "sonic_analysis"
12
13CONF_ENABLE_CLAP_INDEX = "enable_clap_index"
14CONF_ENABLE_TEXT_SEARCH = "enable_text_search"
15CONF_ENABLE_DISCOVER_ROW = "enable_discover_row"
16CONF_DISCOVER_PRESET = "discover_preset"
17CONF_DISCOVER_DIVERSITY = "discover_diversity"
18EXTRA_DATA_CLAP_EMBEDDING = "clap_embedding"
19
20# Engine for the SIMILAR_TRACKS hook; CLAP option offered only when its index is enabled.
21CONF_SIMILAR_TRACKS_ENGINE = "similar_tracks_engine"
22SIMILAR_ENGINE_18DIM = "18dim"
23SIMILAR_ENGINE_CLAP = "clap"
24
25# 18-dim SIMILAR_TRACKS tuning; shown only when the 18-dim engine is selected.
26CONF_SIMILAR_PRESET = "similar_tracks_preset"
27CONF_SIMILAR_DIVERSITY = "similar_tracks_diversity"
28
29# Engine for the discover-row recommendations; mirrors the SIMILAR_TRACKS selector.
30CONF_DISCOVER_ENGINE = "discover_engine"
31
32CONF_LABEL_STATUS_18DIM = "status_label_18dim"
33CONF_LABEL_STATUS_CLAP = "status_label_clap"
34CONF_LABEL_STATUS_TEXT = "status_label_text"
35ACTION_REBUILD_18DIM = "rebuild_18dim_index"
36ACTION_REBUILD_CLAP = "rebuild_clap_index"
37
38PERIODIC_REFRESH_TASK_ID = "sonic_similarity_periodic_refresh"
39PERIODIC_REFRESH_INTERVAL_HOURS = 1
40
41SUPPORTED_FEATURES = {
42 ProviderFeature.SIMILAR_TRACKS,
43 ProviderFeature.RECOMMENDATIONS,
44}
45
46# get_recommendation_items() folder tunables: seed fan-out bound and visible row length.
47RECOMMEND_SEED_COUNT: int = 5
48RECOMMEND_PER_SEED_LIMIT: int = 10
49RECOMMEND_ITEM_LIMIT: int = 12
50
51# Scales genre/year rerank bonus down to the audio-distance range so it nudges, not dominates.
52METADATA_BONUS_SCALE: float = 0.1
53
54# Group weights match FEATURE_GROUPS in vectors.py; `genre`/`era` are rerank-only knobs.
55# Weights are deliberately non-uniform (tuned by per-group informativeness), not all 1.0.
56SIMILARITY_PRESETS: dict[str, dict[str, float]] = {
57 "balanced": {
58 "rhythm": 0.77,
59 "loudness": 0.55,
60 "timbre": 0.47,
61 "regularity": 0.38,
62 "mood": 1.0,
63 "tonal": 0.17,
64 "dynamics": 0.38,
65 "genre": 0.6,
66 "era": 0.2,
67 },
68 "vibe": {
69 "rhythm": 0.15,
70 "loudness": 0.4,
71 "timbre": 0.6,
72 "regularity": 0.0,
73 "mood": 1.0,
74 "tonal": 0.0,
75 "dynamics": 0.4,
76 "genre": 0.4,
77 "era": 0.15,
78 },
79 "party": {
80 "rhythm": 1.0,
81 "loudness": 0.6,
82 "timbre": 0.15,
83 "regularity": 0.7,
84 "mood": 0.25,
85 "tonal": 0.0,
86 "dynamics": 0.2,
87 "genre": 0.3,
88 "era": 0.1,
89 },
90 "genre_era": {
91 "rhythm": 0.5,
92 "loudness": 0.4,
93 "timbre": 0.4,
94 "regularity": 0.3,
95 "mood": 0.7,
96 "tonal": 0.1,
97 "dynamics": 0.3,
98 "genre": 1.0,
99 "era": 0.9,
100 },
101 "discover": {
102 "rhythm": 0.7,
103 "loudness": 0.4,
104 "timbre": 0.3,
105 "regularity": 0.2,
106 "mood": 0.9,
107 "tonal": 0.0,
108 "dynamics": 0.25,
109 "genre": 0.25,
110 "era": 0.1,
111 },
112}
113