Snowflake Cortex¶
- The database role required to access LLM function is
snowflake.cortex_userwhich is granted toPUBLICby default. If this is not desired, this privilege should be explicitly revoked - Certain LLMs may not be available in all regions; there is no egress cost for cross region LLM usage, but must be enabled
Cortex Analyst¶
- allows LLM based search based on a semantic model
- supports multi-turn conversation (asking follow-up questions)
- must include previous messages, since LLMs are stateless
- Permissions needed:
snowflake.cortex_userrole,usageon the model (YAML),selecton the tables - cost is based on the LLM model used, appears in
snowflake.account_usage.cortex_analyst_usage_history - UDTF
SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTSprovides logs of analyst's questions and answers - LLM Model can be changed, but at the account level (Ref Sarathi @ PS Tech Summit)
Semantic Model¶
- Logical Table
- Dimension: categorical data that provides context to facts, such as product, customer, location
- a time_dimension provides temporal context, enables tracking metrics over specific time interval
- Fact: are measurable, quantitative data
- Metric: a quantifiable measure that is calculated by aggregating multiple fact rows
- Filter: named condition that limits query results to specific data such as time, location, or category
- Dimension: categorical data that provides context to facts, such as product, customer, location
- Relationship: connect tables through shared key
- Verified Query: a collection of questions and SQL queries that are verified to be correct
- Custom instruction: optional, provide the unique context of your business to LLM
Cortex Search Service¶
- Used mainly as fuzzy search with RAG
- advantages v/s competition
- Hybrid keyword and vector ranking
- declarative and incremental indexing
- specifies
- a query that returns data
- a single column that has text to be indexed and searched
- one or more attributes that are returned when a search succeeds
- the underlying table must have change capture enabled for incrementally building search index
- the serving and indexing components can be independently suspended
- owner rights. The service owner needs all rights, the users need usage privilege
Cortex Agent API¶
- orchestrates and calls one or more configure tools
| Agentic AI | Generative AI |
|---|---|
| Proactive: Initiates actions and pursues goals independently | Reactive: Responds to a prompt with an output |
| Goal-Oriented: Achieves goals through a series of actions | Content-Focused: Creates novel text, images, or code |
| Planner: Breaks down complex goals and adapts its plans | Non-Planner: Does not engage in multi-step planning |
| Tool User: Utilizes external tools and APIs to take action | Self-Contained: A system focused solely on generating output |
| Learns Continuously: Adapts and learns from feedback in dynamic environments | Learns from Training: Primarily relies on its initial training data |
Snowflake Intelligence¶
- Has access to various agents
- agents can be connected to multiple tools
- 3 types of tools
- Cortex Analyst (or SQL agent): can run queries again Snowflake
- Cortex Search (or Document/Text search tool):
- Custom tool: e.g. send email, lookup weather
- builtin tools for every agent: chart generator, onboarding/who-ami-i tool (replies with capabilities of other tools)
- Calls Cortex agent API to orchestrate and call different tools
- Currently SI makes uses to unpublished features of Cortex Agent API such as deep reasoning, multi-tool selection
- Use Planning Instructions under Orchestration tab, to provide general instructions to alter the default behavior of an agent.
- E.g. to always use charts, Whenever answer can be visualized in charts, use chart tool regardless if the user requested it
AI SQL¶
AI_EXTRACT¶
- Extracting a page using
AI_EXTRACTalways incurs 970 tokens plus prompt and output tokens - It may not be able to parse complex documents. Alternatively, use
AI_COMPLETEusing a capable LLM to extract data- Using images instead of PDF is better because PDF has hidden structure and data that is hard to render by LLMs