Catégories :

Fonctions d’agrégation (général) Fonctions de chaîne et fonctions binaires (Fonctions AI)

AI_SUMMARIZE_AGG

Résume une colonne de données textuelles.

Par exemple, AI_SUMMARIZE_AGG(churn_reason) renverra un résumé de la colonne churn_reason.

Contrairement à AI_COMPLETE et SUMMARIZE (SNOWFLAKE.CORTEX), cette fonction prend en charge des ensembles de données plus grands que la fenêtre contextuelle maximale du modèle de langage.

Voir aussi ::

AI_AGG

Syntaxe

AI_SUMMARIZE_AGG( <expr> )
Copy

Arguments

Obligatoire :

expr

Il s’agit d’une expression qui contient du texte à résumer, comme des critiques de restaurants ou des transcriptions téléphoniques.

Renvoie

Renvoie un résumé sous forme de chaîne de l’expression.

Notes sur l’utilisation

Cette fonction fournit un résumé général. Pour obtenir un résumé plus précis, utilisez AI_AGG.

Exemples

AI_SUMMARIZE_AGG peut être utilisé comme une simple fonction scalaire sur des constantes de chaîne.

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 peut être utilisé sur une colonne de données.

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 peut également être utilisé en combinaison avec 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.                                                                                          |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Voir aussi AI_AGG.