Get Started with RAI in a Cloud Notebook
You can use RelationalAI in cloud notebook environments like Google Colab or Hex. Click on the tabs below to see the instructions for each cloud notebook environment.
Install RelationalAI
Section titled “Install RelationalAI”Paste the following code into a Google Colab cell and press ++shift+enter++ to run it:
%pip install relationalai
Note that the percent sign %
marks the command as a shell command in Colab.
Run the following command in a Python cell in a Hex notebook to install the relationalai
package:
%pip install relationalai snowflake-connector-python==3.11.0
Set Up Your Snowflake Connection
Section titled “Set Up Your Snowflake Connection”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 and execute it to create a RAI model and connect to your Snowflake account:
import relationalai as rai
from google.colab import userdata
rai.save_config(f""" account = "<SNOWFLAKE_ACCOUNT>" user = "<SNOWFLAKE_USER>" password = {userdata.get('snowflake_password')} role = "<SNOWFLAKE_ROLE>" warehouse = "<SNOWFLAKE_WAREHOUSE>"""")
There are two ways to connect to Snowflake from Hex:
-
Using the
hextoolkit
module.If you have connected to your Snowflake account from Hex and enabled Snowpark, you can use the
hextoolkit
module to obtain asession
object and use it to create amodel
object:import relationalai as raiimport hextoolkithex_snowflake_conn = hextoolkit.get_data_connection("<Your Snowflake Connection Name>")hex_snowpark_session = hex_snowflake_conn.get_snowpark_session()model = rai.Model("MyFirstModel", connection=hex_snowpark_session) -
Using the
relationalai
package: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 rairai.save_config(f"""account = "<SNOWFLAKE_ACCOUNT>"user = "<SNOWFLAKE_USER>"password = {snowflake_password}role = "<SNOWFLAKE_ROLE>"warehouse = "<SNOWFLAKE_WAREHOUSE>"""")
-
Run a Test Query
Section titled “Run a Test Query”Verify that the relationalai
package is installed and working correctly by running the following code:
import relationalai as rai
# Create a model named "MyFirstModel".model = rai.Model("MyFirstModel")
# Send a test query.with model.query() as select: response = select(1 + 1)
# The results are stored as a pandas DataFrame in the response.results attribute.print(response.results)# v# 0 2