The Shopify Catalog is a unified intelligence layer that standardizes product data across the platform and exposes it to developers and AI agents through the Catalog API. Product clustering sits at its core, since merchants may structure the same real-world item in radically different ways — one creating a single product with all size and color variants, another splitting each color into its own product. Grouping these related variants and products under one Universal Product Identifier (the UPID field in the Catalog API) means any version of the same item lives under one roof, regardless of how the merchant organized their listings.

Part I of this series covered grouping related listings within a single store under a UPI. The harder question for the Catalog is how to know that different merchants are selling the same product or its variants. Cross-store clustering answers it, bringing listings of the same product across merchants together under a single, global UPI.

The intra-store approach does not port over directly. Inside one store, the merchant’s own catalog is context: how they name products, describe brands, and separate models from variants. Across stores those conventions diverge. Titles and descriptions differ, the same product is photographed differently, and key details land in different fields — a model number in one merchant’s title may sit in another’s description. Barcodes can help but are neither consistently available nor reliable. The search space is unbounded as well: matches for a product may live in any other store, so we cannot partition the problem by merchant, compare every possible pair, or afford to lump together products that should stay distinct.

Pairwise judgments instead of global labels

Rather than having an LLM assign globally consistent product labels, we pose a narrower question: should these two product listings belong to the same UPI? A model can compare titles, images, options, and other metadata without requiring independent model calls to produce identical labels for the same product. Pairwise comparisons also need no pre-existing catalog of reliable global clusters — we gather matching evidence first and build the clusters from it. The judgments can still be non-transitive: the model may match A with B and B with C while rejecting A with C, which rules out simple approaches like connected components and calls for more advanced clustering algorithms.

The system is organized around three steps: find plausible pairs, score each pair, and turn those scores into clusters.

Finding plausible pairs

Candidate generation starts from embeddings of products, with approximate nearest-neighbor search retrieving nearby listings for each product. Searching billions of vectors instead of one merchant’s catalog forces a balance among retrieval quality, index size, and search throughput. Approximate search keeps the computation practical, but both the approximation and the shortlist limit can leave true matches out of the candidate pool, so those pairs never reach the matching models. A missed match does not remove a product from Catalog — the listing remains searchable under its own identifier — it simply isn’t grouped with other stores’ listings until a later build finds the connection.

Retrieval narrows the search sharply, but it still leaves trillions of candidate pairs, and proximity in embedding space is not proof that two listings represent the same product.

Scoring each pair

A capable LLM can reason about these comparisons using the product information and our definition of product identity, but evaluating trillions of pairs with it would be far too expensive. Instead, we use an LLM judge to label sampled comparisons and validate its judgments against human annotations, then train specialized matching models on the LLM-generated labels. Scores from stronger models also supply training signal for cheaper ones, so expensive reasoning yields reusable training data rather than being paid for on every comparison. Three pair scorers — L1, L2, and L3 — differ in capability and inference cost; we collect their scores for the cluster builder and route the more expensive comparisons through background queues.

From scores to clusters

Products become graph nodes and scored relationships become edges, but we cannot simply group everything connected by a path, since one incorrect connection could join two otherwise unrelated product groups. We first partition the graph into bounded-by-size components that can be processed independently; these are computational work units, not final product identities. The UPI builder then evaluates proposed cluster merges with a trained model that weighs evidence for and against each merge, not just the score of the pair that triggered the proposal.

Cross-store clustering pipeline

Three scorers, three jobs

Running every candidate pair through the richest model would be too expensive, while relying only on the cheapest would miss distinctions that need closer inspection. The work is divided accordingly:

  • L1 provides fast, feature-based scoring across a large set of candidate pairs
  • L2 evaluates both listings’ text together
  • L3 adds images and richer metadata for selected comparisons

L1: the inexpensive first pass

