How to run generative AI on SQL tables with Snowflake Cortex
The question that decides whether Cortex belongs in your stack is not what it can do. It is what it costs once the table has millions of rows instead of five. That question exists because the model call is an ordinary SQL function. It sits inside a SELECT , composes with WHERE , JOIN and GROUP BY , and runs once per row. So this walkthrough goes in that order. Access first, then the functions on…
To run generative AI on SQL tables with Snowflake Cortex, start by setting up a Snowflake account in a region where Cortex is available, and a warehouse. Grant access to the AI functions through a database role called SNOWFLAKE.CORTEX_USER. Use the AI_COMPLETE function to generate text based on a model name and prompt. Limit the number of AI calls to a few rows initially to manage costs, and remove the limit when the prompt is finalized.
Utilize task-specific functions like AI_CLASSIFY for classification, AI_FILTER for filtering, and AI_AGG for aggregation to write shorter SQL queries. Monitor costs by viewing the Account Usage schema and aggregate AI function usage. Be aware of preview status for some functions and model availability, and consider materializing results for downstream tables to avoid non-determinism.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.