AI_AGG

Feb 23, 2026

·

5

min read

AI_AGG

Overview

Aggregates a text column and returns insights across multiple rows based on a user-defined prompt. Not subject to context window limitations per row.

Syntax

AI_AGG(
  text_column,
  instruction
)
AI_AGG(
  text_column,
  instruction
)
AI_AGG(
  text_column,
  instruction
)

Parameters

  • text_column (VARCHAR): Column containing text to aggregate

  • instruction (VARCHAR): Natural language prompt describing the desired aggregation

Use Cases

  • Summarize customer feedback across products

  • Extract common themes from reviews

  • Identify key insights from multiple records

  • Aggregate findings from grouped data

  • Generate executive summaries from detailed records

Code Examples

Example 1: Summarize Product Reviews

SELECT 
    product_id,
    AI_AGG(
        review_text,
        'Summarize the key themes in customer reviews'
    ) AS review_summary
FROM customer_reviews
GROUP BY

SELECT 
    product_id,
    AI_AGG(
        review_text,
        'Summarize the key themes in customer reviews'
    ) AS review_summary
FROM customer_reviews
GROUP BY

SELECT 
    product_id,
    AI_AGG(
        review_text,
        'Summarize the key themes in customer reviews'
    ) AS review_summary
FROM customer_reviews
GROUP BY

Output:

product_id | review_summary
-----------|---------------
101        | Customers praise battery life and performance but cite high price as concern
102        | Mixed feedback on durability; excellent display quality noted frequently
product_id | review_summary
-----------|---------------
101        | Customers praise battery life and performance but cite high price as concern
102        | Mixed feedback on durability; excellent display quality noted frequently
product_id | review_summary
-----------|---------------
101        | Customers praise battery life and performance but cite high price as concern
102        | Mixed feedback on durability; excellent display quality noted frequently

Example 2: Extract Common Complaints

SELECT 
    department,
    AI_AGG(
        ticket_description,
        'List the top 3 most common issues mentioned'
    ) AS common_issues
FROM support_tickets
WHERE created_date >= CURRENT_DATE - 30
GROUP BY

SELECT 
    department,
    AI_AGG(
        ticket_description,
        'List the top 3 most common issues mentioned'
    ) AS common_issues
FROM support_tickets
WHERE created_date >= CURRENT_DATE - 30
GROUP BY

SELECT 
    department,
    AI_AGG(
        ticket_description,
        'List the top 3 most common issues mentioned'
    ) AS common_issues
FROM support_tickets
WHERE created_date >= CURRENT_DATE - 30
GROUP BY

Example 3: Identify Opportunities

SELECT 
    region,
    AI_AGG(
        sales_notes,
        'Identify potential upsell opportunities mentioned by sales team'
    ) AS opportunities
FROM sales_calls
WHERE call_date >= CURRENT_DATE - 90
GROUP BY

SELECT 
    region,
    AI_AGG(
        sales_notes,
        'Identify potential upsell opportunities mentioned by sales team'
    ) AS opportunities
FROM sales_calls
WHERE call_date >= CURRENT_DATE - 90
GROUP BY

SELECT 
    region,
    AI_AGG(
        sales_notes,
        'Identify potential upsell opportunities mentioned by sales team'
    ) AS opportunities
FROM sales_calls
WHERE call_date >= CURRENT_DATE - 90
GROUP BY

Example 4: Generate Executive Summary

SELECT 
    AI_AGG(
        meeting_notes,
        'Create an executive summary highlighting decisions made and action items'
    ) AS executive_summary
FROM weekly_meetings
WHERE meeting_date >= DATE_TRUNC('month', CURRENT_DATE)

SELECT 
    AI_AGG(
        meeting_notes,
        'Create an executive summary highlighting decisions made and action items'
    ) AS executive_summary
FROM weekly_meetings
WHERE meeting_date >= DATE_TRUNC('month', CURRENT_DATE)

SELECT 
    AI_AGG(
        meeting_notes,
        'Create an executive summary highlighting decisions made and action items'
    ) AS executive_summary
FROM weekly_meetings
WHERE meeting_date >= DATE_TRUNC('month', CURRENT_DATE)

Example 5: Sentiment Analysis Across Groups

SELECT 
    product_category,
    AI_AGG(
        customer_feedback,
        'Summarize overall customer sentiment and provide specific examples of positive and negative feedback'
    ) AS sentiment_analysis
