Template: Simple Start
A minimal notebook to connect to Snowflake, model a small graph, and compute betweenness centrality with RelationalAI.
Browse files
What this template is for
This template is a minimal, runnable notebook designed to help you get up and running with RelationalAI against Snowflake. It walks through a tiny end-to-end example: create a simple Snowflake table, model it as a graph in RelationalAI, and compute a basic graph metric.
Who this is for
- Anyone new to RelationalAI who wants a short “first success” notebook
- Users comfortable running Jupyter and making small edits
What you’ll build
- A working notebook that connects to Snowflake via your RelationalAI configuration
- A small graph model built from a Snowflake
CONNECTIONStable - A queryable graph representation (edge list)
- Betweenness centrality scores for each station
What’s included
- Model:
StationandConnectionconcepts, plus a derived graph edge relation - Runner:
simple-start.ipynb(primary notebook) - Sample data: a small Snowflake table created by the notebook (
RAI_DEMO.SIMPLE_START.CONNECTIONS) - Outputs: pandas DataFrames (table preview, edge list, and betweenness centrality)
Prerequisites
- Python >= 3.10
- A Snowflake account with the RelationalAI Native App installed
- A Snowflake user/role that can:
- create schemas/tables (or write into a schema you control)
- create/refresh a stream into the RelationalAI app (as prompted by the notebook)
Quickstart
-
Download the ZIP file for this template and extract it:
Terminal window curl -L -O https://docs.relational.ai/templates/zips/v1/simple-start.zipunzip simple-start.zipcd simple-start -
Create and activate a virtual environment
From the template folder (this is
v1/simple-startif you cloned the full repository):Terminal window python -m venv .venvsource .venv/bin/activatepython -m pip install -U pip -
Install dependencies
Terminal window python -m pip install . -
Configure credentials
This notebook reads data from Snowflake and executes RelationalAI queries, so you need a working RelationalAI/Snowflake configuration.
If you use the RelationalAI CLI, run:
Terminal window rai initIf you have multiple profiles, set one explicitly:
Terminal window export RAI_PROFILE=<your_profile> -
Start Jupyter
Terminal window jupyter notebook -
Run the template
Open
simple-start.ipynband run the cells top-to-bottom (or “Run All”). -
Expected output
You should see:
- A preview of the Snowflake
CONNECTIONStable. - An edge list DataFrame (one row per connection).
- A DataFrame of betweenness centrality values (sorted descending).
- A preview of the Snowflake
How it works
At a high level, the notebook:
- Creates and populates the
CONNECTIONStable in Snowflake. - Defines
StationandConnectionconcepts and loads them from the Snowflake source table. - Builds an undirected graph from the station connectivity relation.
- Lists the resulting edges as a table.
- Computes betweenness centrality and queries the scores into a pandas DataFrame.
Customize this template
Use your own data:
- Replace
RAI_DEMO.SIMPLE_START.CONNECTIONSwith your own edge table. - Ensure your table has two columns that represent the endpoints of each edge.
Extend the model:
- Add node attributes (for example, station type, capacity, region) and join them to
Station. - Add additional graph analytics supported by the
Graphreasoner.
Troubleshooting
Jupyter can’t import relationalai (or uses the wrong environment)
- Confirm your virtual environment is active:
which pythonshould point to.venv. - Reinstall dependencies:
python -m pip install .. - In Jupyter/VS Code, select the kernel that points to the
.venvinterpreter.
Authentication/configuration fails when the notebook runs queries
- Make sure your RelationalAI/Snowflake configuration is present and correct.
- If you use the RelationalAI CLI, run
rai initto create/update your config. - If you have multiple profiles, set
RAI_PROFILEto the one you want.
The notebook can’t create the demo table/schema
- Ensure your Snowflake role can create schemas/tables in the target database.
- Alternatively, edit the notebook to write into a database/schema you control.