TL;DR
RoutingTrie is a metadata filtering layer for Generative Retrieval (GR) that applies constraints during the decoding process rather than after. By integrating compact metadata indexes directly into the Semantic ID (SID) trie, it prevents models from wasting beam capacity on invalid candidates, boosting retrieval accuracy (Hit@100) from 67.5% to 96.1% with a negligible 1.1ms latency overhead.
What Problem Does This Paper Address?
Generative Retrieval (GR) is a rising paradigm in search and recommendation where Large Language Models (LLMs) generate item identifiers (Semantic IDs) token by token. While powerful, these systems struggle with real-world constraints. A shopper doesn't just want "relevant" items; they want items that are "in stock," "available in Canada," or from a "specific shop."
Standard GR uses a "catalog trie" to ensure the generated ID exists, but it typically handles metadata constraints via post-filtering. If your beam search identifies the top 10 most relevant items but all of them are out of stock, the system returns zero results. This wastes computation and severely limits recall. The challenge is to move these filters "upstream" into the generation process without exploding memory usage or slowing down the millisecond-scale requirements of industrial search.
Methods
The authors propose RoutingTrie, which maintains a shared SID trie and builds specialized, memory-efficient indexes for each metadata field.
Dual-Index Strategy
Because metadata distributions vary wildly—from binary "in stock" flags to millions of unique "Shop IDs"—the authors use two distinct representations:
- Dense Bitset: Ideal for low-cardinality fields (e.g., Country, Fulfillment). It uses a bitmask table where each bit represents a value. To save space, it employs "row sharing," where multiple trie edges that lead to the same set of metadata values point to a single shared bitmask.
- Sparse List: Designed for high-cardinality fields (e.g., Shop ID). It stores sorted lists of values reachable below a specific edge.
The Selection Rule
A key contribution is a formal storage cost formula (Equation 1 in the paper) that guides engineers on which index to choose based on a field's cardinality, value intensity (average values per edge), and row-sharing potential.
Constraint-Aware Decoding
During inference, as the model generates the next token, RoutingTrie probes these indexes (using bit lookups for dense or binary search for sparse). These probes produce a Boolean mask that is applied to the model's token scores before beam selection. This ensures the beam only tracks paths that can actually lead to a valid, constraint-satisfying item.
Datasets
The paper evaluates RoutingTrie using two primary sources:
- ShopTrie: A newly introduced, configurable synthetic benchmark. It generates deterministic tries and metadata distributions calibrated to real-world industrial catalog summaries, allowing for reproducible comparisons of index size and probe latency.
- Production Replay: A dataset of 23,167 historical purchase sessions from Shopify’s production GR system, which utilizes a 14B parameter model and a multi-million cardinality shop ID field.
Key Insights and Ideas
- Beam Capacity is the Bottleneck: The primary "aha" moment is that post-filtering fails not because of computation time, but because of "beam displacement." Invalid items crowd out valid ones in the limited beam width. RoutingTrie fixes this by "routing" the beam only toward valid regions of the item space.
- Row Sharing is a Massive Optimizer: In the Dense Bitset, many different paths in the trie eventually converge on the same set of metadata (e.g., all items in a sub-category might be available in the same countries). Deduplicating these bitsets is what makes the memory footprint manageable.
- GPU-First Implementation: By using Triton to write custom GPU kernels, the authors show that metadata probing can be done in parallel. This makes the latency hit nearly constant, regardless of whether you are checking one constraint or eight.
Key Results
- Accuracy Boost: In the production replay, RoutingTrie increased Hit@100 from 67.5% to 96.1%, a massive 28.6 percentage point gain.
- Minimal Latency: The end-to-end median request latency increased by only 1.1 ms (from 27.1 ms to 28.2 ms) on an NVIDIA H200.
- Memory Efficiency: For a trie with 338 million edges, the total resident memory for the trie and eight metadata fields was approximately 10.9 GiB, fitting comfortably within modern GPU memory.
- Scalability: As shown in Figure 2, the system handles everything from binary fields to fields with cardinalities over 1 million.
Limitations and Future Work
- Numerical Predicates: RoutingTrie currently focuses on categorical metadata. Numerical constraints (like "price < $50") require discretization into bins before they can be indexed, which may still require a final post-resolution check.
- Lossless Retrieval: While RoutingTrie significantly improves the odds, it cannot guarantee lossless retrieval with a finite beam. A valid item might still be missed if the model assigns its prefix a very low initial score.
- Dynamic Updates: While the paper discusses index updates, the current Sparse List implementation requires repacking arrays when segment lengths change, which could be optimized for high-velocity catalogs.
Summary updated