AI_SUMMARIZE_AGG

AI_SUMMARIZE_AGG

Overview

Aggregates a text column and returns a summary across multiple rows. Not subject to context window limitations.

Syntax

AI_SUMMARIZE_AGG(text_column)

Parameters

  • text_column (VARCHAR): Column containing text to summarize

Use Cases

  • Summarize customer feedback by product
  • Create executive summaries from detailed records
  • Generate meeting highlights across multiple sessions
  • Consolidate survey responses
  • Aggregate news articles by topic

Code Examples

Example 1: Summarize Reviews by Product

SELECT 
    product_id,
    COUNT(*) AS review_count,
    AI_SUMMARIZE_AGG(review_text) AS summary
FROM customer_reviews
GROUP BY product_id;

Output:

product_id | review_count | summary
-----------|--------------|--------
101        | 45           | Customers appreciate the battery life and build quality. Main concerns are price and weight.
102        | 32           | Highly rated for performance. Users report occasional connectivity issues.

Example 2: Monthly Meeting Summaries

SELECT 
    DATE_TRUNC('month', meeting_date) AS month,
    AI_SUMMARIZE_AGG(meeting_notes) AS monthly_summary
FROM team_meetings
WHERE meeting_date >= CURRENT_DATE - 180
GROUP BY month
ORDER BY month;

Example 3: Customer Feedback by Region

SELECT 
    customer_region,
    AI_SUMMARIZE_AGG(feedback_text) AS regional_feedback
FROM customer_feedback
WHERE feedback_date >= CURRENT_DATE - 30
GROUP BY customer_region;

Example 4: Summarize Support Tickets

SELECT 
    ticket_category,
    COUNT(*) AS ticket_count,
    AI_SUMMARIZE_AGG(ticket_description) AS category_summary
FROM support_tickets
WHERE status = 'Resolved'
  AND resolved_date >= CURRENT_DATE - 7
GROUP BY ticket_category;

Example 5: Sales Call Summaries

SELECT 
    sales_rep_id,
    sales_rep_name,
    AI_SUMMARIZE_AGG(call_notes) AS weekly_summary
FROM sales_calls
WHERE call_date >= DATE_TRUNC('week', CURRENT_DATE)
GROUP BY sales_rep_id, sales_rep_name;

Data Output Examples

Product Review Summary

Input: 50 customer reviews
Output: "The product receives high marks for design and functionality. 
Customers frequently mention the intuitive interface and fast performance. 
Common complaints include limited color options and higher price compared to competitors."

Meeting Notes Summary

Input: 4 weekly team meetings
Output: "Team focused on Q1 goals and resource allocation. Key decisions: 
hiring two new developers, postponing Feature X to Q2, implementing new CI/CD pipeline. 
Action items assigned for documentation updates and client presentations."

Model Information

  • Model Used: Snowflake managed model
  • Context Window: 128,000 tokens per row (unlimited rows)
  • Max Output: 8,192 tokens

Limitations & Considerations

Input Processing

  • Each row can contain up to 128,000 tokens
  • Aggregates across all rows in group
  • No hard limit on number of rows

Cost

  • Billing based on input and output tokens
  • All text in aggregated column counts as input
  • Automatic prompt overhead added

Output Quality

  • Works best with coherent, related content
  • May produce generic summaries for disparate content
  • Quality improves with focused grouping

Regional Availability

  • AWS US West/East: ✓
  • Azure East US: ✓
  • EU regions: ✓
  • Cross-region inference: ✓

Best Practices

1. Group Data Appropriately

-- Good: Grouped by meaningful dimension
SELECT 
    product_category,
    price_tier,
    AI_SUMMARIZE_AGG(review_text) AS summary
FROM reviews
GROUP BY product_category, price_tier;

-- Less effective: Too broad
SELECT AI_SUMMARIZE_AGG(review_text) FROM reviews;

2. Filter Before Aggregating

SELECT 
    product_id,
    AI_SUMMARIZE_AGG(feedback_text) AS critical_feedback
FROM customer_feedback  
WHERE sentiment_score < -0.5  -- Only negative feedback
  AND feedback_date >= CURRENT_DATE - 30
GROUP BY product_id;

3. Combine with Metrics

SELECT 
    department,
    COUNT(*) AS ticket_count,
    AVG(resolution_time_hours) AS avg_resolution_time,
    AI_SUMMARIZE_AGG(ticket_description) AS common_issues
FROM support_tickets
WHERE created_date >= CURRENT_DATE - 7
GROUP BY department;

4. Use for Report Generation

CREATE TABLE weekly_summaries AS
SELECT 
    DATE_TRUNC('week', event_date) AS week,
    event_type,
    COUNT(*) AS event_count,
    AI_SUMMARIZE_AGG(event_details) AS weekly_summary
FROM events
WHERE event_date >= CURRENT_DATE - 90
GROUP BY week, event_type;

Common Use Cases

Executive Reporting

SELECT 
    'Q1 2024' AS quarter,
    AI_SUMMARIZE_AGG(project_update) AS quarterly_summary
FROM project_updates
WHERE update_date BETWEEN '2024-01-01' AND '2024-03-31';

Customer Insights

SELECT 
    customer_segment,
    COUNT(DISTINCT customer_id) AS customer_count,
    AI_SUMMARIZE_AGG(feedback) AS segment_insights
FROM customer_feedback
GROUP BY customer_segment;

Competitive Analysis

SELECT 
    competitor_name,
    AI_SUMMARIZE_AGG(mention_text) AS competitor_mentions
FROM social_media_monitoring
WHERE mention_date >= CURRENT_DATE - 30
GROUP BY competitor_name;

Related Functions

  • AI_AGG - For custom aggregation prompts
  • AI_COMPLETE - For detailed analysis
  • AI_SENTIMENT - For sentiment-focused aggregation

Interested to Learn More? Try Out the Free 14-Days Trial

One AI-native workspace to build, ship, and monitor dbt™ — without the tool sprawl.