Real-world forecasting increasingly relies on asynchronous transaction logs in relational databases rather than uniformly sampled arrays. While relational deep learning (RDL) models can forecast from these complex histories, they are typically trained separately for each specific target and root entity type. We introduce Query-Conditioned Relational pretraining (QCRP), a self-supervised framework that enables a standard RDL backbone to act as a universal forecaster across a database. QCRP generates diverse forecasting objectives using a structured temporal query grammar and interleaves them through a shared conditional predictor. This produces a robust, frozen encoder reusable for downstream tasks via lightweight predictors or a zero-shot interface. Evaluated on large-scale RelBench databases, QCRP learns frozen representations that support competitive forecasting across tasks and entity types. Furthermore, a single unified QCRP model checkpoint is competitive with isolated, entity-specific specialists. We demonstrate promising results for reusing the learned representations from standard RDL backbones for forecasting tasks in relational databases.
Figures & tables
Figure 1: QCRP overview. (a) Structured temporal queries are encoded into task embeddings. (b) During pretraining, one historical entity representation is shared across query-defined future forecasting objectives through a conditional predictor. (c) At inference, the frozen relational encoder supports lightweight fitted heads, while the frozen query-conditioned predictor provides zero-shot forecasts.
Rel-Amazon
Rel-HM
Method
u-LTV ↓
i-LTV ↓
u-churn ↑
i-churn ↑
sales ↓
u-churn ↑
Supervised
14.707±0.159
47.210±0.197
69.350±0.030
81.600±0.130
0.041±0.001
69.200±0.070
MaskAE
15.698±0.105
60.135±0.436
66.565±0.341
64.899±1.715
0.072±0.002
68.161±0.151
CTR
14.992±0.037
57.527±0.323
66.202±0.241
76.071±0.422
0.057±0.001
67.112±0.090
TVE
14.652±0.019
54.544±0.100
69.463±0.027
81.975±0.033
0.046±0.002
68.476±0.102
TVE+CTR
14.426±0.027
55.096±0.299
69.730±0.086
81.921±0.069
0.041±0.001
68.724±0.071
Table 1: Frozen GraphSAGE representation reuse. Mean ± SD over three seeds. LTV/sales: MAE; churn: AUC ×100 . Pretrained encoders are frozen and receive fresh MLP probes; supervised training is end-to-end from scratch. Bold marks the best pretrained mean.
Amazon
HM
Rank
Method
u-LTV
i-LTV
u-C
i-C
Sales
u-C
↓
Griffin
35.59
53.21
62.30
69.00
.151
60.20
10.17
RDBLearn
14.54
48.56
67.57
82.07
.064
68.05
7.58
KumoRFM-2
13.92
46.99
69.10
82.17
.034
69.27
4.58
RT-PluRel
13.94
43.03
71.35
83.27
.040
70.44
2.00
TabPFN-Rel
14.36
46.77
70.86
82.80
.061
70.52
4.50
Table 2: Published baselines vs. multi-root QCRP. LTV/sales: MAE ↓ ; churn: AUC ↑ . Top: pretrained foundation models; bottom: conventional RDL models. QCRP multi uses one pretrained RelGNN checkpoint per database with lightweight MLP probes; published methods use differing adaptation protocols: conventional RDL baselines are trained end-to-end for each task, RT-PluRel performs task-specific fine-tuning and context selection, relational tabular methods such as RDBLearn and TabPFN-Rel construct aggregate features before tabular in-context prediction.
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
Rel-Amazon
Rel-HM
Customer entities
1,850,193
1,371,980
Product/article entities
506,012
105,542
Review/transaction events
20,862,040
15,453,651
Prediction horizon
91 days
7 days
First training cutoff
2008-01-10
2019-09-09
Last training cutoff
2015-07-02
2020-08-31
Appendix
Table 3: Database contents and temporal evaluation. Counts refer to the database tables, not the number of labeled forecasting examples.
Database
Task
Train
Validation
Test
Amazon
user-LTV
4,708,383
409,792
351,885
Amazon
item-LTV
2,707,679
166,978
178,334
Amazon
user-churn
4,708,383
409,792
351,885
Amazon
item-churn
2,536,014
177,689
166,842
HM
item-sales
5,488,184
105,542
105,542
HM
user-churn
3,832,692
76,556
74,575
Appendix
Table 4: Numbers of labeled examples in the standard forecasting tasks. Task populations differ even within one root type.
Component
GraphSAGE
RelGNN
Message-passing layers
2
4
Entity representation width
128
256
Aggregation
Mean
Sum
Attention heads
—
16
GNN dropout
0
0
Table encoder layers / hidden width
4 / 128
4 / 128
Appendix
Table 5: Architecture settings for both databases. Query conditioning follows relational encoding, so sampled objectives share the same historical representations.
ID
Scope
Positive class
Test n
Pos. (%)
P1
Direct events
max(rating) < 5
178,251
19.0
P2
Same product
min(rating) > 3
178,251
23.8
P3
Same customer
price × count(rows) > 194.8
178,251
61.6
P4
Same product
mean(rating; verified=True) > 4.5
173,674
52.7
P5
Direct events
price × count(rows; verified=True) > 14.95
178,251
58.4
P6
Same customer
min(rating; verified=True) > 3
174,415
33.2
Appendix
Table 6: Held-out Rel-Amazon queries. All use a 91-day horizon. Test prevalence is computed among defined labels; undefined outcomes are excluded, not treated as negatives.
Rel-Amazon
Rel-HM
Initialization
user-LTV
item-LTV
user-churn
item-churn
item-sales
user-churn
MAE ↓
MAE ↓
AUC ↑
AUC ↑
MAE ↓
AUC ↑
GraphSAGE
Random initialization
16.444±0.029
60.431±0.257
65.772±0.062
74.604±0.474
0.051±0.000
66.616±0.487
Supervised
14.707±0.159
47.210±0.197
69.350±0.030
81.600±0.130
0.041±0.001
69.200±0.070
Masked reconstruction
15.698±0.105
60.135±0.436
66.565±0.341
64.899±1.715
0.072±0.002
68.161±0.151
Appendix
Table 7: Frozen-encoder MLP probes. Supervised training from scratch (Sup.) is an end-to-end reference; all other rows fit a fresh MLP on frozen encoder embeddings. AUC is multiplied by 100. Bold marks the best mean among pretrained rows within each backbone.
Rel-Amazon
Rel-HM
Initialization
user-LTV
item-LTV
user-churn
item-churn
item-sales
user-churn
MAE ↓
MAE ↓
AUC ↑
AUC ↑
MAE ↓
AUC ↑
Masked reconstruction
15.537±1.110
46.833±0.107
68.820±0.232
81.621±0.142
0.040±0.001
69.764±0.090
CTR
14.418±0.051
46.338±0.686
69.347±0.051
81.494±0.026
0.041±0.001
69.486±0.109
TVE-2
14.419±0.064
46.382±0.515
69.471±0.170
81.799±0.064
0.042±0.001
69.531±0.127
TVE-2+CTR
14.353±0.017
47.098±0.425
69.801±0.084
81.769±0.023
0.038±0.001
69.837±0.018
Appendix
Table 8: Full finetuning with GraphSAGE. Each method transfers only its relational encoder, discards pretraining-specific modules, and trains the encoder with a fresh linear head. AUC is multiplied by 100.
ID
Random
TVE
Supervised
QCRP
P1
63.88
72.00
70.82
72.45
P2
81.75
96.14
97.38
97.45
P3
68.34
72.96
77.15
77.46
P4
66.77
91.29
96.96
96.39
P5
68.14
73.88
87.58
85.60
P6
65.56
69.88
69.60
70.28
Appendix
Table 9: Held-out-task test ROC-AUC ( ×100 ), one seed. Random initialization, TVE, and QCRP fit fresh MLPs on frozen entity representations; supervised training updates the full model. Query IDs are defined in Table 6 .
Figure 2: Rel-Amazon GraphSAGE interleaving T=5000 . Top: root-specific validation immediately after its own block and after the other root’s block, at matched root exposure. Bottom: excess training loss after returning, relative to the last ten logs of the preceding active block. Early/late curves average the first/last thirds of complete resumed blocks; shading spans their 10th–90th percentiles after nine-log smoothing. Offset zero is the first return log.
Figure 3: Rel-HM GraphSAGE interleaving T=5000 . Top: mean validation losses over two seeds, with shading spanning seeds. Bottom: recovery with the same block selection, smoothing, and percentile intervals as Amazon. Loss scales differ across roots and databases.
Figure 4: Rel-Amazon scheduling. (a) Mean loss over 78 validation objectives; joint training sums the two root losses. Interleaved validation occurs at block boundaries and averages one freshly trained and one inactive root. (b) Residence-time sweep, 216,000 updates, relative to T=5000 . Points are distinct settings, not a continuous fit.
Figure 5: Gradient alignment in a separate Amazon joint-training diagnostic: 880 observations, one every 250 updates, restricted to parameters used by both root losses. Histograms share cosine bins; dashed lines and legend values give means. (a) Cross-root cosine. (b) Each root gradient’s cosine with their sum. The mean product/customer norm ratio is 1.406. Cosines diagnose gradient relationships [ 32 ] ; they are not AdamW parameter updates [ 16 ] .
Backbone / evaluation
Adaptation
Full model
Trainable
GraphSAGE, holdout
Supervised
≈1.36 M
≈1.36 M
GraphSAGE, holdout
Frozen + MLP
—
16,897
RelGNN, Amazon
Frozen + MLP
44,396,033
66,561
RelGNN, HM
Frozen + MLP
45,282,817
66,561
Appendix
Table 10: Parameters per downstream model. Full RelGNN counts include the frozen encoder and one MLP, excluding buffers and pretraining-only modules. GraphSAGE counts refer to the fourteen-task holdout evaluation; its supervised count is rounded.
Encoder deployment
Rel-Amazon
Rel-HM
Separate supervised or fully finetuned models
4
2
Frozen root-specific models
2
2
Frozen multi-root model
1
1
Appendix
Table 11: Distinct encoder weight sets for the standard-task suite, per backbone and seed. Amazon uses four task-specific predictors; HM uses two.
Figure 6: Query semantics, embedding geometry, and task-label similarity. Columns compare raw query-field agreement, an untrained structured encoder (seed 100), and the trained encoder; rows show product and customer tasks. Field agreement is the fraction of matching variable fields; encoder similarity is cosine. Lines show medians with 10th–90th percentile spread in eight shared bins (at least 25 pairs per displayed bin); no trend is fitted to field agreement. Signed and absolute Spearman alignment appear at bottom right. Pink rings identify the post-hoc rating-dispersion diagnostic.
Root
Pair subset
Query fields
Initial
Trained
Product
All within-root
.121 / .263
.091 / .195
.525 / .509
Product
Train–train
.125 / .294
.107 / .222
.579 / .554
Product
Train–holdout
-.074 / .439
-.159 / .303
.443 / .386
Customer
All within-root
.120 / .173
.106 / .140
.365 / .439
Customer
Train–train
.108 / .228
.103 / .192
.454 / .441
Customer
Train–holdout
.049 / .220
.007 / .151
.146 / .394
Appendix
Table 12: Query-geometry alignment by evaluation subset. “Initial” is the mean over five fresh encoders with the same architecture and vocabulary (seeds 100–104); these are not saved original initializations. Each cell lists signed / absolute-label Spearman alignment.
Root
Binary queries
AUC ↑
Regression queries
R2↑
Product
12
82.93
26
0.368
Customer
12
74.74
28
0.205
Appendix
Table 13: Direct decoding of the 78 seen pretraining queries on temporal validation anchors, GraphSAGE specialists, one seed. Last recorded validation at 96,000 updates (not the final checkpoint). Metrics are unweighted task means; regression R2 uses the transformed pretraining targets.
Backbone
user-LTV
item-LTV
user-churn
item-churn
MAE ↓
MAE ↓
AUC ↑
AUC ↑
GraphSAGE
17.34
50.59
68.35
81.28
RelGNN
14.16
51.65
70.81
82.80
Appendix
Table 14: Zero-shot decoding of pretraining queries on the standard Rel-Amazon test tasks. Recorded final 216,000-update, 74-query checkpoints, one run per backbone; these precede the 78-query experiments. No downstream predictor or calibration is fitted.
ID
Correct query
Shuffled fields
P1
54.88
32.72
P2
96.39
33.71
P3
71.95
71.94
P4
90.59
82.16
P5
70.78
67.32
P6
69.70
31.77
Appendix
Table 15: Zero-shot test ROC-AUC ( ×100 ) on the fourteen held-out queries, one seed. Both columns retain the pretrained encoder and decoder; no downstream predictor is fitted.
Time series forecasting predicts future values from ordered observations using statistical, neural, and probabilistic models to support decisions under uncertainty.
Institute for Artificial Intelligence, Peking University · University of Illinois at Urbana-Champaign · Institute of Computing Technology, Beijing University of Post and Telecommunication +1