Skip to main content
Nori-Rel connects to linked database tables, builds features at each past date from what had happened by then, and has Nori predict what happens next. You describe the target in one line of PQL, and nothing is trained.
Nori-Rel connects to PostgreSQL, Snowflake, and Databricks. It needs Python 3.11, 3.12, or 3.13. Install nori-rel 0.4.5 or later with the extra for your database and the local extra, as each tab in step 2 shows; see Installation. Local mode runs Nori in your process and downloads its weights from Hugging Face on first use. A GPU is faster but not required. The outputs on this page come from the public RelBench rel-f1 Formula 1 database.

1. Build a database from files (optional)

Skip this section if your data is already in related tables with declared keys. If your data is a folder of CSV or Excel exports, the nori-rel-prepare-data skill walks an AI agent through turning it into a PostgreSQL database Nori-Rel can use. The agent profiles the files, designs tables with declared keys, and leaves out columns that would leak the future, such as a customer’s lifetime total. Before it creates anything, it shows you every table, column, and relationship it plans and waits for your confirmation.
Then ask Claude Code to prepare your files for Nori-Rel. With another agent, give it the folder’s SKILL.md as its instructions.

2. Install and connect

Keep anything that identifies your account in environment variables. Nori-Rel reads them in your process and never sends them anywhere. Replace every value marked # yours with your own: the user, role, key path, host, warehouse, database, and schema shown are examples. Register the time column of each event table. Tables without one, such as drivers, are entities.
Connect with a role that can only read. Nori-Rel needs to read the schema and the tables you predict from, and nothing else. If you don’t know which column holds each table’s event time, connect once without time_columns and print every table’s columns with their database types:
For rel-f1 in PostgreSQL, three of the nine tables, in part: Add each event table’s time column to time_columns and connect again. drivers has none, so it stays an entity.

3. Check the graph

discover returns the tables, keys, and links Nori-Rel found. It reads the primary and foreign keys your database declares. Snowflake and Databricks record keys without enforcing them, and Nori-Rel checks them before it uses them. If your tables declare no keys, pass primary_keys= and foreign_keys= to connect. This helper turns the result into a Mermaid diagram:
Paste the output into any Mermaid renderer. For rel-f1:

4. Describe the prediction

This example predicts each driver’s average finishing position over the next 60 days.
  • anchor_time: the date you predict from.
  • anchor_times: past dates Nori learns from, each before anchor_time.
  • observed_through: the date your data is complete up to.
  • entity_created_at: the entity table’s column for when each entity starts, usually created_at. rel-f1 uses dob. Nori-Rel doesn’t create it: if your table has none, add each entity’s first event time.

5. Predict

feature_strategy= picks how Nori-Rel builds the features:
  • FastDFS (the default) takes COUNT, MIN, MAX, MEAN, and STD of every column in the tables that link directly to the entity.
  • NoriDFS also follows links two hops away and uses the entity’s own columns, within a budget of 48 features.
  • AgenticSearch has an LLM agent write SQL features on top of NoriDFS, and keeps them only if they beat NoriDFS on held-out rows.
Each tab runs the request from the previous step. on_event prints each stage as it runs; leave it out to run quietly. The rest of this page uses the NoriDFS result.
48 features. The first five predictions:
To run in the background, call client.start_predict(...) with the same arguments, then read run.events() or stop it with run.cancel().

6. Save the pipeline

details.pipeline records how the prediction was made: the task, the features NoriDFS planned, and the model settings. It holds no credentials, rows, or model weights. Save it to predict again later without a new feature search:

7. Look at the features

get_context_and_scored_table() returns every row Nori read: the past rows it learned from, each with its features at that date and what happened next (label), and the rows it scored, each with its features and Nori’s prediction. One driver’s rows read as a timeline that ends in the forecast:
Each feature’s name says what it reads: results.grid.mean is the mean of results.grid over the driver’s results rows up to that date, and standings.points.mean the mean of the driver’s points in the standings. The table holds all 48 features; table.columns lists them. The rows with a label are exactly what Nori learned from, and the last row is what it predicted from.

8. Join and plot

details.predictions and details.features share entity_id, so you can put them in one table with columns from your own tables and plot it. connection is any DB-API connection to the same database, such as psycopg.connect(...) or snowflake.connector.connect(...). Quote column names the way your database does. The plot needs matplotlib.
Horizontal bar chart of predicted average finishing position for ten Formula 1 drivers, from Max Verstappen at 2.6 to Lance Stroll at 11.5

The ten drivers with the best predicted average finish for August and September 2023. Lower is better.

9. Explain the predictions

agent_details.model is the Nori that made the AgenticSearch prediction in step 5, fitted on the rows it learned from. Explain Verstappen’s prediction with SHAP (synthefy-nori’s interpretability extra installs shapiq):
SHAP waterfall of the features behind Max Verstappen's predicted average finish

SHAP for Max Verstappen's prediction: each bar is one feature's push from the average prediction.

The agent’s features carry the explanation. See the SQL behind the one that moved the prediction most:
Rank all the features with a glass box (needs the explainability extra):
Glass-box model diagram distilled from Nori on the rel-f1 context rows

The glass box: one curve per kept feature, mapping its value to its push on the predicted finish.

10. Replay

Load the saved pipeline, in this process or another one, and predict with it. It reads the database again and rebuilds the same features with the saved plan, with no feature search:
Pass a later as_of to predict a new date with the same features. Each replay reads fresh rows from the database.

11. Backtest

Replay the pipeline from past dates whose next 60 days are already in the database, and compare with what happened. This loop replays it at eight dates, two months apart, and compares Nori with each driver’s average finish over the year before the date. The actual values come from a query on the same database, through the connection from Join and plot.
142 driver-dates had an actual value to compare with: Use more dates on your own data before you rely on a small difference.
A pipeline from AgenticSearch replays the agent’s SQL unchanged. Backtest it only at dates after its search; earlier dates test a program chosen with later data.

Good to know

  • Each prediction reads every table as of one moment. Snowflake uses Time Travel and Databricks pins Delta table versions, so those tables need history; views are not supported.
  • Local mode predicts numeric targets. A yes/no target such as COUNT(results.*,0,60,days)=0 needs hosted mode.
  • To fill in a column for the rows where it is missing, such as a balance, with no dates at all, see Relational static predictions.
  • Your database bills the reads, including the key checks that run before extraction.
  • details.model explains its own prediction; to predict a new date, replay the pipeline. Hosted predictions have no details.model.
  • SHAP explains the reported median; with many features it estimates the values, so they add up to within a few hundredths of the prediction. The glass box fits its own Nori and scores the mean, so it shows which features matter, not these exact predictions.

Next steps

Installation

The nori-rel extras for PostgreSQL, Snowflake, and Databricks.

Explainability

SHAP interactions, partial dependence, and feature selection.

Relational static predictions

Predict a column from the rows where it is known, with no dates.