Understand and Optimize RAI Native App Costs
Using RelationalAI (RAI) on Snowflake incurs costs from both Snowflake and RAI itself. Similar to Snowflake, RAI’s cloud architecture separates storage and compute usage, allowing for cost optimization based on specific needs.
How Costs Are Calculated
Section titled “How Costs Are Calculated”Snowflake costs are based on compute and storage resource usage, detailed in the Snowflake User Guide. RAI costs appear as a surcharge for compute usage, primarily from engines. There’s no surcharge for storage usage.
The following resources all contribute to costs generated by the RAI Native App:
Resource | Description | Snowflake Charge | RAI Surchage | Notes |
---|---|---|---|---|
App Database | Stores data used by the app. | Yes | No | This database is named RELATIONALAI unless you customized the app name during install. |
App Warehouse | Used for Snowflake interopability. | Yes | No | The RELATIONAL_AI_ERP_WAREHOUSE is automatically created the first time you activate the app. It is suspended when you deactivate the app and automatically resumed when reactivated. |
Serverless tasks | Used to schedule billing, garbage collection, upgrades, and other tasks. | Yes | No | Some tasks, like those related to billing, may generate small amounts of compute consumption even when the app is deactivated. |
Compute Pools | Used for internal app operations and to host engines. | No | No | There’s no cost for compute pools themselves. Costs are only incurred by engines hosted by each compute pool. See Compute Pools for the names and instance families of each compute pool managed by the app. |
CDC Engine | Used by the CDC Service to process data streams. | Yes | No | Costs are based on uptime and are determined by the host compute pool’s instance family and the number of compute nodes used by the engine. |
User Engines | Used to evaluate queries from RAI Python models. | Yes | Yes | Costs are based on uptime and are determined by the host compute pool’s instance family and the number of compute nodes used by the engine. |
Optimize Costs
Section titled “Optimize Costs”Configure Engines To Auto-Suspend
Section titled “Configure Engines To Auto-Suspend”Engines consume compute resources even when they’re not actively processing queries. To reduce costs, you can configure engines to auto-suspend after a period of inactivity. See Engine Suspension for more information.
Suspended engines do not consume compute resources, but they retain their configuration and data. Delete an engine when it’s no longer needed to eliminate costs entirely.
Suspend Data Streams That Don’t Require Real-Time Processing
Section titled “Suspend Data Streams That Don’t Require Real-Time Processing”Streams that don’t require minute-by-minute processing can be suspended to reduce costs. You may also disable the CDC Service to delete the CDC engine and stop processing change tracking data.
Deactivate the App When Not In Use
Section titled “Deactivate the App When Not In Use”You can deactivate the app to reduce costs while the app is not in use. When the app is deactivated, the CDC service is disabled and all engines are deleted. Tasks related to diagnostics and billing are still active and will generate small amounts of compute consumption.
Monitor Costs
Section titled “Monitor Costs”Use the queries below to monitor costs associated with your RAI Native App. For more detailed monitoring, administrators may tag the native app’s storage and compute resources to track RAI costs with Snowflake’s cost management framework.
Credits Consumed By All Engines Per Month
Section titled “Credits Consumed By All Engines Per Month”Requires the billing_admin
application role.
SELECT DATE_TRUNC('MONTH', hour) AS first_day_of_month, SUM(credits) AS sum_of_rai_unitsFROM relationalai.consumption.engine_credit_hoursGROUP BY first_day_of_monthORDER BY first_day_of_month DESC;
import relationalai as rai
SQL = """SELECT DATE_TRUNC('MONTH', hour) AS first_day_of_month, SUM(credits) AS sum_of_rai_unitsFROM relationalai.consumption.engine_credit_hoursGROUP BY first_day_of_monthORDER BY first_day_of_month DESC;"""
# Get a Provider instance.app = rai.Provider()
# Run the query and get results as a pandas DataFrame.df = app.sql(SQL, format="pandas")
# Display the results.print(df)
Credits Consumed By All Engines Per Day
Section titled “Credits Consumed By All Engines Per Day”Requires the billing_admin
application role.
SELECT DATE_TRUNC('day',c.HOUR) as day, sum(c.credits) AS total_daily_rai_unitsFROM relationalai.consumption.engine_credit_hours cWHERE hour >= DATEADD(month, -1, CURRENT_TIMESTAMP())GROUP BY all ORDER BY 1 DESC;
import relationalai as rai
SQL = """SELECT DATE_TRUNC('day',c.HOUR) as day, sum(c.credits) AS total_daily_rai_unitsFROM relationalai.consumption.engine_credit_hours cWHERE hour >= DATEADD(month, -1, CURRENT_TIMESTAMP())GROUP BY all ORDER BY 1 DESC;"""
# Get a Provider instance.app = rai.Provider()
# Run the query and get results as a pandas DataFrame.df = app.sql(SQL, format="pandas")
# Display the results.print(df)
Credits Consumed Per Engine In The Past Month
Section titled “Credits Consumed Per Engine In The Past Month”Requires the billing_admin
application role and USAGE_VIEWER
database role.
WITH engine_ownership AS ( SELECT DISTINCT REPLACE(REPLACE(REGEXP_SUBSTR(QUERY_TEXT, $$'.*',$$, 1, 1, 'e'), '\'',''), ',','') AS engine_name, max(USER_NAME) AS user_name FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY WHERE QUERY_TEXT ILIKE '%create_engine%' AND start_time >= DATEADD(month, -1, CURRENT_TIMESTAMP()) GROUP BY engine_name)SELECT c.engine_name, o.user_name, sum(c.credits) AS total_rai_units_by_engineFROM relationalai.consumption.engine_credit_hours cINNER JOIN engine_ownership o ON c.engine_name = o.engine_nameWHERE hour >= DATEADD(month, -1, CURRENT_TIMESTAMP())GROUP BY 1, 2 ORDER BY 3 DESC;
import relationalai as rai
SQL = """WITH engine_ownership AS ( SELECT DISTINCT REPLACE(REPLACE(REGEXP_SUBSTR(QUERY_TEXT, $$'.*',$$, 1, 1, 'e'), '\'',''), ',','') AS engine_name, max(USER_NAME) AS user_name FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY WHERE QUERY_TEXT ILIKE '%create_engine%' AND start_time >= DATEADD(month, -1, CURRENT_TIMESTAMP()) GROUP BY engine_name)SELECT c.engine_name, o.user_name, sum(c.credits) AS total_rai_units_by_engineFROM relationalai.consumption.engine_credit_hours cINNER JOIN engine_ownership o ON c.engine_name = o.engine_nameWHERE hour >= DATEADD(month, -1, CURRENT_TIMESTAMP())GROUP BY 1, 2 ORDER BY 3 DESC;"""
# Get a Provider instance.app = rai.Provider()
# Run the query and get results as a pandas DataFrame.df = app.sql(SQL, format="pandas")
# Display the results.print(df)
Credits Consumed Per Compute Pool Per Month
Section titled “Credits Consumed Per Compute Pool Per Month”Requires the USAGE_VIEWER
database role.
SELECT DATE_TRUNC('MONTH', START_TIME) AS first_day_of_month, compute_pool_name, SUM(credits_used) as total_creditsFROM SNOWFLAKE.ACCOUNT_USAGE.SNOWPARK_CONTAINER_SERVICES_HISTORYWHERE APPLICATION_NAME = 'RELATIONALAI'GROUP BY first_day_of_month, compute_pool_nameORDER BY first_day_of_month DESC, compute_pool_name;
import relationalai as rai
SQL = """SELECT DATE_TRUNC('MONTH', START_TIME) AS first_day_of_month, compute_pool_name, SUM(credits_used) as total_creditsFROM SNOWFLAKE.ACCOUNT_USAGE.SNOWPARK_CONTAINER_SERVICES_HISTORYWHERE APPLICATION_NAME = 'RELATIONALAI'GROUP BY first_day_of_month, compute_pool_nameORDER BY first_day_of_month DESC, compute_pool_name;"""
# Get a Provider instance.app = rai.Provider()
# Run the query and get results as a pandas DataFrame.df = app.sql(SQL, format="pandas")
# Display the results.print(df)
Credits Consumed By the App Warehouse Per Month
Section titled “Credits Consumed By the App Warehouse Per Month”Requires the USAGE_VIEWER
database role.
SELECT DATE_TRUNC('MONTH', START_TIME) AS first_day_of_month, SUM(credits_used) as total_creditsFROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORYWHERE WAREHOUSE_NAME = 'RELATIONAL_AI_ERP_WAREHOUSE'GROUP BY first_day_of_monthORDER BY first_day_of_month DESC;
import relationalai as rai
SQL = """SELECT DATE_TRUNC('MONTH', START_TIME) AS first_day_of_month, SUM(credits_used) as total_creditsFROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORYWHERE WAREHOUSE_NAME = 'RELATIONAL_AI_ERP_WAREHOUSE'GROUP BY first_day_of_monthORDER BY first_day_of_month DESC;"""
# Get a Provider instance.app = rai.Provider()
# Run the query and get results as a pandas DataFrame.df = app.sql(SQL, format="pandas")
# Display the results.print(df)