From ANN to Exact KNN on GPU: How We Rebuilt Candidate Retrieval in Ozon Recommendations

Ilya Osinovskov28 Jul 2026

Problem

Ozon recommends to tens of millions of users from hundreds of millions of items. Candidates came from an HNSW index on Spark, then a CatBoost model ranked them. ANN gives no guarantee of finding the true nearest neighbors, and recall drops for rare items and atypical users. Filters, penalties, ad masks and diversity lived outside the index, so the team had to build a pool of hundreds of billions of rows, and the feature-join stage alone ran up to 9–10 hours. Any change to the item base or the similarity required an index rebuild, which slowed experiments.

Example from the article: time-to-market of user2item selections for all users was about 30 hours.

Solution in brief

Replace the index with exact top-K search on GPU: multiply user embeddings by item embeddings and take the top items per user. Shard the item base, replicate the queries across GPUs, and select the top in CUDA kernels that already apply filters, quotas and diversity. A Triton service later added near real-time use.

Questions this case answers
  • How to replace an approximate nearest-neighbor index with exact top-K retrieval when the user and item sets are too large for naive brute force and business rules must be applied inside retrieval
  • How to move a daily batch candidate-generation pipeline toward near real-time serving without rebuilding an index
  • How to retrieve candidates for tens of millions of users from a catalog of hundreds of millions of items without losing recall on rare items?
  • How to apply filters, dislike penalties, ad masks and diversity quotas during retrieval instead of in heavy post-processing?

Tools and methods

  • Exact KNN on GPU — full brute-force scoring of every query against the whole base
  • PySpark, Hadoop, HDFS — daily data preparation
  • PyTorch — scoring and the first version of top-K
  • CUDA kernels (heap-based, segmented) — top-K with category quotas and masks
  • NVIDIA Triton Inference Server — online serving with item embeddings cached in GPU memory
Continue reading — it's free

Google or a one-time email code. No password.