Berlin Tech Meetup: The Future of Relational Foundation Models, Systems, and Real-World Applications

Register now:
PyG/Guide8 min read

Relational Deep Learning: Learning Directly from Relational Databases

Every enterprise runs on relational databases. Relational deep learning skips the months-long feature engineering pipeline by treating the database itself as a temporal heterogeneous graph. GNNs learn cross-table patterns that flat-table ML systematically misses.

PyTorch Geometric

TL;DR

  • 1Relational deep learning (RDL) treats relational databases as temporal heterogeneous graphs. Each table = a node type, each row = a node, each foreign key = an edge. GNNs process this graph directly.
  • 2Traditional ML requires flattening: join tables, aggregate features, build a single training table. This takes months, loses information (aggregation destroys patterns), and must be rebuilt when the schema changes.
  • 3RDL preserves the full relational structure. A customer node receives messages from its order nodes, which received messages from product nodes. The GNN learns which cross-table patterns predict the target automatically.
  • 4On RelBench (7 databases, 30 tasks, 103M rows), GNNs achieve 75.83 AUROC vs 62.44 for flat-table LightGBM. KumoRFM achieves 76.71 zero-shot and 81.14 fine-tuned.
  • 5Temporal integrity is built in: edges carry timestamps, and message passing only uses data from before the prediction time. No manual temporal feature engineering, no leakage risk.

Relational deep learning is the paradigm of learning directly from relational databases by treating them as temporal heterogeneous graphs. Instead of the traditional workflow (months of feature engineering to flatten multi-table databases into single training tables), RDL preserves the full relational structure. Each table becomes a node type. Each row becomes a node. Each foreign key becomes an edge. Graph neural networks extract cross-table patterns automatically.

The traditional ML pipeline on relational data

Today, most enterprise ML follows this workflow:

  1. Understand the schema: study 10-50 tables, their relationships, and business meaning (weeks)
  2. Feature engineering: write SQL to join tables, compute aggregations (avg order amount, count of orders in 30 days, max product price per customer), and build a flat feature table (months)
  3. Train a model: XGBoost or LightGBM on the flat table (days)
  4. Maintain features: when the schema changes, when new tables are added, when business logic evolves, re-engineer everything (ongoing)

Steps 1, 2, and 4 consume 80% of the time and are where information is lost. Aggregating orders into “average order amount” destroys the distribution. Flattening to a single table loses the multi-hop relationships (customer → order → product → category).

The RDL approach

Relational deep learning replaces steps 1-2 with automatic graph construction:

relational_to_graph.py
# Conceptual: relational database → heterogeneous graph

# Tables become node types
node_types = ['customer', 'order', 'product', 'category']

# Foreign keys become edge types
edge_types = [
    ('customer', 'places', 'order'),     # customer_id FK in orders
    ('order', 'contains', 'product'),     # product_id FK in order_items
    ('product', 'belongs_to', 'category') # category_id FK in products
]

# Row columns become node features
# customer: [age, location, signup_date, ...]
# order: [amount, timestamp, channel, ...]
# product: [price, weight, rating, ...]

# Result: a temporal heterogeneous graph
# - Heterogeneous: multiple node/edge types
# - Temporal: edges carry timestamps (order dates)

The conversion is mechanical: read the schema, map tables to node types, map foreign keys to edge types. No domain expertise required.

What message passing discovers

Consider predicting customer churn in an e-commerce database with customers, orders, products, and support tickets tables:

  • Layer 1: each customer node aggregates its orders (recency, frequency, monetary) and support tickets (count, severity, resolution status). This approximates basic RFM features.
  • Layer 2: each customer also sees the products from their orders (categories, price ranges, return rates) and the resolution patterns of similar support tickets. This captures cross-table patterns.
  • Layer 3: each customer sees the behaviors of other customers who bought the same products. Customers whose product-neighbors have high churn rates are themselves at risk. This is a 3-hop pattern invisible to flat-table ML.

These patterns are discovered automatically. No data scientist manually computed “average return rate of products purchased by customer.” The GNN learned that this signal predicts churn through message passing.

RelBench: the benchmark

RelBench is the standard benchmark for relational deep learning, containing 7 real relational databases with 30 prediction tasks across 103 million rows:

  • Databases: e-commerce, healthcare, reviews, academic, and more
  • Tasks: churn, LTV, fraud, recommendation, demand forecasting
  • Temporal splits: train on historical data, validate and test on future data with strict temporal integrity

Results demonstrate the RDL advantage:

  • Flat-table LightGBM: 62.44 average AUROC (after expert feature engineering)
  • GNN on relational graph: 75.83 average AUROC (no feature engineering)
  • KumoRFM zero-shot: 76.71 average AUROC (no training on the target database)
  • KumoRFM fine-tuned: 81.14 average AUROC (fine-tuned on target database)

Temporal integrity

A critical advantage of RDL is built-in temporal correctness. Rows in relational databases have timestamps (order_date, created_at, updated_at). In the temporal heterogeneous graph, these timestamps determine which edges are visible at prediction time.

If you are predicting whether customer Alice will churn at time T, message passing only uses orders placed before T, products purchased before T, and support tickets filed before T. No future information leaks in. This temporal integrity is automatic; in traditional feature engineering, preventing leakage requires careful manual timestamp filtering at every aggregation step.

Frequently asked questions

What is relational deep learning?

Relational deep learning (RDL) is a paradigm that treats relational databases directly as temporal heterogeneous graphs and uses graph neural networks to learn from the multi-table structure. Instead of flattening multiple tables into a single feature table (which loses relational information), RDL preserves the full relational schema: each row becomes a node, each foreign key becomes an edge, and GNNs extract cross-table patterns automatically.

How does a relational database become a graph?

Every table becomes a node type. Every row becomes a node with the row's columns as features. Every foreign key relationship becomes an edge type connecting rows across tables. A customers table linked to an orders table via customer_id creates customer-nodes linked to order-nodes. The resulting graph is heterogeneous (multiple node/edge types) and temporal (rows have timestamps).

What is RelBench?

RelBench is a benchmark for relational deep learning containing 7 real databases with 30 prediction tasks across 103 million rows. It provides standardized train/val/test splits with temporal integrity (no future data leakage). On RelBench, GNN-based models achieve 75.83 AUROC versus 62.44 for flat-table LightGBM, demonstrating the value of preserving relational structure.

How does relational deep learning handle time?

RDL creates temporal heterogeneous graphs where edges carry timestamps. At any prediction time t, only rows with timestamps before t are visible. This prevents data leakage and models the natural temporal evolution of the database. Message passing respects this temporal ordering: a customer node only receives messages from orders placed before the prediction timestamp.

What is the advantage over traditional feature engineering?

Traditional ML on relational data requires data scientists to manually flatten tables: join, aggregate, and engineer features (average order amount, count of orders in last 30 days, max product price). This is slow (months of work), lossy (aggregation destroys individual-level patterns), and brittle (must be re-engineered when the schema changes). RDL processes the raw tables directly, learning the relevant cross-table patterns automatically.

Learn more about graph ML

PyTorch Geometric is the open-source foundation for graph neural networks. Explore more layers, concepts, and production patterns.