Get startedGet started for free

Introduction to Snowflake Cortex and Notebooks

1. Introduction to Snowflake Cortex and Notebooks

Hi, I'm James Cha-Earley,

2. Meet your instructor!

senior developer advocate at Snowflake, and I'm excited to welcome you to this course.

3. Snowflake Cortex

We'll explore Snowflake Cortex, a suite of built-in LLM tools for solving real business problems directly in Snowflake notebooks. From summarizing customer feedback and translating support tickets to classifying product reviews, Cortex delivers production-ready generative AI without the need to deploy or fine-tune models.

4. Cortex AI

Cortex provides flexible model choice and native integration across SQL, Python, and notebooks. Teams can move from experimentation to production AI workflows entirely within Snowflake. Built-in governance, policies, and observability ensure enterprise-level control throughout our AI journey.

5. Course data

Throughout the course, we will work for Executive Resorts, a global hotel chain. Their database contains hotel reviews - including the rating, review text, review language, and other features. We'll use Cortex to perform various tasks on this data, showcasing Snowflake's powerful generative AI functionality!

6. Template code

Notice that when we create a new notebook, Snowflake provides some helper code to initiate a session, create some data using SQL, and convert it to a pandas DataFrame. Very useful!

7. Querying the data

Let's investigate the hotel reviews data, describing the reviews table. We see columns for review date, rating, review description, hotel name, city, country, and review language.

8. Python variable injection

What if we want to modify our SQL query to limit the results in some way? We could update it directly, but Snowflake notebooks allow Python variable substitution to adjust queries programmatically. Here, we create a Python variable called `target_destination`, assigning a variable of Cancun.

9. Python variable injection

We can now use this variable in our query to filter records where the city is Cancun, Mexico. Notice the syntax - we use two curly brackets inside single quotes, inserting our Python variable there. This functionality allows us to build dynamic, parameterized notebooks - perfect for production pipelines or ad-hoc reports.

10. Setting up Cortex

Next, let's set up our environment! To work with Cortex in Python cells, we need to import packages by clicking "Packages" in the top right corner, typing `snowlfake-ml-python`, then clicking Save.

11. Summarizing text

Our first use case is to summarize text, so we'll import the `summarize` function from the pre-installed `snowflake.cortex` module. Here, we have a long review that we've extracted from our database and stored as a text variable.

12. Summarizing text

To summarize it, we call the `summarize()` function, passing the review to the text argument. We then print the result to see our summary. The summary is concise and keeps all the critical details. This is especially handy for long texts.

13. Cortex in SQL cells

Note that Cortex functions can also run directly in SQL cells without requiring package imports. However, Python cells offer better functionality for chaining multiple functions together and maintaining organized, readable code.

14. Let's practice!

Now, it's time for practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.