GenAI - Snowflake Cortex LLM Functions - Part I
1. GenAI - Snowflake Cortex LLM Functions - Part I
Okay, so I’m really excited about this. We get to actually use a Snowflake Cortex LLM function! Woot woot, raise the roof! We covered four Snowflake Cortex LLM functions in the last video. Here I want to talk about a new one called Complete – as in “Where have you been my whole life, Snowflake Cortex? You complete me.” The goal here isn’t to become an expert on this particular LLM function. Snowflake Cortex Complete is cool and important, but the more important goal is to use this one function as a bridge into understanding more generally how LLM functions work in Snowflake. To follow along here, you don’t need to have a deep understanding of LLMs. Okay, let’s go! So what does Complete do? If you feed it two arguments – the name of an LLM (there are a bunch of options), and a prompt – it gives you back a response to the prompt. It’s pretty straightforward. So before we get into some important nuances, let’s just ask it a question. Snowflake makes available lots of models – We’ll pick one of the smaller ones, ‘mistral-7b,’ for this example. Let’s ask: “What are three reasons that Snowflake is positioned to become the go-to data platform?” We do this by running the following: SELECT SNOWFLAKE.CORTEX.COMPLETE( 'mistral-7b', 'What are three reasons that Snowflake is positioned to become the go-to data platform?'); So you can see that we’re just running this inside a SELECT statement, and we’re calling the full path of the function – SNOWFLAKE is the database, Cortex is the schema, and Complete is the function. (If you look at the left hand side, you can dig down and see Complete there – and notice that it’s listed as a UDF.) Okay, so that seems like a pretty good answer – but it feels a bit long to me. Let’s do this again, but just for fun, let’s use *another* LLM function to summarize the results, like this: SELECT SNOWFLAKE.CORTEX.SUMMARIZE(SNOWFLAKE.CORTEX.COMPLETE( 'mistral-7b', 'What are three reasons that Snowflake is positioned to become the go-to data platform?')); So here you can see that we’re still using a SELECT statement, but this time we are feeding the results from the COMPLETE function into the SUMMARIZE function. They are both Cortex LLM functions. The answer looks pretty good! Looks like it captured the main points, and it’s definitely tighter. Pretty cool. Now an important thing to know about LLMs is that under the hood, they’re not exactly structured in the language you’re feeding into them. Instead, they convert your input into something called tokens, and they work with those tokens, and then they output tokens, and convert them back to your original language. Now you don’t have to understand much about tokens to work with Snowflake Cortex LLM functions, but I wanted to mention it because when you read through function documentation, you’ll see references to tokens – for example, the costs of using Complete can vary depending on which model you choose. For larger models it’s more per token and for smaller models it tends to be less. Also, in the case of Complete, you can specify a “max token” size, which can limit the size of the response – so we could have just used that directly instead of feeding the results of Complete into Summarize. So earlier we used Mistral-7b, but we could have picked from a bunch of models if we’d wanted to, each supported by Snowflake out of the box – 'mistral-large', 'llama2-70b-chat', etc. Okay, so another important thing to know is that since this is working inside a SELECT statement, it’s easy to feed in a bunch of different prompts into COMPLETE row-wise, and get a table of results all at once. Let’s do this by asking COMPLETE to tell us why items on our Tasty Bytes menu are tasty. SELECT SNOWFLAKE.CORTEX.COMPLETE( 'mistral-7b', CONCAT('Tell me why this food is tasty: ', menu_item_name) ) FROM FROSTBYTE_TASTY_BYTES.RAW_POS.MENU LIMIT 5; So we’ve limited this to 5, and you can see that what we’re doing is specifying that we’ll use Mistral-7b, but then as our prompt, we’re concatenating the string “Tell my why this food is tasty: ” with menu_item_name, which is the column in our MENU table that holds the name of that food. Before we run this, let’s run: SELECT CONCAT('Tell me why this food is tasty: ', menu_item_name) ) FROM FROSTBYTE_TASTY_BYTES.RAW_POS.MENU LIMIT 5; So you can visualize the input we’re feeding into Complete. “Tell me why this food is tasty: Lemonade,” “Tell me why this food is tasty: Sugar Cone” – Looks good. And I’m excited to see how COMPLETE reviews the tastiness of Bottled Water. Okay, so we run our COMPLETE command across the above five examples from our table, and we get some pretty cool results! [Read from the results] I don’t know about you, but I’m persuaded. And I like how candid it is about bottled water. Mistral-7b is a very polite LLM. Coming up, we’ll learn how to give the LLM some context. Let’s do it.2. Let's 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.