- 类别:
/sql-reference/functions-aggregation`(通用):doc:/sql-reference/functions-string`(大语言模型)
AI_SUMMARIZE_AGG¶
汇总一列文本数据。
例如,AI_SUMMARIZE_AGG(churn_reason)
将返回 churn_reason
列的摘要。
与 AI_COMPLETE 和 SUMMARIZE (SNOWFLAKE.CORTEX) 不同,此函数支持大于最大语言模型上下文窗口的数据集。
- 另请参阅:
语法¶
AI_SUMMARIZE_AGG( <expr> )
实参¶
必填:
expr
此表达式包含用于摘要的文本,例如餐厅评论或电话记录。
返回¶
返回表达式的字符串摘要。
使用说明¶
此函数提供通用摘要。要获得更具体的摘要,请使用 AI_AGG。
示例¶
AI_SUMMARIZE_AGG 可以用作字符串常量的简单标量函数。
SELECT AI_SUMMARIZE_AGG('The restaurant was excellent. I especially enjoyed the pizza and ice cream. My grandma didnt like it though.');
The restaurant received mixed reviews from our group. While I thoroughly enjoyed the pizza and ice cream, my grandma did not have a positive experience.
AI_SUMMARIZE_AGG 可以用于一列数据。
WITH reviews AS (
SELECT 'The restaurant was excellent.' AS review
UNION ALL SELECT 'Excellent! I loved the pizza!'
UNION ALL SELECT 'It was great, but the service was meh.'
UNION ALL SELECT 'Mediocre food and mediocre service'
)
SELECT AI_SUMMARIZE_AGG(review)
FROM reviews;
The restaurant received mixed reviews. Some customers had a great experience, enjoying the pizza and finding the restaurant excellent. However, others had a more neutral experience, describing the food and service as mediocre, with one customer specifically mentioning that the service was subpar.
AI_SUMMARIZE_AGG 也可以与 GROUP BY 结合使用。
WITH reviews AS (
SELECT 1 AS product_id, 'The restaurant was excellent.' AS review
UNION ALL SELECT 1, 'Excellent! I loved the pizza!'
UNION ALL SELECT 1, 'It was great, but the service was meh.'
UNION ALL SELECT 1, 'Mediocre food and mediocre service'
UNION ALL SELECT 2, 'Terrible quality ingredients, I should have eaten at home.'
UNION ALL SELECT 2, 'Bad restaurant, I would avoid this place.'
)
SELECT product_id,
AI_SUMMARIZE_AGG(review) AS summarized_review
FROM reviews
GROUP BY 1;
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PRODUCT_ID | SUMMARIZED_REVIEW |
|------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | The restaurant received mixed reviews. Some customers had a great experience, enjoying the pizza and finding the restaurant excellent. However, others had a more neutral experience, describing the food and service as mediocre, with one customer specifically mentioning that the service was subpar. |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2 | The reviewer had a poor experience at the restaurant, citing the use of low-quality ingredients and expressing regret over not eating at home instead. They strongly advise against visiting this establishment. |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
另请参阅 AI_AGG。