Understanding Snowflake Cortex functions

Thanks for reading my earlier blogs, this blog helps you learn and develop a basic understanding of Snowflake Cortex. You will learn to use the Snowflake Cortex functions in the next blog.

Snowflake Cortex is a managed service that offers AI and ML solutions to users. There are two types of functions offered by Snowflake:

  1. LLM Functions: These are SQL and Python-based functions that can be used to develop an understanding, query, translate, summarize, and generate free-form text.

2. ML-Based Functions: These are SQL functions based on the ML algorithms that are used to derive predictions.

These services and offerings from Snowflake enable users to develop and use AI/ML and LLM capabilities within the platform without moving data anywhere else.

These services also help with other intelligent features like Document AI, Universal Search, or Copilot. These features are currently in private preview and you can enable them by contacting the Snowflake representative.

What are the LLM functions available?

You might have heard about LLM functions during SNOWDAY announcements as well as read about them with Snowflake documentation. You can refer to below LLM functions below to learn about each of them:

  1. SUMMARIZE(): Used to get a synopsis of the text provided.
  2. COMPLETE(): Used to perform the complex reasoning of the tasks.
  3. SENTIMENT(): Used to get the sentiments based on the text
  4. TRANSLATE(): Used to translate text from one language to another
  5. EXTRACT_ANSWER(): Used to get or extract the answer from the given semi-structured or unstructured data

Not all functions are available to all regions on AWS and Azure. These are available on the below regions for given cloud providers:

Snowflake documentation Image

What are the ML-based functions?

Similarly, there are ML functions that can be used to implement ML use cases like prediction or forecasting. You can use the below functions:

  1. Forecasting: Used to get predictions based on the factors provided.
  2. Anomaly Detection: Used to find potential outliers in the data
  3. Classification: Used for classification and categorizing data into identified classes
  4. Low-code web interface using ML-powered function that allows users to use functionalities without writing SQL code

What are the privileges required to use functions?

CORTEX_USER is a database role that includes the privileges that allow users to call Snowflake Cortex LLM functions. This is a default role granted to the ACCOUNTADMIN however ACCOUNTADMIN can grant permissions to the user roles. This role cannot be granted to the user directly. This is the DATABASE ROLE and you can grant it to existing custom roles using GRANT command.

How much do these functions cost?

These functions’ usage is calculated based on the compute usage and compute is calculated based on the tokens processed. The below table represents the cost of million tokens

Snowflake documentation: Credit usage for LLM functions

How can I measure the usage of the functions?

Snowflake USAGE views store metadata information that can be used to measure the usage and billing of the services or features being used. You can use METERING_DAILY_HISTORY view and service type as “ai_services” to filter the usage metadata information. You can get usage for a month using below query:

SELECT 
SERVICE_TYPE,
sum(CREDITS_USED) as total_credits_used
FROM SNOWFLAKE.ORGANIZATION_USAGE.METERING_DAILY_HISTORY
WHERE service_type ILIKE '%ai_services%'
and datediff(day,usage_date,current_date)=30;

Are there any quotas or limitations for these services?

To maintain a high standard of performance across customers, Snowflake cortex LLM functions are subject to usage quotas. Snowflake has below quotas for each of the LLM functions:

Snowflake documentation: quotas for functions

Are there any restrictions with these functions or models?

Models used for these LLM functions have limitations in terms of tokens. Each of the functions and models used has limitations. You can refer to the below snapshot from Snowflake documentation that represents the token limit for each function.

Snowflake documentation: Token limits per function

As you can see here, the limitations are specific to the model used for functions. e.g. COMPLETE function can be used with model types as shown above. You can pick the model based on your application requirements and usage quota as listed above.

Hope you like this blog and learn the basics of the LLM functions as part of the Snowflake cortex. You will learn more about using these functions in upcoming blogs.

About Me :

I am one of the Snowflake Data Superheroes 2023 & 2024. I am a DWBI and Cloud Architect! I am currently working as Senior Data Architect — GCP, Snowflake. I have been working with various Legacy data warehouses, data implementations, and Cloud platforms/Migrations. I am a SnowPro Core certified Data Architect as well as a Google-certified Google Professional Cloud Architect. You can reach out to me on LinkedIn if you need any further help on certification, Data Solutions, and Implementations!

--

--