L1 is a GBDT classifier over inexpensive pair features, including embedding distances, title and vendor similarity, and price relationships. It evaluates trillions of candidate pairs without running a neural cross-encoder on each one. L1 serves two related but distinct purposes: supplying fast matching evidence, and deciding which candidates deserve more expensive attention. A pair can merit a stronger model even when L1’s score alone is insufficient evidence for a merge; keeping that distinction lets us trade the cost of additional model calls against the chance of finding more true matches.

L2: joint text encoding

L2 is a fine-tuned multilingual E5 cross-encoder. It reads both listings jointly — titles, vendor names, predicted categories, URLs, and shop names — so it can attend to differences between the two inputs rather than relying only on separately generated embeddings. That matters when most of the text agrees but one detail changes identity: two phone-case listings can share a brand and product line and still differ, as in "for iPhone 15" versus "for iPhone 15 Pro." Joint encoding lets L2 weigh that short compatibility suffix against the long stretch of matching brand and product-line text instead of letting overall similarity swamp it.

The limitation lies in the inputs: L2 reads many fields, but not descriptions. When the distinguishing detail appears only in a description, L2 has nothing to find and the pair looks like a match — part of the reason selected pairs go on to L3, which can look for the difference in the images. Joint encoding handles the higher-precision decision, while independent embeddings remain central to retrieval.

L3: images in the decision

L3 is a fine-tuned open model reranker that sees product images alongside text and metadata. Images carry evidence text may omit — a different connector, button layout, or case cutout — but they also introduce ambiguity, since two merchants may photograph the same item from different angles, so the model must interpret them in context rather than compare pixels. L3 returns a match score, not a generated explanation: at serving time the cluster builder needs a score, and the more expensive reasoning belongs in the training-data pipeline.

Labels for sampled examples come from a larger LLM judge, whose scores also provide training signal for cheaper models. We validate the judge against human annotations because its errors can propagate into the models trained on its labels.

The levels supply complementary evidence, but their scores are not directly interchangeable. Thresholds are set separately per scorer, and we evaluate their combined effect on clustering — better pair scores only matter insofar as they produce better product groups.

Intra-store groups as input

The pipeline from Part I was not built to be retired in Part II: intra-store groups provide candidate relationships for the cross-store system. Looking beyond a single store adds evidence from other merchants about which products belong together, and the UPI builder weighs intra-store relationships alongside this broader evidence rather than carrying each group forward unchanged. The earlier work keeps its value while final clusters benefit from information unavailable within one store alone.

Bounding component size

We split the graph into components small enough for the UPI builder to process on a single machine, so different components can be processed independently and in parallel. Deciding where to split is the difficulty. Random division would separate many valid matches, while ordinary connected components keep connected products together but can yield components too large to process efficiently. The aim is to keep as many true matches as possible inside the same component while capping component size.

A single-machine bounded union-find

We use a bounded version of union-find, which tracks the component each product belongs to:

  • Start with every product in its own component.
  • Process edges from highest to lowest score.
  • If an edge’s endpoints are already in the same component, skip it. Otherwise merge their components if the combined result stays within the budget.

The budget is measured by the sum of the products’ degrees — the number of connections attached to them — rather than product count alone, since a densely connected group requires more work than a similarly sized group with few connections. Stronger connections are therefore considered first, and no merge may grow a component past the budget.

Parallel edge processing

On one machine, processing the full edge set becomes a bottleneck. We divide the edges among parallel workers; each uses ordinary union-find to remove redundant connections within its partition. If three products form a triangle, for instance, a worker can discard one edge without breaking connectivity, retaining connecting edges and producing a spanning forest instead of forwarding the full edge list. The workers’ forests are then combined and the bounded merge algorithm runs over that reduced set, again in score order.

The forests preserve connectivity but do not guarantee the same bounded components that processing every edge would produce, and the size budget still uses connection counts from the original graph rather than the reduced forests. Workers carry the bulk of edge processing in parallel while the final pass enforces a shared component-size limit, after which the components are handed to independent UPI-builder workers.

Bounded components

Clustering inside bounded components

