Create a chatbot that speaks to the Snowflake Cortex Analyst
Source:R/provider-cortex.R
chat_cortex.Rd
Chat with the LLM-powered Snowflake Cortex Analyst.
Unlike most comparable model APIs, Cortex does not take a system prompt. Instead, the caller must provide a "semantic model" describing available tables, their meaning, and verified queries that can be run against them as a starting point. The semantic model can be passed as a YAML string or via reference to an existing file in a Snowflake Stage.
Note that Cortex does not support multi-turn, so it will not remember previous messages. Nor does it support registering tools, and attempting to do so will result in an error.
Usage
chat_cortex(
account = Sys.getenv("SNOWFLAKE_ACCOUNT"),
credentials = cortex_credentials,
model_spec = NULL,
model_file = NULL,
api_args = list(),
echo = c("none", "text", "all")
)
cortex_credentials(account = Sys.getenv("SNOWFLAKE_ACCOUNT"))
Arguments
- account
A Snowflake account identifier, e.g.
"testorg-test_account"
.- credentials
A list of authentication headers to pass into
httr2::req_headers()
or a function that returns them when passedaccount
as a parameter. The defaultcortex_credentials()
function picks up ambient Snowflake OAuth and key-pair authentication credentials and handles refreshing them automatically.- model_spec
A semantic model specification, or
NULL
when usingmodel_file
instead.- model_file
Path to a semantic model file stored in a Snowflake Stage, or
NULL
when usingmodel_spec
instead.- api_args
Named list of arbitrary extra arguments appended to the body of every chat API call.
- echo
One of the following options:
none
: don't emit any output (default when running in a function).text
: echo text output as it streams in (default when running at the console).all
: echo all input and output.
Note this only affects the
chat()
method.
Value
A Chat object.
Details
cortex_credentials()
picks up the following ambient Snowflake credentials:
A static OAuth token defined via the
SNOWFLAKE_TOKEN
environment variable.Key-pair authentication credentials defined via the
SNOWFLAKE_USER
andSNOWFLAKE_PRIVATE_KEY
(which can be a PEM-encoded private key or a path to one) environment variables.Posit Workbench-managed Snowflake credentials for the corresponding
account
.
See also
Other chatbots:
chat_bedrock()
,
chat_claude()
,
chat_gemini()
,
chat_github()
,
chat_groq()
,
chat_ollama()
,
chat_openai()
,
chat_perplexity()