Snowflake Cortex is an advanced data processing engine integrating AI and ML capabilities into Snowflake's cloud platform, offering LLM functions for text processing and ML functions for predictive analysis without complex setup or data migration concerns.
In today's data-driven world, where information reigns supreme, businesses are constantly seeking innovative solutions to efficiently manage and analyze their data. Snowflake, a leading cloud data platform, has been at the forefront of this revolution, consistently pushing the boundaries of what's possible in data management. Their latest offering, Snowflake Cortex, represents a significant leap forward in data processing capabilities, promising to revolutionize how organizations harness the power of their data.
Snowflake Cortex is an advanced data processing engine built on top of Snowflake's existing cloud data platform. It integrates seamlessly with Snowflake's data warehouse and data lake capabilities, providing users a unified platform for storing, processing, and analyzing their data at scale. At its core, Cortex is designed to address modern data workloads' growing complexity and diversity, offering unparalleled performance, scalability, and flexibility. By seamlessly integrating ML and AI capabilities into the Snowflake platform, Cortex enables users to leverage advanced analytics and gain deeper insights from their data.
Snowflake Cortex gives you instant access to industry-leading large language models (LLMs) developed by researchers at companies like Mistral, Reka, Meta, and Google, including Snowflake Arctic, an open enterprise-grade model developed by Snowflake.
Since Snowflake fully hosts and manages these LLMs, using them requires no setup. Your data stays within Snowflake, giving you the performance, scalability, and governance you expect. Snowflake Cortex features are accessible as SQL functions and are also available in Python. The available functions are summarized below:
Additionally, Snowflake Cortex offers text embedding and vector comparison features for semantic analysis, which are currently in private preview with select customers. These capabilities provide users with instant access to state-of-the-art LLMs without the need for complex setup, ensuring data security within the Snowflake environment.
In data processing and sentiment analysis, Snowflake Cortex's COMPLETE function is a standout tool for automating sentiment assessment in text data. This function generates responses using a chosen language model based on a given prompt. It supports simple use cases with single-string prompts and more complex interactive chat scenarios with multiple prompts and responses. Additionally, users can customize the output by specifying hyperparameter options for style and size.
SNOWFLAKE.CORTEX.COMPLETE( <model>, <prompt_or_history> [ , <options> ] )
<model>: The COMPLETE function supports the following models.
Model Options 1Model Options 2snowflake-arctic, mistral-large, reka-flash, reka-core, mixtral-8x7bllama2-70b-chat, llama3-8b, llama3-70b, mistral-7b, gemma-7b
<prompt_or_history>: Your response to the prompt. It can be a string or a table.
SELECT SNOWFLAKE.CORTEX.COMPLETE('mistral-large', CONCAT('Critique this review in bullet points: <review>', content, '</review>')) FROM reviews LIMIT 10;
<options>: Argument to control the inference hyperparameters in a single response. Specifying the options argument, even if it is an empty object ({}), affects how the prompt argument is interpreted and how the response is formatted.
Example: Here the hyperparameters are temperature and max_tokens
SELECT SNOWFLAKE.CORTEX.COMPLETE(
'llama2-70b-chat',
[
{
'role': 'user',
'content': 'how does a snowflake get its unique pattern?'
}
],
{
'temperature': 0.7,
'max_tokens': 10
}
);
temperature: A value from 0 to 1 (inclusive) that controls the randomness of the output of the language model.
max_tokens: Sets the maximum number of output tokens in the response. Small values can result in truncated responses.
Let's explore a technical application of the COMPLETE function in real-world scenarios, specifically for analyzing sentiment in financial data.
Problem: Determine the sentiment of customer responses in the FINANCIAL_SENTIMENT_DATA table.
Solution: Using the llama2-70b-chat model and customer responses from the table, the COMPLETE function predicts whether each response is positive, negative, or neutral. The prompt includes the string and the sentence column from the FINANCIAL_SENTIMENT_DATA table, specifying that the response should be a single word. The output for each sentence is then added to a new column, COMPLETE_OUTPUT, in the same table.
OUTPUT:
The following output shows the CORTEX_RESULT column, which represents the output generated by the COMPLETE function model. This table demonstrates how the COMPLETE function assesses sentiment in customer responses, categorizing each as positive, negative, or neutral.
In conclusion, by utilizing Snowflake Cortex's COMPLETE function and Snowflake's robust data processing capabilities, organizations can automate sentiment analysis tasks and extract valuable insights from textual data efficiently.
SNOWFLAKE.CORTEX.SENTIMENT(<text>)
<text>: A string containing the text for which the sentiment score is to be determined.
RETURNS: A floating-point number ranging from -1 to 1 (inclusive) indicates the text's sentiment level. Negative values represent negative sentiment, positive values indicate positive sentiment and values near 0 suggest neutral sentiment.
In this example, a table named FINANCIAL_SENTIMENT_DATA_OUTPUT contains a column named SENTIMENT with user text reviews. The query returns a sentiment score for each review.
SELECT SNOWFLAKE.CORTEX.SENTIMENT(SENTIMENT) AS SCORE, SENTIMENT FROM FINANCIAL_SENTIMENT_DATA_OUTPUT LIMIT 10;
Output: The sentiment score of each review is added in the SCORE column.
The SUMMARIZE function condenses a given English-language text into a concise summary.
SNOWFLAKE.CORTEX.SUMMARIZE(<text>)
Returns: A string with the summary of the original text.
SELECT SENTENCE, SNOWFLAKE.CORTEX.SUMMARIZE(SENTENCE) as SUMMARY FROM CORTEX_DB.SENTIMENT_TEST_DATASET.FINANCIAL_SENTIMENT_DATA_OUTPUT limit 100;
Output:
Consider one sentence from the above output:
SENTENCE: The percentages of shares and voting rights have been calculated in proportion to the total number of shares registered with the Trade Register and the total number of voting rights related to them.
SUMMARY: Shares and voting rights have been proportionally calculated based on the total registered shares and related voting right.
The EXTRACT_ANSWER function retrieves an answer to a specific question from a text document.
SNOWFLAKE.CORTEX.EXTRACT_ANSWER(<source_document>, <question>)
Returns: A string with the answer to the given question.
In this example, SENTENCE is a column from the FINANCIAL_SENTIMENT_DATA_OUTPUT table. To extract an answer from each row of the table:
SELECT SENTENCE, SNOWFLAKE.CORTEX.EXTRACT_ANSWER(SENTENCE, 'What dishes does this review mention?') as ANSWER FROM CORTEX_DB.SENTIMENT_TEST_DATASET.FINANCIAL_SENTIMENT_DATA_OUTPUT LIMIT 10;
The EMBED_TEXT_768 function generates a vector embedding from English-language text.
SNOWFLAKE.CORTEX.EMBED_TEXT_768( <model>, <text> )
Returns: A vector embedding of type VECTOR.
In this example, a vector embedding is generated for the phrase hello world using the snowflake-arctic-embed-m model:
SELECT SNOWFLAKE.CORTEX.EMBED_TEXT_768('snowflake-arctic-embed-m', 'hello world');
The TRANSLATE function translates text from one supported language to another
SNOWFLAKE.CORTEX.TRANSLATE(<text>, <source_language>, <target_language>)
Returns: A string containing the translated text.
The following example translates each row of a table from English to German (in this example, review_content is a column from the reviews table):
SELECT SNOWFLAKE.CORTEX.TRANSLATE(review_content, 'en', 'de') FROM reviews LIMIT 10;
Snowflake Cortex's ML Functions empower analysts, data engineers, and business users to perform predictive analysis and gain valuable insights from their structured data. These functions, accessible through SQL, include:
Additionally, Snowflake Cortex offers advanced ML features, such as classification functions and a low-code web interface for ML functions within Snowsight, which is currently in private preview with select customers.
For data scientists and developers seeking more customization and control over ML models, Snowflake Cortex offers Snowpark ML. Snowpark ML provides a Python API that allows users to develop, deploy, and utilize their ML models directly within the Snowflake environment. This flexibility enables data scientists to tailor ML solutions to their specific needs and seamlessly integrate them into their data workflows.
In summary, Snowflake Cortex represents a significant advancement in data analytics and AI, providing users with a comprehensive suite of ML and AI capabilities directly within the Snowflake platform. From LLM Functions for processing unstructured text data to ML Functions for predictive analysis, Cortex offers a range of tools to unlock insights and drive innovation. With Snowpark ML, data scientists can further extend Cortex's capabilities, empowering them to develop custom ML solutions tailored to their unique requirements.
The versatility and power of Snowflake Cortex make it well-suited for a wide range of use cases across industries:
Snowflake Cortex represents a paradigm shift in data processing technology, empowering organizations to unlock the full potential of their data assets and drive digital transformation at scale. By combining the power of AI, MPP, and cloud-native architecture, Cortex offers unmatched performance, scalability, and flexibility, making it the ideal platform for modern data-driven enterprises. As businesses continue to embrace the era of data-driven decision-making, Snowflake Cortex stands ready to lead the charge into a future where data is not just a resource but a strategic asset driving innovation and growth.