Async Cortex Analyst¶
cortex_agents.async_analyst.AsyncCortexAnalyst ¶
AsyncCortexAnalyst(account_url: str | None = None, pat: str | None = None, enable_logging: bool = True, token_type: str | None = None)
Bases: BaseAgent
Async client for Snowflake Cortex Analyst.
Examples:
async with AsyncCortexAnalyst() as analyst:
response = await analyst.message(
"Which company had the most revenue?",
semantic_model_file="@my_stage/model.yaml"
)
# Stream results
async for event in response.astream():
if event["type"] == "text.delta":
print(event["data"]["text"], end="", flush=True)
Initialize the Async Cortex Analyst client.
Source code in cortex_agents/async_analyst.py
close ¶
Close the async client and cleanup resources.
Source code in cortex_agents/async_analyst.py
aclose
async
¶
Async close helper for use within a running event loop.
message
async
¶
message(question: str, semantic_model_file: str | None = None, semantic_model: str | None = None, semantic_view: str | None = None, semantic_models: list[dict[str, Any]] | None = None, messages: list[dict[str, Any]] | None = None, stream: bool = True) -> AnalystResponse
Send a natural language question to Cortex Analyst (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
Natural language question |
required |
semantic_model_file
|
str | None
|
Path to semantic model file in stage (e.g., "@stage/model.yaml") |
None
|
semantic_model
|
str | None
|
Inline semantic model YAML string |
None
|
semantic_view
|
str | None
|
Name of semantic view (alternative to semantic_model_file) |
None
|
semantic_models
|
list[dict[str, Any]] | None
|
Collection of semantic model descriptors |
None
|
messages
|
list[dict[str, Any]] | None
|
Previous conversation messages for multi-turn conversations |
None
|
stream
|
bool
|
Whether to request a streaming response (default True) |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
AnalystResponse |
AnalystResponse
|
Response with SQL, text, and streaming support |
Examples:
async with AsyncCortexAnalyst() as analyst:
response = await analyst.message(
"What was the total revenue last quarter?",
semantic_model_file="@my_stage/revenue_model.yaml"
)
print(response.sql)
print(response.text)
Source code in cortex_agents/async_analyst.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
suggest_questions
async
¶
suggest_questions(semantic_model_file: str | None = None, semantic_view: str | None = None, max_questions: int = 3) -> list[str]
Get suggested questions based on semantic model (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
semantic_model_file
|
str | None
|
Path to semantic model file |
None
|
semantic_view
|
str | None
|
Name of semantic view |
None
|
max_questions
|
int
|
Maximum number of questions to return |
3
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Suggested questions |
Source code in cortex_agents/async_analyst.py
validate_semantic_model
async
¶
validate_semantic_model(semantic_model_file: str | None = None, semantic_view: str | None = None) -> dict[str, Any]
Validate a semantic model (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
semantic_model_file
|
str | None
|
Path to semantic model file |
None
|
semantic_view
|
str | None
|
Name of semantic view |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
dict[str, Any]
|
Validation results |