Prompt
I'm building an ecommerce app and want to recommend similar products
Latest observation
A solid way to recommend similar products in an ecommerce app is to start with a simple “item-to-item similarity” approach, then improve it over time.
Good starting options
1. Content-based similarity
Recommend products that are similar based on their attributes:
- category
- brand
- price range
- color/material
- tags
- description embeddings
- image embeddings
Best for: new catalogs, cold start, explainable recommendations
Example: “Similar products” for a blue cotton t-shirt could be other blue cotton t-shirts in the same category.
2. Collaborative filtering
Recommend products users often view or buy together.
- “Customers also bought”
- “Frequently viewed together”
- based on clicks, carts, purchases
Best for: larger user base and interaction data
Limit: weak for new products with little history
3. Hybrid approach
Combine both content-based and collaborative methods.
Usually the best choice for ecommerce because it handles:
- new products
- sparse interaction data
- personalization
Practical implementation pattern
Step 1: Define product features
Store structured fields like:
category_idbrand_idpricetagsattributesdescriptionimage_url
Step 2: Convert to vectors
Create a vector representation for each product using:
- one-hot or embeddings for categorical fields
- normalized price
- text embeddings from description/title
- optional image embeddings
Step 3: Compute nearest neighbors
For a given product:
- find the closest products by cosine similarity or Euclidean distance
- filter out the same product
- optionally exclude out-of-stock items
- rank by similarity score and business rules
Step 4: Add business logic
Re-rank results based on:
- availability
- margin
- popularity
- price band
- diversity
- user preferences
Example recommendation flow
If a user is viewing a product:
- fetch its vector
- search for top 20 nearest products
- remove duplicates / exact variants if needed
- apply filters
- return top 4–8 recommendations
Metrics to evaluate
Track:
- CTR on recommended items
- add-to-cart rate
- conversion rate
- revenue per session
- diversity/coverage
- offline similarity quality if you have labeled data
Tools you can use
- Vector search: FAISS, Milvus, Pinecone, Weaviate, Elasticsearch kNN
- Embeddings: sentence-transformers, OpenAI embeddings, CLIP for images
- ML stack: scikit-learn, PyTorch, TensorFlow
Recommended MVP approach
If you want something practical fast:
- start with content-based similarity
- add popularity and availability filters
- later add collaborative signals from clicks/purchases
- move to a hybrid ranking model
If you want, I can also help you with:
- a database schema for product recommendations
- a Python example using embeddings + cosine similarity
- an architecture for real-time similar-product recommendations
- a production-ready ranking strategy