Community Detection using RelationalAI
Overview
In this quickstart, we'll use RelationalAI — a Native App available in the Snowflake Marketplace — to run community detection algorithms. The sample data represent food-truck orders, and we'll use them to identify groups of customers who probably know each other. This allows us to build a social graph and interact with groups of related customers.
What Is RelationalAI?
RelationalAI is a cloud-native platform that enables organizations to streamline and enhance decisions with intelligence. RelationalAI extends Snowflake with native support for an expanding set of AI workloads (e.g., graph analytics, rule-based reasoning, and optimization), all within your Snowflake account, offering the same ease of use, scalability, security, and governance.
Users can build a knowledge graph using Python and materialize it on top of their Snowflake data, which are shared with the RelationalAI app through Snowflake Streams. Insights can be written to Snowflake tables and shared across the organization.
What You’ll Learn
- How to discover new insights by running a variety of graph algorithms on your Snowflake data
- How to complement your graph analytics with graph visualizations
- How — thanks to native applications with Snowpark Container Services — we can do all of this within the Snowflake Data Cloud
What You’ll Need
- A Snowflake Account on AWS in the US East (N. Virginia) region or the US West (Oregon) region.
- Basic knowledge of using a Snowflake SQL Worksheet
- Snowflake privileges on your user to install a Native Application
- Either:
- Snowflake privileges to create databases and schemas in your Snowflake account, or
- A Snowflake table called
RAI_DEMO.TASTYBYTES.ORDERthat contains the data used in this quickstart.
- The RAI Community Detection Jupyter notebook used in this quickstart
What You’ll Build
- A community detection analysis to find which food truck customers frequently eat together
- A visualization of this data
NOTE: If you do not already have the RelationalAI Native App installed, please follow the instructions here
Set Up Your Environment
In addition to your Snowflake account setup, follow the steps below to set up a local installation of Python with Jupyter Lab and the RelationalAI Python library.
- Create a directory for this project and place the demo notebook in it.
- Navigate to your project directory in your operating system's terminal application.
- Check your Python installation:
- Run
python3 --versionfrom your terminal.- If your Python version starts with 3.10 or 3.11, it's compatible with the RelationalAI Python library.
- Otherwise, you'll need to download and install Python:
- Download the installer for your OS from the Python 3.11 download page
- Run the installer.
- Verify that Python 3.11 is available by running
python3.11 --versionfrom your terminal.
- Run
- Set up a virtual environment for the packages you'll install:
python3.11 -m venv .venv # or python3 -m venv .venv, if you don't have a python3.11 executable source .venv/bin/activate # Activate on Linux and macOS. # .venv\Scripts\activate # Activate on Windows. python -m pip install jupyterlab relationalai
RelationalAI Config File
After installing the relationalai package, you will need to set up a RAI configuration with the Snowflake credenrtials you want to use (similar to the configuration for Snowflake CLI).
Run rai init from your terminal and follow the prompts to enter your credentials and other configuration data:

- Choose
Snowflakeas your host platform. - Select a profile from
~/.snowflake/connections.tomlif you have one, or enter your username, password, and Account ID otherwise. - Select your role
rai_userthat you created earlier. - Select a Snowflake warehouse.
- Select
[CREATE A NEW ENGINE]to create a new engine. Enter any name you want for the engine, for examplerai_engine. (Usually you would not want to select the same engine you created above for CDC.) - Select
HighMem|Sas the engine size. - Choose the compute pool
rai_compute_poolthat you created above. - Press
Enterto accept the default profile name ofdefault.
Run the Notebook in Jupyter Lab
-
Start Jupyter Lab with the following command:
jupyter laband visit the URL (something like
http://localhost:8888/lab?token=XXXX) printed in the console output in your browser. -
Open the
community-detection.ipynbfile in Jupyter lab. You should see the top of the notebook:

-
If you don't already have a Snowflake table called
RAI_DEMO.TASTYBYTES.ORDERS, scroll down to the Appendix and run the cells in that section to insert the data for this demo into your Snowflake account. -
The notebook will guide you through defining a knowledge graph!
Conclusion & Resources
Congratulations on completing the our Community Detection using RelationalAI guide! In this Quickstart you learned
- How to install the RelationalAI Native App from the Snowflake Marketplace
- How to build a knowledge graph on top of your Snowflake data without having to export your data from Snowflake
- How to run graph algorithms on your knowledge graph and visualize relationships in the graph
Resources
- To learn about more about RelationalAI and view full documentation, visit https://relational.ai
- Louvain community detection method
- Snowflake Marketplace
- More info on Snowflake Native Apps
- Fork the Repo on GitHub
- Download Reference Architecture
- Read the Blog
- Watch the Demo
This content is provided as is, and is not maintained on an ongoing basis. It may be out of date with current Snowflake instances