Snowflake Gen AI Functions · Topic 6 of 26
SUMMARIZE, AI_SUMMARIZE_AGG and AI_AGG - Condensing Text Across Rows
Pick between SUMMARIZE and AI_SUMMARIZE for one value, and AI_SUMMARIZE_AGG or AI_AGG for many rows. Know syntax, GROUP BY use and context window behavior.
- 4 min
- Includes a diagram
SUMMARIZE(legacySNOWFLAKE.CORTEX) andAI_SUMMARIZEsummarize one value;AI_SUMMARIZEalso takes files and is in preview.AI_SUMMARIZE_AGG(expr)summarizes many rows;AI_AGG(expr, instruction)follows your instruction.- Both aggregate functions handle data larger than one model context window.
What it is
Three Cortex functions turn text into shorter text, and the difference is how many rows go in.
SUMMARIZEsummarizes one text value. It is the olderSNOWFLAKE.CORTEX.SUMMARIZEfunction. The current counterpart isAI_SUMMARIZE, which also accepts a staged image or document.AI_SUMMARIZE_AGGis an aggregate function. It summarizes a whole column of text, such as every review for a product, into one summary.AI_AGGis an aggregate function that applies an instruction you write to a column of text across rows.
Both aggregate functions "support datasets larger than the maximum language model context window". This is the key fact: unlike AI_COMPLETE and AI_SUMMARIZE, they do not fail because the combined text is too long.
How it works
SUMMARIZE and AI_SUMMARIZE
SELECT SNOWFLAKE.CORTEX.SUMMARIZE(article_text) FROM articles;
SELECT AI_SUMMARIZE(article_text) FROM articles;
SELECT AI_SUMMARIZE(TO_FILE('@docs', 'report.pdf'));
Both return a string summary. AI_SUMMARIZE is marked as a preview feature in its documentation. A very short input, 110 characters or fewer, is returned unchanged, and so is an input where the generated summary would be longer than the source. All processed tokens are billed.
Summary quality varies by language, though many are supported. These functions add their own prompt tokens, so billed tokens exceed your input.
A scenario that asks to summarize each row of a column individually points to SUMMARIZE or AI_SUMMARIZE. A scenario that asks for one summary of many rows points to an aggregate function.
AI_SUMMARIZE_AGG
AI_SUMMARIZE_AGG(<expr>)
It takes one text expression and returns one string. Use GROUP BY to get one summary per group.
SELECT product_id, AI_SUMMARIZE_AGG(review_text) AS review_summary
FROM reviews
GROUP BY product_id;
To summarize several columns, combine them first with CONCAT or ||. The summary is general purpose and there is no way to steer it, which is the reason AI_AGG exists.
AI_AGG
AI_AGG(<expr>, <instruction>)
The second argument is a natural language instruction. Typical instructions are "Summarize the reviews", or "Identify all people mentioned and write a short biography for each of them".
SELECT restaurant_id,
AI_AGG(review, 'List the three most common complaints') AS complaints
FROM reviews
GROUP BY restaurant_id;
Guidance from the documentation:
- Use plain English and declarative instructions rather than questions.
- Describe the text and the intended use case.
- Split complex instructions into several steps.
- If the instruction is vague or the data lacks the answer, the function may say that the data does not contain it.
Comparison

| Aspect | SUMMARIZE or AI_SUMMARIZE | AI_SUMMARIZE_AGG | AI_AGG |
|---|---|---|---|
| Rows per result | One value | Many rows | Many rows |
| Instruction | None | None, general summary | Required, written by you |
| Beyond one context window | No | Yes | Yes |
| Typical use | Summarize each document | Summary per product or group | Targeted result, such as top complaints |
For a long list of rows, prefer AI_AGG to building one string with LISTAGG and sending it to a single call, since that string could exceed the context window.
Access and billing
All of them need USE AI FUNCTIONS and the CORTEX_USER role. A role that has AI_FUNCTIONS_USER but not CORTEX_USER covers the scalar functions only, so it excludes AI_AGG and AI_SUMMARIZE_AGG. Billing is by input and output tokens, with extra prompt tokens added by the function.
Do not concatenate a whole column with LISTAGG and pass it to AI_COMPLETE. It can exceed the context window and fail, while AI_AGG handles it.
Common mistakes
Using AI_COMPLETE to summarize a large table. The combined text may not fit in the context window; use AI_SUMMARIZE_AGG or AI_AGG.
Choosing AI_SUMMARIZE_AGG when a specific outcome is needed. It has no instruction argument; use AI_AGG.
Forgetting GROUP BY. Without it you get one summary for the whole table, not one per group.
Writing the instruction as a question. Declarative instructions work better.
Granting only AI_FUNCTIONS_USER and expecting AI_AGG to work. That role excludes the aggregate functions.
What to remember for the exam
SUMMARIZE(legacySNOWFLAKE.CORTEX) andAI_SUMMARIZEsummarize one value;AI_SUMMARIZEalso takes files and is in preview.AI_SUMMARIZE_AGG(expr)summarizes many rows;AI_AGG(expr, instruction)follows your instruction.- Both aggregate functions handle data larger than one model context window.
- Use
GROUP BYfor one result per group, and combine columns withCONCATor||. - Inputs of 110 characters or fewer are returned unchanged by
AI_SUMMARIZE.
Check yourself
Which function summarizes thousands of reviews per product without hitting the context limit?
AI_SUMMARIZE_AGG, grouped by product (orAI_AGGwhen an instruction is needed).What argument does
AI_AGGhave thatAI_SUMMARIZE_AGGlacks?An
instructionstring that tells it how to aggregate.What happens when you pass 100 characters to
AI_SUMMARIZE?The input is returned unchanged because it is 110 characters or fewer.
Topic 6 of 26 in Snowflake Gen AI Functions
Test yourself on Snowflake Gen AI Functions
The full Snowflake GES-C02 question bank has 585 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.