Categories:

Aggregate functions (General) String & binary functions (Large Language Model)

AI_SUMMARIZE_AGG¶

Summarizes a column of text data.

For example, AI_SUMMARIZE_AGG(churn_reason) will return a summary of the churn_reason column.

Unlike AI_COMPLETE and SUMMARIZE (SNOWFLAKE.CORTEX), this function supports datasets larger than the maximum language model context window.

See also:

AI_AGG

Syntax¶

AI_SUMMARIZE_AGG( <expr> )
Copy

Arguments¶

Required:

expr

This is an expression that contains text for summarization, such as restaurant reviews or phone transcripts.

Returns¶

Returns a string summary of the expression.

Usage notes¶

This function provides a general purpose summary. For a more specific summary, use AI_AGG.

Examples¶

AI_SUMMARIZE_AGG can be used as a simple scalar function on string constants.

SELECT AI_SUMMARIZE_AGG('[Excellent, Great, Mediocre]');
Copy
The text discusses rating options, specifically mentioning three categories: Excellent, Great, and Mediocre.

AI_SUMMARIZE_AGG can be used on a column of data.

WITH reviews AS (
            SELECT 'Excellent' AS review
  UNION ALL SELECT 'Excellent'
  UNION ALL SELECT 'Great'
  UNION ALL SELECT 'Mediocre'
)
SELECT AI_SUMMARIZE_AGG(review)
  FROM reviews;
Copy
A product or service received a total of 4 ratings, with 2 being "Excellent", 1 being "Great", and 1 being "Mediocre".

AI_SUMMARIZE_AGG can also be used in combination with GROUP BY.

WITH reviews AS (
            SELECT 1 AS product_id, 'Excellent' AS review
  UNION ALL SELECT 1, 'Excellent'
  UNION ALL SELECT 1, 'Great'
  UNION ALL SELECT 1, 'Mediocre'
  UNION ALL SELECT 2, 'Terrible'
  UNION ALL SELECT 2, 'Bad'
)
SELECT product_id,
       AI_SUMMARIZE_AGG(review) AS summarized_review
  FROM reviews
 GROUP BY 1;
Copy
+------------+------------------------------------------------------------------------------------------------------------------------+
| PRODUCT_ID | SUMMARIZED_REVIEW                                                                                                      |
|------------+------------------------------------------------------------------------------------------------------------------------+
| 1          | A product or service received a total of 4 ratings, with 2 being "Excellent", 1 being "Great", and 1 being "Mediocre". |
+------------+------------------------------------------------------------------------------------------------------------------------+
| 2          | The text expresses a strong negative sentiment, conveying a terrible and bad experience or opinion.                    |
+------------+------------------------------------------------------------------------------------------------------------------------+

See also AI_AGG.