FROM feedback
GROUP BY

SELECT 
    product_category,
    AI_AGG(
        customer_feedback,
        'Summarize overall customer sentiment and provide specific examples of positive and negative feedback'
    ) AS sentiment_analysis
FROM feedback
GROUP BY

SELECT 
    product_category,
    AI_AGG(
        customer_feedback,
        'Summarize overall customer sentiment and provide specific examples of positive and negative feedback'
    ) AS sentiment_analysis
FROM feedback
GROUP BY

Data Output Examples

Customer Feedback Aggregation

Input: 20 customer reviews for a laptop
Instruction: "Summarize the main pros and cons"

Output:
"Pros: Excellent battery life (15+ mentions), fast performance, lightweight design.
Cons: High price point, limited port selection, loud fan noise under heavy load

Input: 20 customer reviews for a laptop
Instruction: "Summarize the main pros and cons"

Output:
"Pros: Excellent battery life (15+ mentions), fast performance, lightweight design.
Cons: High price point, limited port selection, loud fan noise under heavy load

Input: 20 customer reviews for a laptop
Instruction: "Summarize the main pros and cons"

Output:
"Pros: Excellent battery life (15+ mentions), fast performance, lightweight design.
Cons: High price point, limited port selection, loud fan noise under heavy load

Support Ticket Analysis

Input: 50 support tickets
Instruction: "What are the recurring technical issues?"

Output:
"Top issues: 1) Login failures (40% of tickets), 2) Slow page load times (25%), 
3) Mobile app crashes (20%), 4) Payment processing errors (15%)

Input: 50 support tickets
Instruction: "What are the recurring technical issues?"

Output:
"Top issues: 1) Login failures (40% of tickets), 2) Slow page load times (25%), 
3) Mobile app crashes (20%), 4) Payment processing errors (15%)

Input: 50 support tickets
Instruction: "What are the recurring technical issues?"

Output:
"Top issues: 1) Login failures (40% of tickets), 2) Slow page load times (25%), 
3) Mobile app crashes (20%), 4) Payment processing errors (15%)

Model Information

  • Model Used: Snowflake managed model

  • Context Window: 128,000 tokens per row (can aggregate across unlimited rows)

  • Max Output: 8,192 tokens

Limitations & Considerations

Input Processing

  • Each row can contain up to 128,000 tokens

  • Function processes all rows in the group

  • No hard limit on number of rows aggregated

Cost

  • Billing based on total input and output tokens

  • All aggregated text counts toward input tokens

  • Instruction counts as input for each group

Performance

  • Designed for batch processing

  • Use MEDIUM warehouse or smaller

  • Processing time scales with data volume

Regional Availability

  • AWS US West/East: ✓

  • Azure East US: ✓

  • EU regions: ✓

  • Cross-region inference: ✓

Best Practices

1. Use Detailed Instructions

-- Good: Specific task description
AI_AGG(
    review_text,
    'Summarize customer feedback for an investor report, highlighting product strengths, weaknesses, and recommended improvements'
)

-- Less effective: Vague instruction
AI_AGG(review_text, 'Summarize')
-- Good: Specific task description
AI_AGG(
    review_text,
    'Summarize customer feedback for an investor report, highlighting product strengths, weaknesses, and recommended improvements'
)

-- Less effective: Vague instruction
AI_AGG(review_text, 'Summarize')
-- Good: Specific task description
AI_AGG(
    review_text,
    'Summarize customer feedback for an investor report, highlighting product strengths, weaknesses, and recommended improvements'
)

-- Less effective: Vague instruction
AI_AGG(review_text, 'Summarize')

2. Pre-filter Data

-- Filter before aggregating for better relevance
SELECT 
    product_id,
    AI_AGG(
        review_text,
        'What are customers saying about product quality?'
    ) AS quality_feedback
FROM customer_reviews
WHERE rating <= 3  -- Focus on critical reviews
  AND created_date >= CURRENT_DATE - 90
GROUP BY

-- Filter before aggregating for better relevance
SELECT 
    product_id,
    AI_AGG(
        review_text,
        'What are customers saying about product quality?'
    ) AS quality_feedback
FROM customer_reviews
WHERE rating <= 3  -- Focus on critical reviews
  AND created_date >= CURRENT_DATE - 90
