RelationalAI in Cloud Notebooks#
You can use RelationalAI in cloud notebook environments like Google Colab or Hex.
This guide shows you how to set up the relationalai
package in these environments.
Google Colab#
Installation#
Begin by installing relationalai
from PyPI by pasting the following code into the first cell and doing shift+enter
to run it:
#!pip install relationalai
Note that the exclamation mark !
marks the command as a shell command in Colab.
Setup#
Click on the key icon in the left sidebar to open the user secrets editor.
Add your password with the key snowflake_password
.
Then fill in the following code snippet with your Snowflake account details:
#import relationalai as rai
from relationalai.clients.config import Config
from google.colab import userdata
snowflake_password = userdata.get('snowflake_password')
snowflake_account = ""
snowflake_user = ""
snowflake_role = ""
snowflake_warehouse = ""
rai_engine_name = ""
config = Config({
"platform": "snowflake",
"authenticator": "snowflake",
"account": snowflake_account,
"user": snowflake_user,
"password": snowflake_password,
"role": snowflake_role,
"warehouse": snowflake_warehouse,
"rai_app_name": "relationalai",
"engine": rai_engine_name,
})
model = rai.Model("Example", config=config)
Run this cell to define the model
object and connect to your Snowflake account.
Usage#
Now you can use model
to run queries as usual:
#with model.query() as select:
z = select(1 + 1)
print(z.results)
Hex#
Installation#
Run the following command in a Python cell in a Hex notebook to install the relationalai
package:
#!pip install relationalai
Setup and Usage#
Using Hex’s Snowflake Integration#
If you have connected to your Snowflake account from Hex and enabled Snowpark, you can use the hextoolkit
module to obtain a session
object and use it to create a model
object:
#import relationalai as rai
import hextoolkit
hex_snowflake_conn = hextoolkit.get_data_connection("<Your Snowflake Connection Name>")
hex_snowpark_session = hex_snowflake_conn.get_snowpark_session()
model = rai.Model("Example", connection=hex_snowpark_session)
with model.query() as select:
z = select(1 + 1)
print(z.results)
Connecting to Snowflake from Python#
Alternatively, you can connect to Snowflake from Python using the relationalai
package:
Click on the Variables menu item in the left sidebar. Enter your Snowflake password as a secret. Paste the code below and fill in your account details:
#import relationalai as rai
from relationalai.clients.config import Config
config = Config({
"platform": "snowflake",
"authenticator": "snowflake",
"account": "<SNOWFLAKE_ACCOUNT>",
"user": "<SNOWFLAKE_USER>",
"password": snowflake_password,
"role": "<SNOWFLAKE_ROLE>",
"warehouse": "<SNOWFLAKE_WAREHOUSE>",
"rai_app_name": "relationalai",
"engine": "<RAI_ENGINE_NAME>",
})
model = rai.Model("Example", config=config)
with model.query() as select:
z = select(1 + 1)
print(z.results)
Next steps#
To begin exploring RelationalAI’s capabilities, check out the Getting Started guide or the Example Notebooks.