Cortex Completions
Editions
Production use of this feature is available for specific editions only. Contact our sales team for more information.
Cortex Completions is a transformation component that uses Snowflake Cortex to receive a prompt and then generate a response (a completion) using your chosen supported language model.
You must use a Snowflake role that has been granted the SNOWFLAKE.CORTEX_USER database role. Read Required Privileges to learn more about granting this privilege.
To learn more about Snowflake Cortex, such as availability, usage quotas, managing costs, and more, visit Large Language Model (LLM) Functions (Snowflake Cortex).
Properties
Name
= string
A human-readable name for the component.
Model
= drop-down
Select a language model from the drop-down menu. Review the Snowflake documentation for supported models, costs, and quotas.
Read Availability for details about which models are available in which regions.
System Prompt
= text editor | optional
An initial plain-English prompt to your chosen language model to provide the model with background information and instructions for a style of response. An example of response steps offered by Snowflake is "Respond in the style of a pirate."
The language model doesn't generate a response to your system prompt, but to your user prompt. The system prompt informs the model on how to answer the user prompt.
Only one system prompt may be provided.
User Prompt
= text editor
A plain-text prompt provided by the user. This prompt should be contextually relatable to the system prompt (if used).
Inputs
= column editor | optional
Select the source columns to feed as input to the model.
- Column Name: A column from the input table.
- Descriptive Name (optional): An alternate descriptive name to better contextualize the column. Recommended if your column names are low-context.
Temperature
= floating point number | optional
A value between 0 to 1 (inclusive) to control the randomness of the output of the language model. Higher temperatures (for example, 0.8) will result in more diverse and random outputs. Lower temperatures (for example, 0.2) make the output more focused and deterministic.
Top P
= floating point number | optional
A value between 0 and 1 (inclusive) to control the randomness of the output of the language model—typically used as an alternative to temperature.
Top P restricts the set of possible tokens that the mode will output, whereas Temperature influences which tokens are chosen at each step.
Many LLM models recommend altering Top P or Temperature, but not both.
Max Tokens
= integer | optional
Set the maximum number of output tokens in the response. A small number of max tokens can result in truncated responses.
Include Input Columns
= boolean
- Yes: Outputs both your source input columns and the new completion columns. This will also include those input columns not selected in Inputs.
- No: Only outputs the new completion columns.
Explanation of output
This component returns a string representation of a JSON object, containing the following keys:
Key | Description |
---|---|
choices | An array of the model's responses. (Currently, only one response is provided.) Each response is an object containing a "messages" key whose value is the model's response to the latest prompt. |
created | UNIX timestamp (seconds since midnight, January 1, 1970) of when the response was generated. |
model | The language model that created the response. |
usage | An object recording the number of tokens consumed and generated by this completion. |
completion_tokens | The number of tokens in the generated response. |
prompt_tokens | The number of tokens in the prompt. |
total_tokens | Sum of completion_tokens and prompt_tokens. |
Example
A coffee shop has been collecting customer reviews left on a web site, and wants to distill some key pieces of information from these reviews. The primary information wanted is: was the customer satisfied with the service?
Input data:
COFFEE TYPE | REVIEW |
---|---|
Espresso | The espresso was bold and aromatic, but a tad too bitter for my taste. The barista was friendly, though, and the atmosphere was cozy. |
Cappuccino | My cappuccino was perfectly balanced, with a creamy foam that melted in my mouth. However, the service was a bit slow, and the coffee wasn't piping hot. |
Latte | The latte was velvety smooth, but it lacked the flavor I was hoping for. The barista was friendly, and the ambiance was pleasant. |
Americano | The Americano was strong and robust, just how I like it. However, the service was a bit impersonal, and the coffee could have been hotter. |
Mocha | Indulging in the mocha was like sipping on liquid chocolate bliss. The service, however, was lacking, with long wait times and a disorganized atmosphere. |
The shop can use the Cortex Completions component to ask a question (prompt) and receive an answer based on the review text given to the component.
Cortex Completions component properties:
- Model: llama2-70b-chat
- System Prompt: [blank]
- User Prompt: Was the customer satisfied with the service?
- Inputs:
- Column Name: REVIEW
- Descriptive Name: [blank]
- Temperature: [blank]
- Top P: [blank]
- Max Tokens: 6
- Include Input Columns: YES
By setting Include Input Columns to YES, the original columns from the table will be kept as part of the pipeline run, and the completion_result column is appended to the end of the table.
Output data (with completion_result column abbreviated for ease of illustration):
COFFEE TYPE | REVIEW | completion_result |
---|---|---|
Espresso | The espresso was bold and aromatic, but a tad too bitter for my taste. The barista was friendly, though, and the atmosphere was cozy. | {"messages": " The customer was partially satisfied with"} |
Cappuccino | My cappuccino was perfectly balanced, with a creamy foam that melted in my mouth. However, the service was a bit slow, and the coffee wasn't piping hot. | {"messages": " The customer was partially satisfied with"} |
Latte | The latte was velvety smooth, but it lacked the flavor I was hoping for. The barista was friendly, and the ambiance was pleasant. | {"messages": " The customer was partially satisfied with"} |
Americano | The Americano was strong and robust, just how I like it. However, the service was a bit impersonal, and the coffee could have been hotter. | {"messages": " No, the customer was not"} |
Mocha | Indulging in the mocha was like sipping on liquid chocolate bliss. The service, however, was lacking, with long wait times and a disorganized atmosphere. | {"messages": " No, the customer was not"} |
Snowflake | Databricks | Amazon Redshift |
---|---|---|
✅ | ❌ | ❌ |