AI_AGG

AI_AGG

자연어 지시(instruction)를 사용해 텍스트 데이터 컬럼을 요약·집계하는 함수예요. 예를 들어 AI_AGG(reviews, 'Describe the most common complaints mentioned in the book reviews')는 사용자 피드백 요약을 반환합니다.

출처: Snowflake SQL Reference

본문

COMPLETE (SNOWFLAKE.CORTEX)나 AI_SUMMARIZE와 달리, 이 함수는 언어 모델 컨텍스트 창 최대 크기보다 큰 데이터셋도 지원해요.

AI_AGG( <expr>, <instruction> )

expr — 집계 작업을 수행할 텍스트(예: 레스토랑 리뷰, 전화 통화 기록)가 담긴 표현식.

instruction — 수행할 집계를 자연어로 지정한 문자열. 예: "Summarize the reviews" 또는 "Identify all people mentioned and write a short biography for each of them".

반환값 — 집계 결과가 담긴 문자열.

제공한 데이터에 답이 없음을 함수가 알릴 수 있는 경우는, 데이터를 집계하는 방법을 지정하는 명확한 지시를 제공하지 않았거나, 데이터에 지시를 완료하는 데 필요한 정보가 없을 때예요.

사용 메모 (최적 성능 가이드)

  • 지시는 평이한 영어 텍스트로 작성하세요.
  • 질문 대신 선언형 지시를 주세요. (예: "Can you summarize this?" 대신 "Summarize the phone call transcripts")
  • 지시 안에서 제공된 텍스트를 설명하세요. (예: "summarize" 대신 "Summarize the phone call transcripts")
  • 의도한 용도를 설명하세요. (예: "find the best review" 대신 "Find the most positive and well-written restaurant review to highlight on the restaurant website")
  • 문자열 표현식에 CONCAT이나 || 연산자로 여러 컬럼을 사용할 수 있어요.
  • 지시를 여러 단계로 나누는 걸 고려하세요. (예: "Summarize the new articles" 대신 "You will be provided with news articles from various publishers... Please create a concise and elaborative summary of source texts without missing any crucial information.")

예시 — 단일 문자열 상수로 요약:

SELECT AI_AGG('[Excellent, Excellent, Great, Mediocre]',
              'Summarize the product ratings for a blog post targeting consumers');

컬럼 데이터에도 사용할 수 있어요.

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;

GROUP BY와 함께 쓸 수도 있고, ||로 여러 컬럼을 합쳐 사용할 수도 있어요.

SELECT AI_AGG('Menu Item: ' || menu_item || '\nReview: ' || review,
              'Summarize the restaurant reviews for potential consumers')
  FROM reviews;

더 알아보기 (Learn more)