Description
/recommend-events uses a toy user-based collaborative filter on a 4-user mock dict. The algorithm counts user-pair overlaps but ignores event popularity, recency, or ticket availability. Item-based similarity (events that are frequently bought together) is more robust for cold-start users and scales better.
Requirements & context
- Implement
build_item_similarity_matrix(user_events_dict) in a new src/recommender.py using cosine similarity between event co-occurrence vectors
- Replace the current scoring loop in
/recommend-events with a call to get_item_recommendations(user_id, user_events_dict, similarity_matrix, top_n=3)
- The function must handle cold-start: if the user has no purchase history, return the 3 most popular events (highest total purchase count)
- The
user_events_dict should come from the DB (real user scan/purchase history) not the mock — use get_user_events_from_db from the earlier search fix
- Write unit tests with a known similarity matrix asserting correct top-3 output
Suggested execution
git checkout -b feat/item-based-recommendation
- Create
src/recommender.py
- Update
src/main.py /recommend-events handler
- Write tests
Guidelines
- Do not use numpy for this — pure Python dict-based cosine similarity is sufficient and avoids a heavy dependency
- PR must include:
Closes #[issue_id]
- Timeframe: 72 hours
Description
/recommend-eventsuses a toy user-based collaborative filter on a 4-user mock dict. The algorithm counts user-pair overlaps but ignores event popularity, recency, or ticket availability. Item-based similarity (events that are frequently bought together) is more robust for cold-start users and scales better.Requirements & context
build_item_similarity_matrix(user_events_dict)in a newsrc/recommender.pyusing cosine similarity between event co-occurrence vectors/recommend-eventswith a call toget_item_recommendations(user_id, user_events_dict, similarity_matrix, top_n=3)user_events_dictshould come from the DB (real user scan/purchase history) not the mock — useget_user_events_from_dbfrom the earlier search fixSuggested execution
src/recommender.pysrc/main.py/recommend-eventshandlerGuidelines
Closes #[issue_id]