Tutorial: Build a Smart Product Catalog
Overview
Build an intelligent product catalog that understands natural language queries, provides personalized recommendations, and automatically enriches product data. By the end, you'll have a fully functional e-commerce search system that outperforms traditional keyword-based searches.
Time Required: 15 minutes Difficulty: Beginner Prerequisites: SynapCores account, Basic programming knowledge
What You'll Learn
- Creating AI-enhanced collections
- Inserting products with automatic enrichment
- Natural language product search
- Building recommendation systems
- Real-time personalization
- Performance optimization
Step 1: Create Your Product Collection
First, let's create a collection with AI capabilities enabled:
curl -X POST https://api.synapcores.com/v1/collections \
-H "Authorization: Bearer $YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "products",
"schema": {
"ai_enabled": true,
"fields": {
"sku": {"type": "string", "primary_key": true},
"name": {"type": "text", "semantic": true},
"description": {"type": "text", "semantic": true, "extract_entities": true},
"category": {"type": "string", "auto_classify": true},
"price": {"type": "float"},
"brand": {"type": "string"},
"features": {"type": "array", "items": {"type": "string"}},
"image_url": {"type": "string"},
"in_stock": {"type": "boolean"},
"rating": {"type": "float"},
"review_count": {"type": "integer"}
},
"indexes": [
{"fields": ["category", "price"], "type": "compound"},
{"fields": ["brand"], "type": "hash"},
{"fields": ["embedding"], "type": "vector", "algorithm": "hnsw"}
],
"ai_config": {
"embedding_model": "all-MiniLM-L6-v2",
"auto_generate_tags": true,
"extract_colors": true,
"sentiment_from_reviews": true
}
}
}'
Step 2: Load Sample Products
Let's add some products. SynapCores will automatically:
- Generate embeddings for semantic search
- Extract entities and features
- Classify products into categories
- Generate tags
import requests
import json
API_URL = "https://api.synapcores.com"
headers = {
"Authorization": f"Bearer {YOUR_API_TOKEN}",
"Content-Type": "application/json"
}
# Sample products
products = [
{
"sku": "LAPTOP-001",
"name": "TechPro Ultra 15",
"description": "High-performance laptop with 15.6\" 4K display, Intel i9 processor, 32GB RAM, and NVIDIA RTX 4080. Perfect for gaming, content creation, and professional work.",
"price": 1999.99,
"brand": "TechPro",
"features": ["4K Display", "32GB RAM", "1TB SSD", "RTX 4080"],
"in_stock": True,
"rating": 4.8,
"review_count": 256
},
{
"sku": "SHOES-001",
"name": "CloudRunner Pro",
"description": "Professional running shoes with advanced cushioning technology. Breathable mesh upper, responsive midsole, and durable rubber outsole.",
"price": 149.99,
"brand": "RunTech",
"features": ["Breathable Mesh", "Responsive Cushioning", "Arch Support"],
"in_stock": True,
"rating": 4.6,
"review_count": 1823
},
{
"sku": "CAMERA-001",
"name": "SnapMaster Pro X",
"description": "Professional mirrorless camera with 45MP full-frame sensor, 8K video recording, and advanced AI autofocus. Weather-sealed body.",
"price": 3499.99,
"brand": "SnapMaster",
"features": ["45MP Sensor", "8K Video", "AI Autofocus", "Weather Sealed"],
"in_stock": True,
"rating": 4.9,
"review_count": 89
}
]
# Insert products
for product in products:
response = requests.post(
f"{API_URL}/v1/collections/products/documents",
headers=headers,
json=product
)
print(f"Inserted {product['name']}: {response.status_code}")
Step 3: Natural Language Search
Now let's search using natural language instead of keywords:
Example 1: Vague Requirements
# Traditional search would fail with vague queries
query = "something for my morning jog that won't break the bank"
response = requests.post(
f"{API_URL}/v1/collections/products/search",
headers=headers,
json={
"query": query,
"limit": 5,
"explain": True
}
)
results = response.json()
for product in results["results"]:
print(f"{product['name']} - ${product['price']}")
print(f" Relevance: {product['_score']:.2f}")
print(f" Why matched: {product['_explanation']}")
# Returns: CloudRunner Pro, FitTrack Ultra
Example 2: Technical Requirements
# Complex technical search
query = "high-end device for content creation with good display"
response = requests.post(
f"{API_URL}/v1/collections/products/search",
headers=headers,
json={
"query": query,
"filters": {"in_stock": True},
"boost": {
"rating": 1.5,
"price": -0.5
}
}
)
# Returns: TechPro Ultra 15, SnapMaster Pro X
Example 3: Multi-language Support
# SynapCores understands queries in multiple languages
queries = [
"portable computer for students", # English
"ordinateur portable pour etudiants", # French
"laptop para estudiantes", # Spanish
]
for query in queries:
response = requests.post(
f"{API_URL}/v1/collections/products/search",
headers=headers,
json={"query": query, "limit": 1}
)
result = response.json()["results"][0]
print(f"{query} -> {result['name']}")
# All return: TechPro Ultra 15