Trie-Aware Transformers for Generative Recommendation

Zhenxiang Xu, Sirui Chen, Yong He, Jieyu Yang, Chuan Yuan, Ke Ding, Jing Cao, Can Wang, Jiawei ChenNeurIPS 2026

TL;DR

Modern generative recommendation systems organize item catalogs into hierarchical prefix trees (tries), yet they paradoxically flatten these rich trees into linear 1D sequences when feeding them into a Transformer. TrieRec solves this structural amnesia by injecting two lightweight, hyperparameter-free positional encodings directly into the Transformer, teaching it to "see" the underlying tree. Plugging TrieRec into existing generative recommenders boosts accuracy by an average of 8.83% with barely any extra compute.

What Problem Does This Paper Address?

Instead of scoring millions of query-item pairs one by one, Generative Recommendation (GR) treats predicting your next purchase or movie watch like generating text. First, every item in a catalog is quantized from coarse-to-fine into a short sequence of discrete semantic tokens—say, [Sports, Ball, Basketball]. Because items share prefixes (a football might be [Sports, Ball, Football]), the entire catalog naturally forms a prefix tree, or trie, where each root-to-leaf path represents an item.

Figure 1: Generative recommendation pipeline. Item tokenization maps items to semantic token sequences via hierarchical quantization, forming a trie structure. Autoregressive generation employs a Transformer to predict the next item’s token sequence conditioned on user interaction history.

Here is the catch: during the second stage—autoregressive generation—standard Transformers take a user's interaction history and smash all those structured item tokens into a flat, 1D stream.

Flattening the tree throws away two vital pieces of information:

  1. Structural Position: Because token IDs are often reused across residual quantization layers, a token's meaning depends heavily on its tree depth, ancestors, and descendants. Without tree context, semantics get muddled.
  2. Relational Topology: Tokens sharing a deep Lowest Common Ancestor (LCA)—like the leaf tokens of a basketball and a football—are semantically much closer than tokens from distant branches (like a basketball and a computer mouse). Standard linear positional encodings only measure how far apart tokens sit in time, completely missing how close they sit on the tree.

Methods

Rather than redesigning the whole pipeline, the authors propose TrieRec, a model-agnostic drop-in upgrade that gives standard Transformers structural inductive biases via two novel positional encodings:

Figure 2: The illustration of our proposed trie-aware absolute positional encoding and topology-aware relative positional encoding in TrieRec.
  • Trie-aware Absolute Positional Encoding (TAE): Before tokens enter the Transformer, TAE enriches each token with its full root-to-leaf item context. It concatenates the embeddings of all tokens along the same item path (ancestors and descendants), passes them through a position-dependent MLP to capture cross-token and cross-dimension interactions, and applies a depth-specific projection before adding the result back to the initial token embedding.
  • Topology-aware Relative Positional Encoding (TRE): Instead of relying solely on 1D sequence distance in self-attention, TRE injects a pairwise structural bias into the attention scores. For any two tokens $u$ and $v$ in a user's history, it computes a 3D coordinate: (depth of their LCA, distance from u to LCA, distance from v to LCA). This tuple looks up a learnable scalar bias from a shared relation table, explicitly telling the attention mechanism how closely related any two tokens are on the global trie.

Notably, TrieRec requires zero new tunable hyperparameters and shares the TRE lookup table across Transformer layers for high efficiency.

Datasets

The authors evaluate TrieRec on four standard, real-world sequential recommendation benchmarks (using a 5-core filtering setting and retaining the 20 most recent interactions per user):

  • Amazon-Beauty, Amazon-Toys, and Amazon-Food (e-commerce product ratings).
  • MovieLens-1M (movie ratings).

No new datasets were introduced in this work.

Key Insights and Ideas

  • Syntax Trees $\neq$ Recommendation Tries: Prior tree-aware Transformers (built for code generation) focus on relative distances within local, instance-specific syntax trees. Those methods underperform here because recommendation tries are global—specific depths carry fixed levels of semantic granularity across the entire catalog. Knowing the exact LCA depth is just as important as knowing the distance between nodes.
  • Automatic Collision Suppression: In case studies of the learned TRE attention biases, the model organically learned to assign negative attention biases to the final token column when prefixes collided—effectively recognizing and ignoring semantically meaningless "collision-resolution" IDs while using informative descendant tokens to enrich ancestor representations.
  • Cross-Dimensional Mixing Matters: Restricting TAE's MLP so dimensions couldn't interact across tree depths caused a noticeable performance drop, proving that hierarchical semantics aren't neatly aligned dimension-by-dimension across quantization layers.

Key Results

TrieRec was plugged into three state-of-the-art GR backbones (TIGER, CoST, and LETTER) and compared against traditional sequential recommenders, tree-loss methods, and alternative positional encodings.

  • Consistent Gains: Across all four datasets and three backbones, TrieRec achieved an 8.83% average relative improvement.
  • Standout Numbers: On MovieLens-1M, adding TrieRec boosted NDCG@10 by +15.46% on TIGER (0.0912 $\rightarrow$ 0.1053), +14.02% on CoST (0.0920 $\rightarrow$ 0.1049), and +13.93% on LETTER (0.0991 $\rightarrow$ 0.1129). On Amazon-Toys, it lifted CoST's NDCG@10 by +11.62%.
  • Minimal Overhead: Because TAE runs once at the input and TRE uses fast $O(1)$ table lookups after LCA calculation, the total training and inference latency overhead is less than 10%.

Limitations and Future Work

TrieRec's biggest bottleneck is its reliance on a fixed, pre-computed trie. Item tokenization (like RQ-VAE) happens offline; if that clustering step introduces semantic noise or awkward groupings, TrieRec faithfully hard-codes those flaws into the attention mechanism.

For future work, the authors suggest exploring joint optimization—allowing the autoregressive Transformer to dynamically refine and update the trie structure during training—as well as extending these structure-aware topologies to multi-modal recommendation scenarios.

Summary updated

Abstract

Generative recommendation (GR) aligns with advances in generative AI by casting next-item prediction as token-level generation rather than score-based ranking. Most GR methods adopt a two-stage pipeline: (i) \textit{item tokenization}, which maps each item to a sequence of discrete, hierarchically organized tokens; and (ii) \textit{autoregressive generation}, which predicts the next item's tokens conditioned on the tokens of user's interaction history. Although hierarchical tokenization induces a prefix tree (trie) over items, standard autoregressive modeling with conventional Transformers often flattens item tokens into a linear stream and overlooks the underlying topology. To address this, we propose TrieRec, a trie-aware generative recommendation method that augments Transformers with structural inductive biases via two positional encodings. First, a \textit{trie-aware absolute positional encoding} aggregates a token's (node's) local structural context (\eg depth, ancestors, and descendants) into the token representation. Second, a \textit{topology-aware relative positional encoding} injects pairwise structural relations into self-attention to capture topology-induced semantic relatedness. TrieRec is also model-agnostic, efficient, and hyperparameter-free. In our experiments, we implement TrieRec within three representative GR backbones, achieving notably improvements of 8.83\% on average across four real-world datasets.
BibTeX
@inproceedings{xu2026trie,
  author = {Zhenxiang Xu and Sirui Chen and Yong He and Jieyu Yang and Chuan Yuan and Ke Ding and Jing Cao and Can Wang and Jiawei Chen},
  title = {{Trie-Aware Transformers for Generative Recommendation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=oxoJ8MqY3p},
}
Figure