Once the graph has been cut into bounded components, a catalog-wide matching problem becomes many independent, smaller ones. Each component fits on a single machine, and distinct components can run in parallel, so the UPI builder never has to coordinate individual merge decisions across machines.

Inside a component, the builder applies hierarchical agglomerative clustering (HAC) driven by a learned merge rule, progressively folding smaller clusters into larger ones. A GBDT model scores every proposed merge, with the objective of placing as many matching listings as possible under one UPI without ever combining distinct products. Precision comes first here: a wrong merge can contaminate two entire product groups, while a rejected valid merge merely leaves groups separate. The acceptance threshold is therefore tuned for precision, and recall is then maximized within that constraint.

Scoring merges from edge evidence

Edges already carry a type and a score assigned by the upstream scorers, summarizing comparisons of titles, brands, categories, images, and other metadata. The type records where the evidence came from and its confidence level. The builder reuses these predictions instead of re-reading product data for every proposal, combining them into a cluster-level verdict on whether two groups should join.

The GBDT model operates on features that describe both clusters and their potential union:

  • Support: the number of edges linking the clusters and how dense those links are relative to cluster size.
  • Coverage: whether connections touch many products on both sides or concentrate on one or two.
  • Cohesion: how strongly products connect within each cluster versus outward.
  • Contradiction: the volume of low-scoring L2 or L3 evidence opposing the union.

These features are computed per edge type, so strong matches remain distinguishable from negative judgments. The result is a compact view of the relationship between the groups rather than just the score of the pair that triggered the proposal.

A strong pair is evidence

Training on the policy's own output

Assembling the training set required several iterations, because each new model shifts which merges are accepted, which reshapes the intermediate clusters, and which situations the policy later faces. Labels gathered under a prior policy do not fully cover those new situations. The team cycled through running the builder, sampling its merge proposals, labeling them with the LLM judge, and retraining, deliberately gathering both acceptable and unacceptable merges rather than teaching the model to imitate the earlier builder. Graph changes compound the problem: incoming scores and departing products alter cluster densities and connections, so graph-derived training features must be refreshed alongside new labels. Fresh proposals are now collected and the model retrained on a regular cadence, keeping the data aligned with both builder behavior and the evolving catalog.

Refreshing evidence as the catalog changes

New products appear, merchants revise titles and images, and formerly unrelated listings become plausible matches, so candidate pairs must be continually evaluated and existing scores refreshed when product information changes.

Separating fast and expensive inference

L1 runs on CPUs and is fast enough to score the full candidate set, giving each new or changed pair an initial match score. L2 and L3 need GPU inference and cannot be applied to every candidate at that scale. Comparisons awaiting these models sit in queues, and new work joins the same queues as candidates that have not yet received expensive scoring. The GPU fleet thus receives a steady stream of work, and progress accumulates continuously instead of being squeezed into each daily clustering run.

Choosing what the GPUs work on

Prioritization is what makes the queued work useful. Candidates are ranked using earlier model scores, which flag promising matches; purchase and search signals, which favor products buyers interact with; and the current graph structure, which favors comparisons whose outcome could affect the UPI builder's merge decisions. The queues serve two goals at once: absorbing catalog changes and improving matching coverage for existing products, with new comparisons able to overtake older work.

Caching scores between builds

Completed scores are cached together with the model and product features that produced them. A cached score is reused whenever those inputs are unchanged. Each daily UPI build draws on current L1 results plus whatever L2 and L3 scores are available for that run, without waiting for the queues to drain, while background inference keeps processing new, changed, and previously unscored pairs. Clusters therefore update daily even as the evidence behind them is continuously extended.

Outcome

Merchants retain their own individual listings, while AI agents can recognize which listings across stores belong together and treat them as a group with high precision, kept current as products are added or modified and designed to hold up at Shopify's scale. The central design choice was making expensive judgments reusable, as training data for faster models and as cached scores for later builds, so effort concentrates on comparisons that are new, changed, or not yet scored.