Get startedGet started for free

Snowflake Cortex via CLI

1. Snowflake Cortex via CLI

In the last two videos, we cover Snowflake's GenAI landscape, including all the Cortex LLM functions you can call from SQL. Now, I want to show you another way to access those same functions that's particularly useful if you spend a lot of time in the terminal, the Snowflake CLI's built-in Cortex commands. If you followed along in the CLI video back in module 2, you already got the Snow CLI installed, and your connection is configured. Let's confirm everything is still working using the version flag. Good. Now, let's see what Cortex-specific commands are available by using the help flag. You can see a handful of sub-commands here, including complete, extract answer, sentiment, translate, and search. These map almost directly to the Cortex LLM functions we've been using in SQL throughout this module. The difference is that here, we're calling them from the terminal, which opens up workflow options that SQL alone doesn't give you. Let's start with complete, since that's the one we spent the most time with, and since I've been promising you further discussion. The simplest possible call looks like this. Use Snow Cortex complete, followed by your natural language query. There it is. It responds right in the terminal. No SQL works it needed. By default, it uses a sensible model. But you can specify one explicitly with the model flag. Let's try that with a LLAMA model. Same question, now explicitly routed to a different model. Swapping models is one flag. It's really that easy. Speaking of scripting, the output is plain text by default, which means it plays nicely with standard Unix tools. You can redirect it to a file, pipe it into another command, or capture it in a shell variable. Let's just do a simple printout of a result using the echo command like this. That kind of composability is where the CLI really earns its place. SQL is great for row-wise operations against your tables. The CLI is great for ad hoc tasks, scripting, and integrating Cortex into workflows that live outside of Snowflake entirely. There's one more thing worth knowing surrounding Snow Cortex search. Search lets you query a Cortex search service you've already set up also directly from the terminal. We're not going to demo that here since it requires a search service that already exists, but the pattern is exactly the same. One command, your query as an argument, results back in the terminal. To recap, in this video, we cover four things. One, use Snow Cortex with the help flag to see the available subcommands. Two, use Snow Cortex complete with a prompt and the model flag to specify which model to use. Three, you can pipe file contents into Snow Cortex complete for document level tasks. Four, you can capture output in shell variables for use in scripts. The Snowflake CLI and Cortex are a natural pairing. Once you have both set up, adding AI to any terminal workflow is one command away.

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.