Clustering billions of products for agentic commerce with Catalog API

Mariya Mansurova17 Jun 2026

Problem

Shopify hosts billions of product listings from millions of merchants, and each merchant models products in its own way. One sells a protein powder as one listing with flavor variants, another makes a listing per flavor. An AI shopping agent has to treat both as the same product line. Precision failures merge different products. Recall failures leave a variant outside its cluster, so it looks like a duplicate or cannot be found.

Example from the article: a buyer asks for women's sneakers and receives the men's pair, because both were merged under one product identifier.

Solution in brief

Product identity is defined by one question: what is the buyer primarily purchasing this product for? An attribute that does not change the answer is a variant. Rules first remove shops that need no clustering. The rest are split into chunks of up to 200 similar products, and a two-stage LLM flow proposes clusters, then flags outliers. A strict JSON schema generated per chunk guarantees every product gets a label.

Questions this case answers
  • How to group records that describe the same real-world item when sources model them differently and the record set is too large for one model context
  • How to force an LLM to return a complete, well-formed label for every item in a large batch
  • How to group product listings from merchants with different catalog structures under one product identity?
  • How to make an LLM label every item in a large batch without skipping or inventing items?

Tools and methods

  • Core value proposition test — separates variants from distinct products
  • Singleton detector — skips clustering for shops without variant grouping
  • HNSW (FAISS) and sparse average linkage — build chunks of related products
  • Two-stage LLM flow — assigns brand and model, then flags outliers
  • OpenAI Structured Output — strict per-chunk JSON schema
  • Labeled sets and LLM judges — measure precision and recall
Continue reading — it's free

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