You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(snowflake): add Cortex Analyst operations to the Snowflake block (#8347)
* feat(snowflake): add Cortex Analyst operations to the Snowflake block
* fix(snowflake): keep Cortex Analyst SQL context for quoted and multi-source views and replay suggestions
* fix(snowflake): run Cortex Analyst SQL with the resolved token, the chosen source's schema, and document access requirements
@@ -14,12 +14,20 @@ import { BlockInfoCard } from "@/components/ui/block-info-card"
14
14
[Snowflake](https://www.snowflake.com/) stores data in databases and schemas and uses virtual warehouses to run queries. Sim connects over the SQL API with a programmatic access token.
15
15
16
16
Use the block to execute SQL, synchronize rows, move staged data, manage warehouses and tasks, and inspect history. To unload a query result, first materialize it as a view or with `CREATE TABLE AS SELECT`.
17
+
18
+
**Cortex Analyst.** Ask Cortex Analyst turns a plain-English question into SQL against a semantic view or semantic model, and can run that SQL to return rows. Pass the returned `conversation` back as history to ask follow-up questions, and start a new conversation after a handful of turns, since Snowflake reprocesses the whole history on every question. Before you use it:
19
+
20
+
- The access token's role needs the `SNOWFLAKE.CORTEX_USER` or `SNOWFLAKE.CORTEX_ANALYST_USER` database role, `SELECT` on the tables behind the semantic view, and read access to the stage when the model is a staged YAML file.
21
+
- Cortex Analyst always answers under the access token's role. The block's execution role, warehouse, and row limit apply only when it runs the generated SQL.
22
+
- Cortex Analyst runs natively in a limited set of cloud regions. Other accounts need cross-region inference turned on.
23
+
- Snowflake bills each successful answer, and running the SQL uses warehouse credits on top.
24
+
- Snowflake now recommends Cortex Agents for new builds; Cortex Analyst remains available.
17
25
{/* MANUAL-CONTENT-END */}
18
26
19
27
20
28
## Usage Instructions
21
29
22
-
Connect with a Snowflake programmatic access token to execute SQL, synchronize structured rows, load and unload staged data, browse databases and schemas, size and control warehouses, run and schedule tasks, review query and load history, inspect schemas, and call stored procedures.
30
+
Connect with a Snowflake programmatic access token to execute SQL, synchronize structured rows, load and unload staged data, browse databases and schemas, size and control warehouses, run and schedule tasks, review query and load history, inspect schemas, and call stored procedures. Ask Cortex Analyst questions in natural language against a semantic view or model to get generated SQL and, optionally, its results, with multi-turn follow-ups.
23
31
24
32
25
33
@@ -1354,4 +1362,95 @@ Call a stored procedure with explicitly typed Snowflake bindings.
1354
1362
| ↳ `duplicateRowsUpdated`| number | Duplicate rows updated by the statement |
1355
1363
| ↳ `rowsAffected`| number | Total inserted, updated, and deleted rows |
1356
1364
1365
+
### Snowflake Cortex Analyst Ask
1366
+
1367
+
Ask Snowflake Cortex Analyst a question in natural language against a semantic view or semantic model. Returns its interpretation and the generated SQL, or suggested questions when the question is ambiguous, and can run the SQL to return rows. Pass the returned conversation as history to ask a follow-up.
|`question`| string | Yes | The question to ask about your data |
1375
+
|`semanticView`| string | No | Fully qualified semantic view name \(for example MY_DB.MY_SCHEMA.MY_VIEW\). Provide exactly one semantic source. |
1376
+
|`semanticModelFile`| string | No | Stage path to a semantic model YAML file \(for example @MY_DB.MY_SCHEMA.MY_STAGE/model.yaml\). Provide exactly one semantic source. |
1377
+
|`semanticModel`| string | No | Full semantic model YAML. Provide exactly one semantic source. |
1378
+
|`semanticModels`| json | No | Several semantic sources for Cortex Analyst to choose between, as a JSON array of \{"semantic_view": "..."\} or \{"semantic_model_file": "@..."\} objects. Provide exactly one semantic source. |
1379
+
|`history`| json | No | Earlier conversation messages in order, as returned in the conversation output of a previous ask |
1380
+
|`executeSql`| boolean | No | Run the generated SQL with the same credential and return the result rows |
1381
+
|`warehouse`| string | No | Warehouse for running the generated SQL; defaults to the PAT user setting |
1382
+
|`role`| string | No | Snowflake role for running the generated SQL. Cortex Analyst itself always answers under the access token role |
1383
+
|`maxRows`| number | No | Maximum result rows when running the SQL; defaults to 1000 \(Sim limit 10000\)|
1384
+
|`statementTimeoutSeconds`| number | No | Timeout in seconds for running the SQL; 0 uses the Snowflake maximum |
1385
+
1386
+
#### Output
1387
+
1388
+
| Parameter | Type | Description |
1389
+
| --------- | ---- | ----------- |
1390
+
|`requestId`| string | Cortex Analyst request ID, used to send feedback on this answer |
1391
+
|`text`| string | How Cortex Analyst interpreted the question, or why it could not answer it \(text content joined in order\)|
1392
+
|`sql`| string | SQL Cortex Analyst generated, or null when the question was ambiguous |
1393
+
|`verifiedQuery`| object | Verified Query Repository entry used to generate the SQL, or null when none was used |
|`cortexSearchRetrieval`| json | Entities Cortex Analyst resolved with Cortex Search \(\[\{service, query, response_body\}\]\), passed through as returned |
1409
+
|`conversation`| array | Full conversation including this question and answer \(analyst turns keep their text and SQL\); pass it as History to ask a follow-up. Snowflake recommends starting a new conversation after many turns |
|`execution`| object | Result of running the generated SQL when Run Generated SQL is on, otherwise null. A query still running after 45 seconds returns status RUNNING with a statementHandle; fetch its rows with Get Statement |
| ↳ `result`| object | Completed result partition, or null while running or when no result is available |
1417
+
| ↳ `columns`| array | Documented Snowflake result column metadata, or null when Snowflake returned a metadata-less partition response |
1418
+
| ↳ `name`| string | Column name |
1419
+
| ↳ `type`| string | Snowflake data type |
1420
+
| ↳ `length`| number | Column length |
1421
+
| ↳ `precision`| number | Numeric precision |
1422
+
| ↳ `scale`| number | Numeric scale |
1423
+
| ↳ `nullable`| boolean | Whether the column is nullable |
1424
+
| ↳ `rows`| array | One complete Snowflake result partition as string or null arrays |
1425
+
| ↳ `totalRows`| number | Total result rows |
1426
+
| ↳ `currentPartition`| number | Zero-based partition returned |
1427
+
| ↳ `partitionCount`| number | Total partitions in the result set. Snowflake reports this only on the first partition, so pass it back to Get Statement when fetching later partitions |
1428
+
| ↳ `nextPartition`| number | Next partition to request with Get Statement, if one exists |
1429
+
| ↳ `truncated`| boolean | Whether more result partitions remain to fetch with Get Statement, or null when Snowflake returned a metadata-less partition response and partitionCount was not supplied. Snowflake does not report when the requested row limit capped the result set, so that cap is never reflected here |
1430
+
| ↳ `dml`| object | Completed DML statistics, or null when the statement has no DML statistics |
1431
+
| ↳ `rowsInserted`| number | Rows inserted by the statement |
1432
+
| ↳ `rowsUpdated`| number | Rows updated by the statement |
1433
+
| ↳ `rowsDeleted`| number | Rows deleted by the statement |
1434
+
| ↳ `duplicateRowsUpdated`| number | Duplicate rows updated by the statement |
1435
+
| ↳ `rowsAffected`| number | Total inserted, updated, and deleted rows |
1436
+
1437
+
### Snowflake Cortex Analyst Feedback
1438
+
1439
+
Rate a Cortex Analyst answer thumbs up or down, with an optional comment. Feedback appears in the Snowsight Cortex Analyst monitoring tab.
0 commit comments