How to use Snowflake Cortex & Omni together

Enrich data, analyze sentiment, and answer questions with AI

Snowflake Cortex blog hero image

One of my favorite parts of working with Omni customers is seeing how they use our AI functionality to query data. It’s opened up many cool use cases, like helping people figure out what questions to ask, write complicated Excel calcs, and more.

When I discovered Snowflake Cortex (Snowflake’s suite of LLM functions), I got excited to see the new possibilities it could open up for our customers.

In this blog, I’ll show you a few ways to integrate AI into your Omni workflows with Cortex – covering data enrichment, summarization, sentiment analysis, and ChatGPT-style questions. If you’re already using Omni, check out the code snippets below to quickly apply these functions to your own analyses.

Ways to use Snowflake Cortex in Omni #

In this demo, I walk through a few workflows in Omni with Snowflake Cortex:

  • Enrichment lets you add more info to existing data using AI. So, when you get a new sales lead, AI can instantly give your sales reps context on the account, like the number of employees, when it was founded, etc., without needing to do manual research.

  • Summarization with AI allows you to understand your data at a glance. For example, customer success managers can get a summary of a customer’s usage data before a renewal meeting so they know how to provide the most value.

  • ChatGPT-style questions with the COMPLETE function mean you can ask anything about your data and get an AI-generated answer. For example, an inventory analyst planning their monthly inventory could ask, “Based on this sales and inventory data, what should I include in my next merchandise order?”

  • Sentiment analysis with the SENTIMENT function assigns an AI-generated sentiment score from -1 to 1 based on some input text. This is especially useful for analyzing unstructured text, like customer reviews or survey responses. With sentiment analysis, product managers can quickly track trends in customer feedback to identify and learn from particularly positive or negative comments.

  • Categorization with the CLASSIFY_TEXT function sorts values into categories with AI. For example, a customer support manager could use categorization to sort customer requests into bugs, feature requests, or enhancements to quickly prioritize them and take next steps.

How to get started with Snowflake Cortex functions in Omni #

Snowflake Cortex SQL functions are hosted and managed by Snowflake, so you don’t need any special setup to access them. You can immediately include them in your field and view definitions in Omni.

Defining a new field

In Omni, there are a few ways to create a new field and define it with a Cortex function:

  • From the UI: At the bottom of the field picker, click the “+ Add field” button. Give the field a name, and then write your SQL that includes a Cortex function (see the next section for some code snippets).

    Adding a new field via the UI

  • From the model IDE: Define a new field with the syntax described here

Examples of Cortex functions

Categorization: Defines a field “player_classification” that takes the value from an existing field “player_name” and categorizes it into one of the values in the array. More on the CLASSIFY_TEXT function here

ChatGPT-style questions: Defines a field “bio” that uses the Snowflake Arctic model to generate a short biography on the player with the name in “player_name”. More on the COMPLETE function, including model options and prompts, can be found here. (Note: Double quotes around the SQL are required since the Complete function definition includes single quotes.) 

Sentiment analysis: Defines a field “review_sentiment” that takes the text from a field called “review” and assigns a score from -1 to 1 indicating the level of negative or positive sentiment. More on the SENTIMENT function here.

Advanced implementations

Passing values from the filter bar into Cortex functions

At the 5:30 mark in the demo video, I show how to pass questions from a dashboard’s filter bar into a Cortex function. 

To do so, I implemented a filter-only field called “Question” that lets users select a pre-defined question or input their own question from the dashboard. Then, this field is called in the definition of the field “Answer”, which utilizes the COMPLETE function to retrieve a response. Here’s the full example – feel free to copy & paste.

Summarizing numeric results

In the demo video at the 6:20 mark, I also show how you can use Cortex to summarize the numeric results of a query. 

To do this, you need to define the SQL of the results query as a CTE in a SQL tab, then pass those results into the COMPLETE function as a JSON with TO_JSON, ARRAY_AGG, and OBJECT_CONSTRUCT. Here’s a simple example: 

AI insights with Snowflake & Omni #

With Snowflake Cortex and Omni, you don’t have to switch to another application to get AI insights while analyzing your data. Whether you’re enriching data, summarizing trends, categorizing information, or asking ChatGPT-style questions, Cortex functions in Omni help you gain practical insights quickly.

Let us know if you give this a try on your own data. And if you want to learn more about using Snowflake with Omni and these AI-powered workflows, please reach out to us – we’d love to continue the conversation.