Learning Objectives
By the end of this chapter, you will be able to:
- Apply general Cortex AI functions including AI_COMPLETE and COMPLETE Structured Outputs, and set up the Snowflake environment with required privileges.
- Apply task-specific functions including AI_CLASSIFY, AI_EXTRACT, AI_PARSE_DOCUMENT, AI_SENTIMENT, SUMMARIZE, AI_SUMMARIZE_AGG, AI_TRANSLATE, AI_EMBED, AI_FILTER, AI_AGG, AI_SIMILARITY, AI_TRANSCRIBE, and AI_REDACT, and invoke them from Streamlit in Snowflake.
- Use vector functions including VECTOR_INNER_PRODUCT, VECTOR_L1_DISTANCE, VECTOR_L2_DISTANCE, VECTOR_COSINE_SIMILARITY, VECTOR_TRUNCATE, VECTOR_NORMALIZE, VECTOR_SUM, VECTOR_MIN, VECTOR_MAX, and VECTOR_AVG, and design multi-turn chat conversations using the messages array.
- Apply helper functions including AI_COUNT_TOKENS, TRY_COMPLETE, SPLIT_TEXT_RECURSIVE_CHARACTER, SPLIT_TEXT_MARKDOWN_HEADER, TO_FILE, and PROMPT, and connect Snowflake Intelligence as the turnkey chat surface.
- Build unstructured-data pipelines using AI_PARSE_DOCUMENT, AI_EXTRACT, AI_SIMILARITY, and AI_COMPLETE with Cortex Search, recursive markdown splitting, chunk sizing, embedding model selection, and semantic reranking through the Cortex SQL interface.
- Perform multi-modal analytics on audio and image inputs and apply data extraction, enrichment, augmentation, and transformation patterns.
- Build structured-data flows with AI_COMPLETE and Cortex Analyst using the Verified Query Repository, Cortex Search integration, Suggested Questions, and CUSTOM_INSTRUCTIONS, and run third-party models through Snowpark Container Services with Docker images, specification files, compute pools, and image repositories.
- Reason about performance trade-offs across model choice, latency, accuracy, model capability, and Provisioned Throughput, and operate the Snowflake Model Registry to log and call models.
Executive Summary
- The Cortex AI function family is the SQL-callable inference surface of Snowflake. Every function in this chapter shares the same authorization root (the CORTEX_USER application role), the same model catalog, the same usage-history attribution, and the same cross-region inference rules. Mastering one tightens reasoning about all of them.
- Task-specific functions sit on top of AI_COMPLETE but expose tighter signatures and tuned prompts. Choosing AI_CLASSIFY over a hand-rolled AI_COMPLETE classifier is almost always the right call because the task function is cheaper, more deterministic, and observable through CORTEX_AISQL_USAGE_HISTORY.
- Vector functions and helper functions are the connective tissue that turns scalar AI calls into retrieval, chat, and pipeline patterns. The text splitters, AI_EMBED, the VECTOR_*_DISTANCE family, and PROMPT together replace most ad-hoc embedding code that teams used to write in external Python.
- Performance, cost, and accuracy are not three problems. They are one problem with a Provisioned Throughput knob in the middle: the right model size, the right region, the right retrieval strategy, and the right governance roles compose into predictable latency and predictable bill lines.
Assumptions
- You have account-level access to Snowflake with the ability to grant the CORTEX_USER, CORTEX_ANALYST_USER, CORTEX_AGENT_USER, and CORTEX_EMBED_USER application roles, or to coordinate with a SECURITYADMIN who does.
- All examples assume an Enterprise edition or above, with cross-region inference parameters available at the account level. Where a feature is region-restricted, the prose flags the constraint inline.
- Code samples follow the fictional schema
AI_DB.AI_LAB.*with warehouseAI_WH. Substitute identifiers for your own environment. Schema names, table names, and role names that match terms defined in Chapter 1 reuse the exact spelling without re-defining them. - Where a function exists both in the legacy
SNOWFLAKE.CORTEX.<FUNCTION>form and in the unqualified system-function form (such asAI_COMPLETE), the chapter uses the unqualified form unless a specific governance discussion requires the fully qualified path.
