Prompt
How do I build product recommendations for an ecommerce site?
Latest observation
To build product recommendations for an ecommerce site, start simple and evolve toward personalization.
1) Pick the recommendation use cases
Common placements:
- Homepage: trending, popular, personalized picks
- Product page: similar items, frequently bought together
- Cart/checkout: add-ons, accessories, complementary items
- Email/push: recently viewed, back-in-stock, replenishment
2) Collect the right data
You’ll usually need:
- Catalog data: product ID, category, brand, price, attributes, tags, availability
- User behavior: views, clicks, add-to-cart, purchases, search queries
- Context: time, device, location, referral source
- Feedback signals: returns, ratings, dislikes, skips
3) Start with baseline recommendation methods
These are easy to implement and often strong enough initially:
Popularity-based
Recommend top-selling or most-viewed items.
- Good for new users and homepage
- Easy fallback when you lack history
Rule-based / editorial
Example:
- “If user bought a laptop, recommend a laptop sleeve”
- “Show items from same category and price band”
Content-based
Recommend products similar to the one being viewed based on attributes/text:
- Category, brand, price, color, material, description embeddings
- Great for “similar products”
Collaborative filtering
Recommend based on behavior of similar users or item co-occurrence:
- “Users who bought X also bought Y”
- Works well once you have enough interaction data
4) Add personalization
Use each user’s:
- Browsing history
- Purchase history
- Preferred categories/brands
- Price sensitivity
- Recency/frequency of interactions
A simple approach:
- Score products by similarity to the user’s past interactions
- Combine with business rules like stock, margin, or promotion priority
5) Build candidate generation + ranking
A practical recommender often has two stages:
Candidate generation
Pull a few hundred likely items from:
- Similar products
- Popular items in user’s category
- Co-purchase graph
- Search/query matching
Ranking
Sort candidates using a model or scoring function with features like:
- User-item affinity
- Category match
- Price proximity
- Recency
- Inventory status
- Margin / promotion flag
6) Handle cold start
New user
Use:
- Popular items
- Trending by region/device
- Contextual recommendations
- Session-based behavior
New item
Use:
- Content-based features
- Category/brand/price similarity
- Exploration to collect interactions
7) Evaluate recommendations
Offline metrics:
- Precision@K / Recall@K
- NDCG@K
- MAP
- Coverage and diversity
Online metrics:
- CTR
- Add-to-cart rate
- Conversion rate
- Revenue per session
- Average order value
- Return rate
Always A/B test against a control.
8) Balance relevance with business goals
You may want to optimize for:
- Revenue
- Conversion
- Margin
- Inventory clearance
- Customer satisfaction
Common constraints:
- Don’t recommend out-of-stock items
- Avoid over-recommending discounted low-margin items if that hurts profit
- Ensure diversity so the list isn’t repetitive
9) Production architecture
Typical pipeline:
- Ingest events from site/app
- Update user/item profiles
- Generate candidates
- Rank them
- Filter by business rules
- Cache results for fast serving
- Log impressions/clicks/purchases for retraining
10) Recommended implementation path
If you’re starting from scratch:
- Popularity + category-based rules
- Co-purchase / “also bought”
- Content-based similarity
- Collaborative filtering
- Learning-to-rank / deep personalized model
11) Useful model choices
- Baseline: popularity, association rules
- Lightweight: matrix factorization, item-item similarity
- Mid-level: gradient boosted rankers
- Advanced: two-tower retrieval models, deep ranking models, sequence/session models
12) Don’t forget safeguards
- Deduplicate recommendations
- Respect privacy and consent
- Avoid recommending already purchased items unless relevant
- Add explainability where useful:
- “Because you viewed…”
- “Frequently bought with…”
If you want, I can also give you:
- a simple architecture diagram,
- a Python/SQL implementation, or
- a modeling approach for a small vs. large ecommerce site.