Affinity Engine — Two-Tower Neural Recommender System
The Problem
System Bottlenecks & Technical Friction
E-commerce catalogs with hundreds of thousands of SKUs require recommendation architectures that go beyond simple collaborative filtering or keyword matching. Matrix factorization models frequently generate stale suggestions and struggle with cold-start users and seasonal catalog shifts. E-commerce platforms need deep dual-tower neural retrieval that encodes user behavioral history and product semantics into low-dimensional vector spaces, serving sub-30ms recommendations at scale.
Our Engineering Approach
Architecture Design & Implementation
Affinity Engine is a two-tower neural retrieval architecture. The User Tower encodes session clickstream, purchase recency, and category preferences via a Transformer encoder. The Item Tower encodes product metadata, taxonomy hierarchy, and visual features into a shared 512-dimensional embedding space. At inference time, Pinecone executes sub-15ms approximate nearest neighbor (ANN) retrieval over precomputed item vectors, followed by a lightweight XGBoost model that re-ranks candidates for click and conversion probability.
Technical Architecture
System breakdown & stack.
Two-tower Transformer architecture: 6-layer user encoder + 6-layer item encoder, 340M parameters total
Trained on 840M user interaction events (clicks, add-to-cart, purchases) via batch-softmax contrastive loss
Ray distributed training on AWS SageMaker: 32-node GPU cluster, mixed-precision FP16, gradient checkpointing
Pinecone vector DB with 880K precomputed item embeddings, <15ms k-NN retrieval (k=200)
XGBoost reranking model for CTR/CVR prediction on top-200 candidates retrieved from Pinecone
Feast feature store: versioned user/item features, point-in-time correctness for backfill training
Redis embedding cache with 10-minute TTL for repeat user queries, 92% hit rate
FastAPI inference API with <25ms P95 latency for end-to-end user query → ranked recommendations
Engagement Timeline
Engineering delivery schedule.
User interaction data extraction, EDA, train/val/test splits, feature engineering research
Two-tower architecture design, PyTorch implementation, initial single-GPU training experiments
Ray distributed training setup on SageMaker, mixed-precision FP16, hyperparameter tuning
Pinecone vector DB deployment, item embedding precomputation, k-NN retrieval optimization
XGBoost reranking model, Feast feature store integration, FastAPI inference API build
A/B test on 10% traffic, latency profiling, gradual rollout to 100%, monitoring dashboards
More Case Studies
Related AI projects
Want results like these for your business?
Book a 30-minute scoping call with a senior engineer. We'll scope your AI project, define the architecture, and give you a fixed-price proposal within 5 business days.