Snowflake Cortex AI
Overview
Snowflake Cortex AI is a suite of fully managed machine learning and AI features built directly into the Snowflake Data Cloud. It democratizes AI by allowing users to leverage industry-leading Large Language Models (LLMs) and ML algorithms using standard SQL or Python, without needing to move data or manage complex AI infrastructure. For the SnowPro Core exam, you must understand the categories of functions available, the newer AI services (Search, Analyst, Agents), and the underlying security and compute models.
Key Concepts
1. LLM Functions (Generative AI)
Cortex provides access to industry-leading models (like Meta Llama, Mistral, Snowflake Arctic) through simple SQL functions. These functions process unstructured text data.
| Function | Description | Example Use Case |
| :--- | :--- | :--- |
| SNOWFLAKE.CORTEX.COMPLETE (or AI_COMPLETE) | Generates text based on a prompt. | Drafting emails, answering questions. |
| SNOWFLAKE.CORTEX.CLASSIFY (or AI_CLASSIFY) | Categorizes text into predefined labels. | Categorizing support tickets (e.g., 'Billing', 'Tech'). |
| SNOWFLAKE.CORTEX.EXTRACT_ANSWER | Extracts a specific answer from a document based on a question. | Finding the contract expiration date in a legal PDF. |
| SNOWFLAKE.CORTEX.SENTIMENT | Returns a score between -1 and 1 indicating sentiment. | Analyzing customer product reviews. |
| SNOWFLAKE.CORTEX.TRANSLATE | Translates text between supported languages. | Localizing a product catalog. |
| SNOWFLAKE.CORTEX.SUMMARIZE | Generates a concise summary of a larger text block. | Summarizing long call transcripts. |
| SNOWFLAKE.CORTEX.EMBED_TEXT_768 | Generates vector embeddings for text. | Creating vectors for a vector database / similarity search. |
*(Note: Snowflake occasionally aliases these as AI_COMPLETE, AI_CLASSIFY, etc. Understand both naming conventions).*
2. Machine Learning (ML) Functions
These functions are designed for structured, time-series, or tabular data.
- Forecasting: Predicts future metric values based on historical trends.
- Anomaly Detection: Flags unusual data points (e.g., spikes in login failures).
- Classification: Sorts rows into classes based on patterns in the data (different from text classification).
- Contribution Explorer: Identifies which dimensions (e.g., region, product) contributed most to a change in a metric.
- Top Insights: Finds the most significant drivers of a specific outcome.
3. Cortex Advanced AI Services
Snowflake has expanded Cortex into managed AI services to build full AI applications:
- Cortex Search: A fully managed Retrieval-Augmented Generation (RAG) and search service. It allows you to build a search engine over your structured and unstructured data, supporting both natural language (semantic) and keyword searching.
- Cortex Analyst: Enables natural language-to-SQL interactions. Users can ask questions in plain English, and Analyst uses YAML-based Semantic Models to understand your schema and generate accurate SQL queries.
- Cortex Agents: A newer orchestration framework for building autonomous AI agents. Agents can reason, plan, and execute multi-step tasks by utilizing tools like Cortex Search, Cortex Analyst, or custom functions.
- Cortex Fine-tuning: Allows you to customize foundational LLMs (like Llama) on your specific, secure corporate data to improve accuracy on domain-specific tasks.
How It Works
Compute Model
- Serverless Compute: Most Cortex AI functions (especially LLM functions like
COMPLETE,SUMMARIZE) execute using Snowflake's serverless compute. You do *not* need to spin up a virtual warehouse to run these functions; Snowflake provisions the GPUs behind the scenes. You are billed based on compute usage (e.g., tokens processed). - Virtual Warehouses: ML functions (like training a forecasting model) and building Cortex Search indices *do* utilize your standard virtual warehouses.
Security Model
- Data Stays in Snowflake: The biggest selling point of Cortex AI is security. When you use an LLM function, your data is not sent over the internet to a third-party provider (like OpenAI). It is processed within Snowflake's secure perimeter using models hosted by Snowflake.
- RBAC applies: Standard Role-Based Access Control applies to Cortex functions. Users need specific grants (e.g.,
CORTEX_USERdatabase role) to execute the functions.
SQL Examples
-- 1. Text Summarization
SELECT SNOWFLAKE.CORTEX.SUMMARIZE(email_body) AS summary
FROM customer_emails;
-- 2. Sentiment Analysis
SELECT
review_text,
SNOWFLAKE.CORTEX.SENTIMENT(review_text) AS sentiment_score
FROM product_reviews
WHERE sentiment_score < -0.5; -- Find strongly negative reviews
-- 3. Text Completion (using a specific model)
SELECT SNOWFLAKE.CORTEX.COMPLETE(
'mistral-large',
'Write a polite rejection letter for a software engineering candidate.'
);
-- 4. Creating a Cortex Search Service (requires a warehouse)
CREATE CORTEX SEARCH SERVICE my_kb_search
ON document_chunk
ATTRIBUTES category, author
WAREHOUSE = compute_wh
TARGET_LAG = '1 hour'
AS (
SELECT document_chunk, category, author
FROM parsed_knowledge_base
);
Exam Tips
⚠️ Data Privacy: A very common exam scenario involves a company wanting to use LLMs but with a strict policy against data leaving their cloud perimeter. Snowflake Cortex AI is the correct answer.
⚠️ Compute Type: Remember that LLM functions (Complete, Summarize, Sentiment) are generally serverless, whereas creating a Search Service or training an ML model requires a virtual warehouse.
⚠️ Search vs. Analyst: Know the difference: Cortex Search is for finding information (text/RAG). Cortex Analyst is for querying structured data (Natural Language to SQL).
⚠️ Roles: To use these functions, a user must be granted the CORTEX_USER role via the SNOWFLAKE database.
Key Takeaways
- Cortex AI brings LLMs and ML directly to your data in Snowflake.
- No data movement means enterprise-grade security and compliance.
- LLM functions (Complete, Classify, Extract, Translate, Sentiment, Summarize) handle unstructured text.
- ML functions handle structured data (Forecasting, Anomaly Detection).
- Advanced services include Cortex Search (RAG), Cortex Analyst (NL-to-SQL), and Cortex Agents.
- Accessible via standard SQL functions, making AI available to data analysts.