Resource budgets for Cortex Search¶
A resource budget lets you monitor Cortex Search spend and take automated actions, such as revoking access, when consumption exceeds configured limits. Budgets apply at an aggregated level to credits consumed by a specific Cortex Search service.
How resource budgets work¶
Resource budgets use Snowflake’s tag-based cost attribution model. You create a tag, apply it to a Cortex Search service, and then associate that tag with a budget. Snowflake tracks credit consumption for the tagged service and evaluates spending against the budget limit periodically. The resource budget is useful for limiting the spend for the Cortex Search service.
Snowflake enforces resource budgets with the following flow:
- You create a tag.
- You apply the tag to the Cortex Search service.
- You create a budget and specify the tag to track spending for. As part of creating the budget, you also set a monthly spending limit in credits.
- You add a stored procedure to be executed when spending reaches a configured threshold of the budget. For example, you can invoke a stored procedure for alerting at 80% and another stored procedure for revoking access at 100%.
- Snowflake tracks credit consumption for the tagged service.
- When spending reaches a configured threshold of the budget, such as 80% or 100%, Snowflake executes the stored procedure defined for that threshold.
Snowflake calculates usage, evaluates thresholds, and triggers any configured actions periodically. After the budget is exceeded, it might take up to eight hours with standard budget (or two hours with latency optimized option) for the budget to be enforced.
Create a tag¶
-
Create a tag to identify the cost center associated with the Cortex Search service:
-
Apply the tag to the Cortex Search service to associate it with a cost center:
Set up a resource budget¶
You can use either Snowsight or SQL to create a budget and associate it with a Cortex Search service.
- Sign in to Snowsight.
- In the navigation menu, select Admin » Cost management.
- Select Budgets.
- Select + Budget.
- For Location to store, select the name of the database and schema where you want to create the budget.
- For Name, use
my_budget. - For Budget (credits per month), enter a value, such as 10000, for the spending limit of the budget.
- To decrease the budget refresh interval so you can watch spending more closely, select Enable low latency budget.
- For Threshold, enter a value, such as 80, for the notification threshold.
- For Notify, enter email addresses to receive notification emails.
- Select Next.
- For Budget scope, add the tag on the Cortex Search service to the resource budget.
- Select Create.
-
Create a budget instance in the schema where you manage budgets:
-
Set the monthly credit spending limit for the budget:
-
Add the tag to the budget so that Snowflake tracks spending for the tagged service against this budget:
Now, Snowflake tracks credit consumption for my_search_service against the my_budget budget
with a 10,000-credit monthly limit.
Configure threshold actions¶
You can attach stored procedures that are executed when spending reaches specific thresholds, which are expressed as a percentage of the spending limit and apply to the monthly budget period. For more information, see Custom actions for budgets.
Send notifications¶
You can send notifications when spending reaches a threshold. For more information, see Notifications for budgets.
-
Set the email to send notifications to:
-
Set the notification threshold:
Revoke access and suspend the service¶
-
Create a stored procedure that revokes access to the Cortex Search service and suspends the service to stop ongoing costs. In the stored procedure, you can limit access to a specific role to revoke USAGE for that role. Suspending both the indexing and serving layers stops warehouse compute, embedding, and serving charges for the service.
Important
Ensure the
role_nameand the user do not have access to the Cortex Search service through other roles. The role that runs this stored procedure must have the OPERATE privilege on the Cortex Search service to suspend it. For guidance about configuring roles and privileges correctly, see Required privileges. -
Set a custom action that blocks access when 100% of the budget has been spent. You can also use custom actions for notifications.
Note
You can also use custom actions to take action when spending is forecasted to exceed the budget limit. For more information, see Custom actions for budgets.
Handling exceptions to spending limits¶
In some cases, you may need to reinstate access after the budget limit is reached, like during earnings season or other peak periods. You can configure thresholds beyond 100%, up to 500%, to handle these exception scenarios.
The workflow assumes that access is revoked and the service is suspended using the configured stored procedure when spending reaches a budget threshold. The admin reinstates a subset of the users and grants access back. When spending reaches 200%, the revocation procedure runs again as a hard stop.
-
Create a stored procedure to resume the service and reinstate access to the role:
-
During an exception period, an admin manually reinstates access by calling the reinstatement procedure. Configure a 200% threshold as a hard stop so the revocation procedure runs again if spending continues to grow:
Reinstate access¶
To ensure that users can access the Cortex Search service again at the start of the next budget period, configure the sp_reinstate_search_access procedure from the previous section to run when the budget cycle restarts.
- Set a cycle-start action for the budget:
Setting alerts based on projected spend¶
To receive an alert or perform an action based on forecasted spend rather than actual spend, you can set the trigger type to PROJECTED. For example, to call a stored procedure named alert_team when projected consumption reaches 75% of the budget limit, run the following command:
List custom actions¶
- To list all custom actions configured on a budget, use the GET_CUSTOM_ACTIONS method:
For more information, see Custom actions for budgets.
Monitor usage¶
-
To view credit consumption per Cortex Search service, use the budget’s usage reporting method:
The output includes the following columns:
Column Description Service type The service category (AI) Entity type The object type (CORTEX_SEARCH_SERVICE) Entity ID The unique identifier of the Cortex Search service Name The display name of the Cortex Search service Credits used The total credits consumed during the specified period Cloud services credits Number of cloud service credits used
Budget enforcement latency¶
Budget calculations and threshold enforcement are conducted periodically:
- Snowflake calculates credit consumption for the tagged Cortex Search service.
- The system evaluates spending against all configured thresholds.
- If a threshold is reached, the associated stored procedure is executed.
- Usage dashboards are updated with the latest figures.
If you have enabled the low latency budget, your budgets are enforced in two hours after the budget is exceeded. Otherwise, it may take up to eight hours after the budget is exceeded for enforcement. You can trigger budget execution more frequently, such as every sixty minutes, to reduce the refresh interval.
Warning
There is an inherent delay between when credits are consumed and when the budget system detects the threshold breach. During the enforcement interval, spending can exceed the configured threshold before the action is executed. Plan your thresholds accordingly. For example, set an alert at 80% to give you time to respond before the 100% action is triggered.
Limitations¶
The following limitations apply to resource budgets for Cortex Search:
- Single-service resources only: Resource budgets apply to the entire Cortex Search service.
- Enforcement latency: Budget enforcement runs on a periodic cycle and may take up to eight hours after the budget is exceeded to enforce the budget. Spending can exceed a threshold during the interval before the action triggers.
- Role-based access revocation and service suspension: To revoke access at a threshold, you must revoke USAGE on the Cortex Search service from the affected roles. To stop ongoing indexing and serving costs, suspend the service using
ALTER CORTEX SEARCH SERVICE ... SUSPEND. - Monthly period: Budgets operate on a monthly cycle. You can’t configure resource budget periods.
- Tag latency: When you change a tag on an object, it can take up to eight hours after the change to be reflected in budgets that use tags. For more information, see Custom budgets.