카테고리:

집계 함수 (일반) 문자열 및 이진 함수 (AI 함수)

AI_AGG

자연어 명령을 사용하여 텍스트 데이터의 열을 줄입니다.

예를 들어, AI_AGG(reviews, 'Describe the most common complaints mentioned in the book reviews') 는 사용자 피드백의 요약을 반환합니다.

COMPLETE (SNOWFLAKE.CORTEX)SUMMARIZE (SNOWFLAKE.CORTEX) 와 달리, 이 함수는 최대 언어 모델 컨텍스트 윈도우보다 큰 데이터 세트를 지원합니다.

참고 항목:

AI_SUMMARIZE_AGG

구문

AI_AGG( <expr>, <instruction> )
Copy

인자

필수:

expr

레스토랑 리뷰나 전화 기록과 같이 집계 작업을 수행할 텍스트가 포함된 식입니다.

instruction

수행할 집계 작업의 자연어 사양을 포함하는 문자열입니다(예: “Summarize the review” 또는 “Identify all people mentioned and write a short biography for each of them”).

반환

집계 결과가 포함된 문자열을 반환합니다.

이 함수는 다음과 같은 경우 제공한 데이터에 답변이 포함되어 있지 않음을 나타낼 수 있습니다.

  • 데이터 집계 방법을 지정하는 명확한 지침을 제공하지 않은 경우

  • 데이터에 지침을 완료하는 데 필요한 정보가 없는 경우

사용법 노트

최적의 성능을 위해 다음 지침을 따르십시오.

  • 지침에는 일반 영어 텍스트를 사용합니다.

  • 질문하는 대신 선언적 지침을 제공합니다. 예를 들어, “Can you Summary this?”와 같은 질문 대신 “Summarize the phone call transcripts”를 사용합니다.

  • 지침에 제공된 텍스트를 설명합니다. 예를 들어, “summarize”과 같은 지침 대신 “Summarize the phone call transcripts”를 사용합니다.

  • 의도된 사용 사례를 설명합니다. 예를 들어 “최고의 리뷰 찾기” 대신 “레스토랑 웹사이트에서 강조 표시할 가장 긍정적이고 잘 작성된 레스토랑 리뷰 찾기”를 사용하십시오.

  • 지침을 여러 단계로 나누는 것이 좋습니다. 예를 들어, “Summarize the new articles” 대신 “You will be provided with news articles from various publishers presenting events from different points of view. Please create a concise and elaborative summary of source texts without missing any crucial information.”을 사용합니다.

AI_AGG는 문자열 상수에 대한 간단한 스칼라 함수로 사용할 수 있습니다. 다음 예제에서 AI_AGG는 단일 문자열로 제공되는 제품 평가를 요약하는 데 사용됩니다.

SELECT AI_AGG('[Excellent, Excellent, Great, Mediocre]',
              'Summarize the product ratings for a blog post targeting consumers');
Copy
Overall, the product has received overwhelmingly positive reviews, with the majority of users rating it as 'Excellent' or 'Great'. Only a small percentage of users had a mediocre experience with the product. This suggests that the product is well-liked by most consumers and is a great option for those looking for a reliable choice.

AI_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_AGG(review, 'Summarize the restaurant reviews for potential consumers')
  FROM reviews;
Copy
Reviews for this restaurant are mixed. Some customers had a very positive experience, describing the restaurant as "excellent" and loving the pizza. However, others had a more neutral or negative experience, citing mediocre food and service.

AI_AGG를 GROUP BY와 함께 사용할 수도 있습니다. 다음 예제에서는 두 제품(열 ``product_id``로 식별)에 대한 제품 평가를 리뷰 테이블에 요약합니다.

WITH reviews AS (
            SELECT 1 AS restaurant_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 restaurant_id,
       AI_AGG(review, 'Summarize the restaurant reviews for potential consumers')
  FROM reviews
 GROUP BY 1;
Copy
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| RESTAURANT_ID | SUMMARIZED_REVIEW                                                                                                                                                                                                                                 |
|---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1             | Reviews for this restaurant are mixed. Some customers had a very positive experience, describing the restaurant as "excellent" and loving the pizza. However, others had a more neutral or negative experience, citing mediocre food and service. |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2             | Two reviewers had extremely negative experiences at this restaurant, citing poor quality ingredients and advising others to avoid it.                                                                                                             |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

이 지침은 다양한 집계 작업과 응답의 스타일 및 어조를 구성하는 데 사용할 수 있습니다. 다음 예제에서는 지침을 사용하여 각 제품에 대한 가장 긍정적인 평가를 찾고 평가의 프랑스어 및 폴란드어 번역을 제공합니다.

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'
  UNION ALL SELECT 2, 'Average'
)
SELECT product_id,
       AI_AGG(review, 'Identify the most positive rating and translate it into French and Polish, one word only') AS summarized_review
  FROM reviews
 GROUP BY 1;
Copy
+------------+--------------------+
| PRODUCT_ID | SUMMARIZED_REVIEW  |
|------------+--------------------+
| 1          | French: Excellent  |
|            | Polish: Doskonały  |
+------------+--------------------+
| 2          | French: Moyen      |
|            | Polish: Przeciętny |
+------------+--------------------+

AI_SUMMARIZE_AGG 도 참조하십시오.