From cf8c943921b1c16ae1b98ff860b1dfec59da53c7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 19 Jul 2025 10:22:25 +0000 Subject: [PATCH] Optimize content-based algorithm for better item availability - Increase candidate item pool from 200 to 500 items for better selection - Lower scoring threshold from 0.1 to 0.05 to include more relevant items - Remove redundant stock status filtering in _apply_filters method - Content-based algorithm already pre-filters for in_stock items This should increase recommendations from 8 items to 15-20 items per page by expanding the pool of scored items while maintaining quality. --- app/recommendation_service_v2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/recommendation_service_v2.py b/app/recommendation_service_v2.py index 2074d0f..1de018d 100644 --- a/app/recommendation_service_v2.py +++ b/app/recommendation_service_v2.py @@ -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, @@ -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( @@ -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 @@ -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