Product Recommendations with Marqo
Build powerful recommendation systems that drive engagement and sales using Marqo's similarity-based recommendation API. This guide covers everything from basic implementation to advanced e-commerce strategies.
What is the Recommend API?
Marqo's recommend API finds products similar to existing items in your catalog by leveraging pre-computed embeddings. When you provide product IDs, the API interpolates their embeddings and searches for the most similar items—no real-time inference required, making it lightning-fast.
Perfect for:
- "Customers who bought this also bought" features
 - Product discovery and browsing
 - Personalized shopping experiences
 - Cross-selling and upselling
 - Similar item suggestions
 
đź“– API Reference: Complete Recommend API Documentation
Quick Start
Installation and Setup
import marqo
# Initialize your Marqo client
api_key = "your_api_key"
mq = marqo.Client("https://api.marqo.ai", api_key=api_key)
Basic Single Product Recommendations
# Find products similar to one item
results = mq.index("product-catalog").recommend(documents=["sku_38702"], limit=10)
# Display results
for hit in results["hits"]:
    print(f"Product: {hit['title']} (Score: {hit['_score']:.3f})")
Multi-Product Recommendations
# Get recommendations based on multiple products
# Useful for shopping cart or browsing history
results = mq.index("product-catalog").recommend(
    documents=["sku_39329", "sku_29472", "sku_30933"], limit=10
)
Advanced Features
Weighted Recommendations
Control the influence of different products using weights. Higher weights mean more influence on the final recommendations.
# Weighted recommendations for personalized experiences
results = mq.index("product-catalog").recommend(
    documents={
        "sku_39329": 3.0,  # Recently viewed - high influence
        "sku_29472": 2.0,  # Added to cart - medium influence
        "sku_30933": 1.0,  # Quick browse - low influence
    },
    limit=10,
)
E-commerce Use Cases
"Customers Also Bought" Recommendations
# Show similar products on product pages
results = mq.index("product-catalog").recommend(
    documents=["sku_38702"],
    limit=6,
    exclude_input_documents=True,
    attributes_to_retrieve=["title", "price", "image_url", "rating"],
)
Shopping Cart Recommendations
# Suggest complementary items based on cart contents
results = mq.index("product-catalog").recommend(
    documents=["laptop_123", "mouse_456"],
    limit=5,
    filter="category:(accessories OR supplies) AND in_stock:true",
)
Personalized Recommendations
user_history = {"recent_view_123": 3.0, "purchased_456": 2.0, "browsed_789": 1.0}
results = mq.index("product-catalog").recommend(documents=user_history, limit=10)