Using the RelationalAI Predictive Reasoner in a Snowflake Notebook
Get Access to the RelationalAI Native App
Section titled “Get Access to the RelationalAI Native App”To use the RelationalAI Predictive Reasoner, you’ll need access to the RelationalAI Native App. You can request access via the Snowflake Marketplace. When submitting your request, be sure to include a note indicating that you’re interested in the app’s predictive reasoning capabilities using graph neural networks (GNNs).
Once your request is approved you will receive email notification by RAI. Follow the instructions here to install the RAI Native App. Note that you will need to be a user with either ORGADMIN or ACCOUNTADMIN privileges to do the installation.
If you have already installed the RelationalAI Native App reach out to us to request enabling the predictive reasoning feature flag.
Upload relationalai_gnns.zip Package
Section titled “Upload relationalai_gnns.zip Package”To train models and make predictions within a Snowflake Notebook, you need access to certain RelationalAI services through the Predictive Reasoner Python SDK. Since this SDK isn’t available by default, you must install it as a third-party Python package. Snowflake supports this by allowing you to import packages from a Snowflake stage. For more details, refer to the official Snowflake documentation.
So, you’ll first need to upload the SDK package to a Snowflake stage. Follow the steps below:
- Download the SDK package.
Obtain the provided ZIP file
relationalai_gnns.zip. - Create a Snowflake stage to upload the package. Run the following SQL commands in a Snowflake worksheet:
- Select the database and schema where you want to create the stage to upload the package:
USE DATABASE RELATIONAL_AI_GNN; --database name that sdk is uploadedUSE SCHEMA SDK_SCHEMA; --schema name that sdk is uploaded- Create the stage (if it doesn’t already exist):
CREATE STAGE IF NOT EXISTS SDK_STAGE;- Set a query tag with metadata for tracking and auditing:
ALTER SESSION SET query_tag = '{"origin":"sf_sit-is","name":"notebook_demo_pack","version":{"major":1,"minor":0},"attributes":{"is_quickstart":0,"source":"sql","vignette":"import_package_stage"}}';- Optionally, remove any previously uploaded versions of the package from the stage to ensure that only the latest build is used:
LIST @SDK_STAGE; -- view filesREMOVE @SDK_STAGE/relationalai_gnns.zip; -- delete old package - Upload the package to
SDK_STAGE:- In the left navigation pane, go to
Catalog -> Database Explorer. - Navigate to the target stage location, for example:
RELATIONAL_AI_GNN > SDK_SCHEMA > Stages > SDK_STAGE. - In the stage view, click
Files(top-right corner). - In the upload dialog, drag and drop the file
relationalai_gnns.zip. - Click
Uploadto complete the process.
- In the left navigation pane, go to
Use Snowflake Connector for Python to upload the package to a Snowflake stage. The Snowflake Connector for Python is a library that lets you connect to your Snowflake account programmatically and execute SQL commands directly from Python code. For more details, refer to the official Snowflake documentation.
- Download the SDK package.
Obtain the provided ZIP file
relationalai_gnns.zip. - Run this Python code:
import snowflake.connector# Change this to the actual path to relationalai_gnns.zippath_to_package = "local/path/to/relationalai_gnns.zip"# Enter your Snowflake credentialsconn = snowflake.connector.connect(user='YOUR_SNOWFLAKE_USERNAME',password='YOUR_SNOWFLAKE_PASSWORD',account='YOUR_SNOWFLAKE_ACCOUNT',warehouse='YOUR_SNOWFLAKE_WAREHOUSE'role='YOUR_SNOWFLAKE_ROLE')cur = conn.cursor()# Select the database and schema where you want to create the stage to upload the packagecur.execute("USE DATABASE RELATIONAL_AI_GNN")cur.execute("USE SCHEMA SDK_SCHEMA")# Create the stage (if it doesn’t already exist)cur.execute("CREATE STAGE IF NOT EXISTS SDK_STAGE")# Set a query tag with metadata for tracking and auditingcur.execute("""ALTER SESSION SET query_tag = '{"origin":"sf_sit-is","name":"notebook_demo_pack","version":{"major":1,"minor":0},"attributes":{"is_quickstart":0,"source":"sql","vignette":"import_package_stage"}}'""")# Optionally, remove any previously uploaded versions of the# package from the stage to ensure that only the latest build is usedcur.execute("LIST @SDK_STAGE")cur.execute("REMOVE @SDK_STAGE/relationalai_gnns.zip")# Upload the package to SDK_STAGE using PUT,# ensuring it is available for use (overwriting any existing version if necessary)cur.execute("PUT file://{path_to_package} @SDK_STAGE AUTO_COMPRESS=FALSE OVERWRITE=TRUE")cur.close()conn.close()
Use snow to upload the package to a Snowflake stage.
snow is the Snowflake CLI — a command-line tool that lets you connect to your Snowflake account and run SQL commands,
manage stages, and perform other Snowflake tasks directly from your local machine.
For more details, refer to the official Snowflake documentation.
- Download the SDK package.
Obtain the provided ZIP file
relationalai_gnns.zip. - In a terminal configure a Snowflake connection by running the following command. Enter your Snowflake credentials and select the database and schema where you want to create the stage to upload the package:
Terminal window snow connection add --name my_conn \--account YOUR_SNOWFLAKE_ACCOUNT \--user YOUR_SNOWFLAKE_USERNAME \--password YOUR_SNOWFLAKE_PASSWORD \--role YOUR_SNOWFLAKE_ROLE \--warehouse YOUR_SNOWFLAKE_WAREHOUSE \--database RELATIONAL_AI_GNN \--schema SDK_SCHEMA \ - Create a Snowflake stage to upload the package. Run the following commands in the terminal:
- Create the stage (if it doesn’t already exist):
Terminal window snow sql -c my_conn -q "CREATE STAGE IF NOT EXISTS SDK_STAGE;"- Set a query tag with metadata for tracking and auditing:
Terminal window snow sql -c my_conn -q "ALTER SESSION SET query_tag = '{ \"origin":"sf_sit-is", \"name":"notebook_demo_pack", \"version":{"major":1,"minor":0}, \"attributes":{"is_quickstart":0,"source":"sql","vignette":"import_package_stage"} \}'" - Optionally, remove any previously uploaded versions of the package from the stage to ensure that only the latest build is used:
Terminal window snow sql -q "LIST @SDK_STAGE;"snow sql -q "REMOVE @SDK_STAGE/relationalai_gnns.zip;" - Upload the package to
SDK_STAGE, ensuring it is available for use (overwriting any existing version if necessary):Terminal window snow snowpark package upload \--connection my_conn \--file relationalai_gnns.zip \--stage SDK_STAGE \--overwrite
Set up Notebook
Section titled “Set up Notebook”-
Create Notebook
- Go to https://app.snowflake.com.
- Select
Projects > Notebooks > + Notebook. - Insert a
Namefor the notebook. - In
Notebook locationchoose the same database where the SDK has been uploaded. - In
Runtime versionchoose a version that supports python 3.10 (or more).
-
Load Python Packages
The Predictive Reasoner Python SDK uses some Python packages. These packages need to be installed before a Notebook can run. To install such packages you should click on the top
Packagesand then type the name of each package in theAnaconda Packagessearch box and select the package. You should install the following packages:numpytabulatepydanticsqlalchemypython-graphvizcryptographypydotcertifi
Finally, click
Save. -
Load
relationalai_gnns.zipPython PackageFinally, you will need to install the
relationalai_gnns.zipPython package that is needed to interface with the RelationalAI Native App. The process is somewhat similar with the regular Python packages that you just installed, except you will be clicking on theStage Packagestab on top and specifying the path to therelationalai_gnns.zippackage.The path needs to be fully qualified. For example
@RELATIONAL_AI_GNN.SDK_SCHEMA.SDK_STAGE/relationalai_gnns.zip.The system checks whether the path contains a valid Python package and, if yes, a green check box appears. Click
Importto import therelationalai_gnns.zippackage into your notebook.