Snowflake Cortex Function — Complete Guide — 1
Recently, there has been a significant buzz surrounding ML/AI LLM models, sparking curiosity about how Snowflake has integrated them. To address these inquiries, you may have encountered Snowflake Cortex functions, now in public preview, generating considerable interest and excitement in the tech community. But what do these functions entail? Snowflake Cortex functions offer immediate access to LLM (Large Language Models) within Snowflake, eliminating the need for complex setup processes. This groundbreaking development paves the way for various possibilities, particularly in the realm of ML/AI LLM models.
Given the growing interest, I’ve received numerous requests to explore Snowflake Cortex functions further. Hence, I’ve decided to launch a series of blog posts dedicated to this topic. In today’s post, we’ll delve into the fundamentals: What exactly are Snowflake Cortex functions, and how can they be configured? Additionally, we’ll discuss the different types of Snowflake Cortex functions available, their availability, and the associated costs.
Unlocking the Power of Snowflake Cortex: Revolutionizing Machine Learning and AI Solutions
Snowflake Cortex, an intelligent, fully managed service revolutionizing machine learning and AI solutions within Snowflake’s ecosystem.
Within Snowflake Cortex, two key capabilities shine:
- LLM Functions: These powerful SQL and Python functions harness large language models (LLMs), enabling users to comprehend, query, translate, summarize, and generate free-form text effortlessly.
- ML-Based Functions: With these SQL functions, Snowflake Cortex empowers predictive analysis using machine learning techniques, facilitating deeper insights from structured data and accelerating everyday analytics.
What varieties of LLM and ML-Powered functions does Snowflake Cortex provide?
Snowflake Cortex currently supports the following LLM functions, which are ready for immediate use and require no complex setup.
Snowflake Cortex currently supports following ML-Based functions,
Now in these series of blog we will see more LLM functions which are present in snowflake cortex and how to Operate the same.
Exploring the Regional Availability of Snowflake Cortex Functions:
As of today, Snowflake Cortex functions are accessible across several regions, including mentioned below in the list:
It’s important to note that while some functions are available in all regions, others might be limited to specific regions. Before exploring the various functions, it’s crucial to understand this regional availability aspect.
Understanding the Models Utilized by Snowflake Cortex LLM Functions:
Next, we’ll delve into the models utilized by Snowflake Cortex LLM functions. In the below complete as the snowflake function runs any of the following models like
Now, we’ll explore functions that operate on Snowflake-managed models.
Below is the table listing the models used for various functions across different regions, sourced from the Snowflake documentation.
Now that we’ve established the availability of Snowflake Cortex functions across different regions, it’s crucial to understand the privileges necessary to access these powerful tools. Snowflake Cortex functions are specifically accessible to users who are assigned to the CORTEX_USER
database role within the Snowflake database.
But what exactly is a database role, and how can one obtain access to it? A database role in Snowflake is essentially a collection of privileges or permissions that define what actions users can perform within the database. These roles streamline access control and security management within the Snowflake environment.
To gain access to the CORTEX_USER
database role, users typically need to be granted this role by a user with sufficient privileges, such as a Snowflake account administrator or a user with the necessary role-granting permissions. Once assigned, users in the CORTEX_USER
role will have the necessary privileges to leverage the capabilities of Snowflake Cortex functions.
Understanding database roles and how to obtain access to them is essential for users looking to leverage the full potential of Snowflake Cortex functions within their data workflows.
Understanding Database Roles in Snowflake:
When an account is provisioned in Snowflake, the SNOWFLAKE database is automatically imported. This database serves as a prime example of Snowflake’s utilization of Secure Data Sharing, providing object metadata and usage metrics for your organization and accounts.
Access to schema objects within the SNOWFLAKE database is meticulously controlled by a variety of database roles.
To elaborate on this concept, let’s consider a simple example scenario:
Imagine you’re logged in as a Snowflake admin. You execute the following SQL query to display the database roles present within the Snowflake database:
SHOW DATABASE ROLES IN DATABASE SNOWFLAKE;
Now, we observe that cortex_user
is prominently displayed and highlighted in the above figure 7, underscoring its importance. Access to this specific role is pivotal for utilizing Snowflake Cortex functions effectively.
Moving forward, our next step involves creating the user and assigning an active warehouse to them.
-- Switch to SYSADMIN role
USE ROLE SYSADMIN;
-- Create or replace warehouse 'CORTEX_WH' with XSMALL size
CREATE OR REPLACE WAREHOUSE CORTEX_WH
WAREHOUSE_SIZE = 'XSMALL';
-- Create or replace database 'CORTEX_DB_1'
CREATE OR REPLACE DATABASE CORTEX_DB_1;
-- Create or replace schema 'CORTEX_SCH' (assuming within 'CORTEX_DB_1')
CREATE OR REPLACE SCHEMA CORTEX_SCH;
-- Switch to SECURITYADMIN role
USE ROLE SECURITYADMIN;
-- Create or replace role 'SNOWFLAKE_CORTEX_ROLE'
CREATE OR REPLACE ROLE SNOWFLAKE_CORTEX_ROLE;
-- Switch back to SYSADMIN role
USE ROLE SYSADMIN;
-- Grant USAGE privilege on warehouse 'CORTEX_WH' to role 'SNOWFLAKE_CORTEX_ROLE'
GRANT USAGE ON WAREHOUSE CORTEX_WH TO ROLE SNOWFLAKE_CORTEX_ROLE;
-- Switch back to SECURITYADMIN role
USE ROLE SECURITYADMIN;
-- Create or replace user 'CORTEX_USER_1' with password 'XXXXX', must change password on first login, and set default role to 'SNOWFLAKE_CORTEX_ROLE'
CREATE OR REPLACE USER CORTEX_USER_1 PASSWORD = 'XXXXX' MUST_CHANGE_PASSWORD = TRUE DEFAULT_ROLE = SNOWFLAKE_CORTEX_ROLE;
-- Grant role 'SNOWFLAKE_CORTEX_ROLE' to user 'CORTEX_USER_1'
GRANT ROLE SNOWFLAKE_CORTEX_ROLE TO USER CORTEX_USER_1;
When logging in for the first time and querying the Snowflake database using the user CORTEX_USER_1
, executing the following query will yield the indicated result:
SHOW DATABASE ROLES IN DATABASE SNOWFLAKE;
In the output, Snowflake Cortex functions are not visible. To address this, we need to take the following actions in order to enable the viewing of Snowflake Cortex functions:
USE ROLE ACCOUNTADMIN;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE SNOWFLAKE_CORTEX_ROLE;
Now, let’s switch to the respective CORTEX_USER_1
user and verify their access.
Now that we’ve successfully gained access to Snowflake Cortex functions, it’s time to delve deeper into each function individually. We’ll explore the capabilities and features of Snowflake Cortex functions step by step, uncovering their potential and understanding how they can enhance data analytics and processing within the Snowflake environment.
Stay tuned as we embark on an in-depth exploration of Snowflake Cortex functions, unlocking their power and possibilities.
COMPLETE:
The first function we’ll explore is the Snowflake Cortex Complete
function, which offers a wide range of use cases. This function generates responses based on prompts provided by the user, utilizing a chosen language model.
In its simplest form, the Complete function can generate a response from a single string prompt. Alternatively, it can handle interactive chat-style conversations, where multiple prompts and responses are provided. Users can also customize the style and size of the output by specifying hyperparameter options.
It’s important to note that all Snowflake Cortex Language Model (LLM) functions incur compute costs based on the number of tokens processed. Tokenization is a crucial aspect of Snowflake Cortex, where a token represents the smallest unit of text processed. Generally, a token is approximately equal to four characters of text, although this equivalence can vary depending on the specific language model being used.
Understanding the Snowflake Cortex Complete
function and its underlying tokenization process is essential for leveraging its capabilities effectively within data analytics and processing workflows.
I’ll conclude here for now but stay tuned for the next blog where we’ll take a deeper dive into the Snowflake Complete function. We’ll explore its functionalities, use cases, and how it can enhance your data processing tasks within the Snowflake environment.
References: -
About me:
I am a Cloud Data Architect with experience as a Senior Consultant at EY New Zealand. Throughout my career, I have worked on numerous projects involving legacy data warehouses, big data implementations, cloud platforms, and migrations. If you require assistance with certification, data solutions, or implementations, please feel free to connect with me on LinkedIn.