Cortex Analyst¶
solver
¶
CortexAnalystSolver: a Solver that answers questions with Snowflake Cortex Analyst.
CortexAnalystSolver
¶
CortexAnalystSolver(
client: CortexTransport,
*,
semantic_view: str | None = None,
semantic_model_file: str | None = None,
)
A Solver that sends a question to Cortex Analyst and returns the SQL it generates.
Configure the solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
CortexTransport
|
The Cortex Analyst client to send questions through. |
required |
semantic_view
|
str | None
|
A fully qualified semantic view, e.g. |
None
|
semantic_model_file
|
str | None
|
A stage path to a semantic-model YAML, e.g.
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If not exactly one of |
client
¶
CortexAnalystClient: a thin HTTP client for the Snowflake Cortex Analyst REST endpoint.
CortexTransport
¶
Bases: Protocol
Sends a question to Cortex Analyst and returns the raw JSON reply or a typed error.
send
¶
send(
question: str, semantic_ref: dict[str, str]
) -> dict[str, Any] | SolverError
Send question against semantic_ref, returning the JSON body or a SolverError.
CortexAnalystClient
¶
CortexAnalystClient(
*,
host: str,
token_provider: Callable[[], str],
session: Session | None = None,
timeout: float = 60.0,
)
Sends a question to the Cortex Analyst REST endpoint and returns the raw JSON reply.
Configure the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The Snowflake account host, e.g. |
required |
token_provider
|
Callable[[], str]
|
Returns the session token to place in the |
required |
session
|
Session | None
|
The |
None
|
timeout
|
float
|
Per-request timeout in seconds. |
60.0
|
from_connection
classmethod
¶
from_connection(
connection: SnowflakeConnection,
*,
timeout: float = 60.0,
) -> CortexAnalystClient
Build a client that authenticates with connection's live session token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
SnowflakeConnection
|
An open Snowflake connection whose host and session token are reused. |
required |
timeout
|
float
|
Per-request timeout in seconds. |
60.0
|
Returns:
| Type | Description |
|---|---|
CortexAnalystClient
|
A |
send
¶
send(
question: str, semantic_ref: dict[str, str]
) -> dict[str, Any] | SolverError
POST question against semantic_ref, returning the JSON body or a typed error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
The natural-language question to answer. |
required |
semantic_ref
|
dict[str, str]
|
The semantic-model reference field, e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | SolverError
|
The decoded JSON response body, or a |
dict[str, Any] | SolverError
|
failure. |