Cost Management#
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.
Customizable SQL queries for monitoring costs associated with the RAI Native App. →
Table Of Contents#
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#
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#
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.
While the CDC service is disabled, some compute is consumed as changes to data streams are tracked and queued for processing. To eliminate all costs associated with data streams, you must delete the streams.
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#
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.
COMING SOON: Snowflake will add support for detailed cost monitoring for native apps through standard cost monitoring tools.
All of the SQL queries in this section, ready to customize and run. →
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_units
FROM
relationalai.consumption.engine_credit_hours
GROUP BY
first_day_of_month
ORDER 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_units
FROM
relationalai.consumption.engine_credit_hours
GROUP BY
first_day_of_month
ORDER 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#
Requires the billing_admin
application role.
SELECT
DATE_TRUNC('day',c.HOUR) as day, sum(c.credits) AS total_daily_rai_units
FROM
relationalai.consumption.engine_credit_hours c
WHERE
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_units
FROM
relationalai.consumption.engine_credit_hours c
WHERE
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#
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_engine
FROM
relationalai.consumption.engine_credit_hours c
INNER JOIN
engine_ownership o ON c.engine_name = o.engine_name
WHERE
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_engine
FROM
relationalai.consumption.engine_credit_hours c
INNER JOIN
engine_ownership o ON c.engine_name = o.engine_name
WHERE
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)
If multiple users created an engine with the same name during the selected period, the name in the USER_NAME
column reflects the name of the last user who created the engine.
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_credits
FROM
SNOWFLAKE.ACCOUNT_USAGE.SNOWPARK_CONTAINER_SERVICES_HISTORY
WHERE
APPLICATION_NAME = 'RELATIONALAI'
GROUP BY
first_day_of_month, compute_pool_name
ORDER 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_credits
FROM
SNOWFLAKE.ACCOUNT_USAGE.SNOWPARK_CONTAINER_SERVICES_HISTORY
WHERE
APPLICATION_NAME = 'RELATIONALAI'
GROUP BY
first_day_of_month, compute_pool_name
ORDER 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#
Requires the USAGE_VIEWER
database role.
SELECT
DATE_TRUNC('MONTH', START_TIME) AS first_day_of_month,
SUM(credits_used) as total_credits
FROM
SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY
WHERE
WAREHOUSE_NAME = 'RELATIONAL_AI_ERP_WAREHOUSE'
GROUP BY
first_day_of_month
ORDER 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_credits
FROM
SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY
WHERE
WAREHOUSE_NAME = 'RELATIONAL_AI_ERP_WAREHOUSE'
GROUP BY
first_day_of_month
ORDER 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)