カテゴリ:

/sql-reference/functions-aggregation`(一般):doc:/sql-reference/functions-string`(AI 関数)

AI_SUMMARIZE_AGG

テキストデータの列を要約します。

例えば、 AI_SUMMARIZE_AGG(churn_reason) は、 churn_reason 列の要約を返します。

AI_COMPLETESUMMARIZE (SNOWFLAKE.CORTEX) とは異なり、この関数は言語モデルのコンテキストウィンドウの最大値よりも大きなデータセットをサポートします。

こちらもご覧ください:

AI_AGG

構文

AI_SUMMARIZE_AGG( <expr> )
Copy

引数

必須:

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.');
Copy
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;
Copy
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;
Copy
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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 もご参照ください。