GROUP BY

-- Filter before aggregating for better relevance
SELECT 
    product_id,
    AI_AGG(
        review_text,
        'What are customers saying about product quality?'
    ) AS quality_feedback
FROM customer_reviews
WHERE rating <= 3  -- Focus on critical reviews
  AND created_date >= CURRENT_DATE - 90
GROUP BY

3. Appropriate Grouping

-- Group by meaningful dimensions
SELECT 
    product_category,
    price_range,
    AI_AGG(
        review_text,
        'Summarize value-for-money sentiment'
    ) AS value_perception
FROM reviews
GROUP BY product_category,

-- Group by meaningful dimensions
SELECT 
    product_category,
    price_range,
    AI_AGG(
        review_text,
        'Summarize value-for-money sentiment'
    ) AS value_perception
FROM reviews
GROUP BY product_category,

-- Group by meaningful dimensions
SELECT 
    product_category,
    price_range,
    AI_AGG(
        review_text,
        'Summarize value-for-money sentiment'
    ) AS value_perception
FROM reviews
GROUP BY product_category,

4. Combine with Metrics

SELECT 
    product_id,
    COUNT(*) AS review_count,
    AVG(rating) AS avg_rating,
    AI_AGG(
        review_text,
        'Extract the most frequently mentioned feature (positive or negative)'
    ) AS key_feature
FROM reviews
GROUP BY product_id
HAVING COUNT(*) >= 10;  -- Ensure sufficient data
SELECT 
    product_id,
    COUNT(*) AS review_count,
    AVG(rating) AS avg_rating,
    AI_AGG(
        review_text,
        'Extract the most frequently mentioned feature (positive or negative)'
    ) AS key_feature
FROM reviews
GROUP BY product_id
HAVING COUNT(*) >= 10;  -- Ensure sufficient data
SELECT 
    product_id,
    COUNT(*) AS review_count,
    AVG(rating) AS avg_rating,
    AI_AGG(
        review_text,
        'Extract the most frequently mentioned feature (positive or negative)'
    ) AS key_feature
FROM reviews
GROUP BY product_id
HAVING COUNT(*) >= 10;  -- Ensure sufficient data

Common Use Cases

Market Research

SELECT 
    competitor,
    AI_AGG(
        customer_comment,
        'What competitive advantages or disadvantages are mentioned?'
    ) AS competitive_analysis
FROM competitor_mentions
GROUP BY

SELECT 
    competitor,
    AI_AGG(
        customer_comment,
        'What competitive advantages or disadvantages are mentioned?'
    ) AS competitive_analysis
FROM competitor_mentions
GROUP BY

SELECT 
    competitor,
    AI_AGG(
        customer_comment,
        'What competitive advantages or disadvantages are mentioned?'
    ) AS competitive_analysis
FROM competitor_mentions
GROUP BY

Product Development

SELECT 
    feature_request_category,
    AI_AGG(
        user_request,
        'Prioritize feature requests by frequency and impact'
    ) AS prioritized_requests
FROM feature_requests
GROUP BY

SELECT 
    feature_request_category,
    AI_AGG(
        user_request,
        'Prioritize feature requests by frequency and impact'
    ) AS prioritized_requests
FROM feature_requests
GROUP BY

SELECT 
    feature_request_category,
    AI_AGG(
        user_request,
        'Prioritize feature requests by frequency and impact'
    ) AS prioritized_requests
FROM feature_requests
GROUP BY

Related Functions

  • AI_SUMMARIZE_AGG - Specialized for summaries

  • AI_COMPLETE - For more complex analysis

  • AI_SENTIMENT - For sentiment-specific aggregation

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

More Articles

decorative icon

Experience Analytics for the AI-Era

Start your 14-day trial today - it's free and no credit card needed

decorative icon

Experience Analytics for the AI-Era

Start your 14-day trial today - it's free and no credit card needed

decorative icon

Experience Analytics for the AI-Era

Start your 14-day trial today - it's free and no credit card needed

Copyright © 2026 Paradime Labs, Inc.

Made with ❤️ in San Francisco ・ London

*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.

Copyright © 2026 Paradime Labs, Inc.

Made with ❤️ in San Francisco ・ London

*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.

Copyright © 2026 Paradime Labs, Inc.

Made with ❤️ in San Francisco ・ London

*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.