Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/recommendation_service_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ async def _get_content_based_recommendations(
"""
from app.algorithms.content_based import ContentBasedFilter

# Get candidate items from main database
# Get candidate items from main database - pre-filter for stock status
candidate_items_query = """
SELECT
id::text as item_id,
Expand All @@ -499,7 +499,7 @@ async def _get_content_based_recommendations(
AND user_id IS NULL
AND ($2::text[] IS NULL OR id::text != ALL($2::text[]))
ORDER BY created_at DESC
LIMIT 200
LIMIT 500
"""

candidate_items = await db.execute_main_query(
Expand All @@ -525,7 +525,7 @@ async def _get_content_based_recommendations(
scored_items = []
for item in candidate_items:
score = ContentBasedFilter.calculate_item_score(dict(item), user_profile_dict)
if score > 0.1: # Only include items with reasonable scores
if score > 0.05: # Lowered threshold to include more items
scored_items.append((item['item_id'], score))

# Sort by score and return top items
Expand Down Expand Up @@ -644,7 +644,8 @@ async def _apply_filters(
return item_ids

# Build filter conditions - cast UUIDs properly
filter_conditions = ["hp.id::text = ANY($1::text[])", "hp.geo_id = $2", "hp.status = 'in_stock'"]
# Note: stock status already filtered in candidate selection
filter_conditions = ["hp.id::text = ANY($1::text[])", "hp.geo_id = $2"]
filter_params = [item_ids, geo_id]
param_count = 2

Expand Down