AI Generate Function
The AI_GENERATE function produces a generated text
value for each row returned by the query. For every row, the function sends the provided
input text and prompt to the specified AI model and returns the model’s response.
Note:
For information about limitations with using AI Functions, see Known Issues with AI Functions.
Use this function for general-purpose text generation tasks such as:
- Summarization
- Classification
- Rewriting or paraphrasing
- Enrichment or explanation
- Label or tag generation
- General or prompt querying
Syntax
AI_GENERATE(<input>, <prompt>, <model_id>)
Parameters
| Parameter | Description |
|---|---|
input |
String
|
prompt |
String
|
model_id |
String literal
|
Example
This example classifies each review as positive, negative, or neutral.
SELECT
AI_GENERATE( 'Review: ' || REVIEW_TEXT || ';
Rating: ' || CAST(RATING
AS VARCHAR(5)), 'Given the review and rating,
classify the review as positive, negative, or neutral. Return only one word in lowercase
between the options: positive, negative, or neutral.', 'model'.'id' ) FROM
REVIEWS;
Best Practices
Keep these best practices in mind when you use the
AI_GENERATE function:
- Avoid vague prompts. Write clear and explicit instructions describing exactly what the model should produce.
- Specify the desired output format explicitly to prevent extra or unexpected text.
- Provide descriptive labels for each input value to help the model understand what each piece of data represents.
- Ensure the prompt references the same labels used in the input.
- Use punctuation and separators to clearly distinguish between multiple input values.
- Cast non-string expressions / columns to string.
- Use consistent and predictable labels across queries to improve reliability.
- Keep input text concise and focused to improve model quality and reduce unnecessary processing.