Skip to content

Commit 12b895a

Browse files
refactor: update strong signal item percentage and simplify scoring parameters
1 parent 51e0be6 commit 12b895a

File tree

5 files changed

+7
-27
lines changed

5 files changed

+7
-27
lines changed

app/services/profile/sampling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def sample_items(
6969
if not (it.get("_is_loved") or it.get("_is_liked") or it.get("_id") in added_item_ids)
7070
]
7171

72-
# Always include strong signal items: Loved/Liked: 30%, Added: 20%
73-
strong_signal_items = loved_liked_items[: int(max_items * 0.45)] + added_items[: int(max_items * 0.20)]
72+
# Always include strong signal items: Loved/Liked: 40%, Added: 20%
73+
strong_signal_items = loved_liked_items[: int(max_items * 0.40)] + added_items[: int(max_items * 0.20)]
7474
strong_signal_scored = [self.scoring_service.process_item(it) for it in strong_signal_items]
7575

7676
# Score watched items and sort by score

app/services/recommendation/all_based.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ async def get_recommendations_from_all_items(
119119
profile=profile,
120120
scorer=self.scorer,
121121
mtype=mtype,
122-
is_ranked=False,
123-
is_fresh=False,
124122
)
125123

126124
# Apply genre multiplier (if whitelist available)

app/services/recommendation/scoring.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,15 @@ def m_raw(year: int | None) -> float:
9292
return m_raw, alpha
9393

9494
@staticmethod
95-
def apply_quality_adjustments(
96-
score: float, wr: float, vote_count: int, popularity: float, is_ranked: bool, is_fresh: bool
97-
) -> float:
95+
def apply_quality_adjustments(score: float, wr: float, vote_count: int, popularity: float) -> float:
9896
"""Apply simple quality boost for high-confidence items only."""
99-
# Simplified: only boost proven high-quality items, no penalties
100-
# Trust the weighted rating formula to handle low vote counts naturally
10197
if vote_count >= 1000 and wr >= 7.5 and popularity <= MAXIMUM_POPULARITY_SCORE:
10298
# Proven gem: high confidence, high quality
10399
return score * 1.10
104100
elif vote_count >= 500 and wr >= 7.0 and popularity <= MAXIMUM_POPULARITY_SCORE:
105101
# Good confidence and quality
106102
return score * 1.05
107103

108-
# Everything else: trust the base scoring
109104
return score
110105

111106
@staticmethod
@@ -114,8 +109,6 @@ def calculate_final_score(
114109
profile: Any,
115110
scorer: Any,
116111
mtype: str,
117-
is_ranked: bool = False,
118-
is_fresh: bool = False,
119112
) -> float: # noqa: E501
120113
"""
121114
Calculate final recommendation score combining profile similarity and quality.
@@ -125,8 +118,6 @@ def calculate_final_score(
125118
profile: User taste profile
126119
scorer: ProfileScorer instance
127120
mtype: Media type (movie/tv) to determine minimum rating
128-
is_ranked: Whether item is from ranked source
129-
is_fresh: Whether item should get freshness boost
130121
minimum_rating_tv: Minimum rating constant for TV
131122
minimum_rating_movie: Minimum rating constant for movies
132123
@@ -155,8 +146,6 @@ def calculate_final_score(
155146
# light boost for high-confidence items (no penalties!)
156147
vote_count = item.get("vote_count", 0)
157148
popularity = item.get("popularity", 0)
158-
final_score = RecommendationScoring.apply_quality_adjustments(
159-
base_score, wr, vote_count, popularity, is_ranked=is_ranked, is_fresh=is_fresh
160-
)
149+
final_score = RecommendationScoring.apply_quality_adjustments(base_score, wr, vote_count, popularity)
161150

162151
return final_score

app/services/recommendation/theme_based.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ async def get_recommendations_for_theme(
111111
profile=profile,
112112
scorer=self.scorer,
113113
mtype=mtype,
114-
is_ranked=False,
115-
is_fresh=False,
116114
)
117115

118116
# Apply genre multiplier (if whitelist available)

app/services/recommendation/top_picks.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import time
23
from collections import defaultdict
34
from datetime import date, datetime, timedelta
45
from typing import Any
@@ -17,6 +18,7 @@
1718
)
1819
from app.services.profile.sampling import SmartSampler
1920
from app.services.profile.scorer import ProfileScorer
21+
from app.services.recommendation.filtering import RecommendationFiltering
2022
from app.services.recommendation.metadata import RecommendationMetadata
2123
from app.services.recommendation.scoring import RecommendationScoring
2224
from app.services.recommendation.utils import content_type_to_mtype, filter_watched_by_imdb, resolve_tmdb_id
@@ -70,7 +72,6 @@ async def get_top_picks(
7072
Returns:
7173
List of recommended items
7274
"""
73-
import time
7475

7576
start_time = time.time()
7677

@@ -98,15 +99,11 @@ async def get_top_picks(
9899
scored_candidates = []
99100
for item in filtered_candidates:
100101
try:
101-
is_ranked = item.get("_ranked_candidate", False)
102-
is_fresh = item.get("_fresh_boost", False)
103102
final_score = RecommendationScoring.calculate_final_score(
104103
item=item,
105104
profile=profile,
106105
scorer=self.scorer,
107106
mtype=mtype,
108-
is_ranked=is_ranked,
109-
is_fresh=is_fresh,
110107
)
111108
scored_candidates.append((final_score, item))
112109
except Exception as e:
@@ -214,8 +211,6 @@ async def _fetch_discover_with_profile(
214211
Returns:
215212
List of candidate items
216213
"""
217-
# Get excluded genres
218-
from app.services.recommendation.filtering import RecommendationFiltering
219214

220215
excluded_genre_ids = RecommendationFiltering.get_excluded_genre_ids(self.user_settings, content_type)
221216
without_genres = "|".join(str(g) for g in excluded_genre_ids) if excluded_genre_ids else None
@@ -371,7 +366,7 @@ def _apply_diversity_caps(
371366
Apply diversity caps to ensure balanced results.
372367
373368
Caps:
374-
- Recency: max 15% from items released in last 6 months
369+
- Recency: max 15% from items released in last year
375370
- Genre: max 50% per genre
376371
- Creator: max 3 items per creator
377372
- Era: max 50% per era

0 commit comments

Comments
 (0)