From ANN to Exact KNN on GPU: How We Rebuilt Candidate Selection for Ozon Recommendations
Ozon
Ozon's recommendation team replaced approximate nearest neighbor (ANN) search with exact K-nearest neighbors (KNN) on GPUs, embedding business logic directly into the computation to improve recall and flexibility. The new pipeline processes tens of millions of users and hundreds of millions of products daily, enabling real-time filtering and diversity control without costly post-processing.
The Ozon recommendation system serves tens of millions of users and hundreds of millions of products. Traditionally, candidate selection relied on approximate nearest neighbor (ANN) search using HNSW on Spark, followed by heavy post-processing with CatBoost ranking. However, ANN's approximate nature led to recall degradation on rare items, and the need to filter out unavailable or disliked products required massive intermediate data shuffles. The team implemented exact KNN on GPUs, performing a full brute-force search over all vectors. This allows embedding business logic—such as boolean masks for ad products, category-based dislikes, and user history filtering—directly into the GPU kernel, avoiding costly Spark jobs. The pipeline uses PySpark and PyTorch on Hadoop with dedicated GPU nodes. It supports sharding the item base and replicating queries across multiple GPUs, enabling efficient scaling. Custom similarity scoring via small neural networks allows combining multiple embeddings (e.g., ALS and neural) and mixing relevance with business signals like ad bids. The shift improved recall, reduced pipeline runtime by eliminating intermediate data writes, and enabled rapid experimentation.
- Сокращения
- ANN = Approximate Nearest Neighbor — приближённый поиск ближайшего соседа
- KNN = K-Nearest Neighbors — K ближайших соседей
- GPU = Graphics Processing Unit — графический процессор
- HNSW = Hierarchical Navigable Small World — иерархический навигационный малый мир
- ALS = Alternating Least Squares — чередующиеся наименьшие квадраты
- A/B = A/B testing — A/B-тестирование
- RFM = Recency, Frequency, Monetary — давность, частота, денежная ценность
- HDFS = Hadoop Distributed File System — распределённая файловая система Hadoop
- CPU = Central Processing Unit — центральный процессор
- API = Application Programming Interface — программный интерфейс приложения
Source: Habr — хаб ML —
original
