AI_SUMMARIZE is an AI function in MaxCompute that calls a model to summarize input text.
Syntax
STRING AI_SUMMARIZE(
STRING <model_name>,
STRING <version_name>,
STRING <input>
[, BIGINT <max_words>]
[, STRING <model_parameters>]
);Parameters
model_nameRequired. A string that specifies the name of the model to use. For more information, see SQL AI functions.
version_name: Required. A string that specifies the name of the model version to use. To use the default version, you can specify
DEFAULT_VERSION.input: Required. A string containing the text to be summarized.
max_words: Optional. An integer specifying the maximum number of words in the generated summary. Defaults to
50. A value of0disables the word limit; however, the output length is still constrained by the model's internal limits and themax_tokensparameter. Content exceeding these limits is truncated.model_parameters: Optional. A JSON-formatted string that specifies model parameters, such as
max_tokens,temperature, andtop_p.For example:'{"max_tokens": 500, "temperature": 0.6, "top_p": 0.95}'. The following parameters are supported:max_tokens: Sets the maximum number of tokens to generate in a single model call. For MaxCompute public models, the default value is 4096.
temperature: A value between 0 and 1 that controls the randomness of the model's output. A higher value results in more creative and diverse output, while a lower value makes the output more deterministic and conservative.
top_p: A value between 0 and 1 that limits the range of candidate tokens the model considers. A higher value results in a wider range and more diversity, while a lower value results in a narrower range and more focused output.
Return value
Returns a STRING containing the summary of the input text. The return rules are as follows:
Returns an error if the input is not of the STRING type.
Returns an error if max_words is NULL.
Examples
Example 1: Generate a summary with the default limit
Calls the Qwen3-4B-GGUF public model from MaxCompute to generate a summary for a text string with the default 50-word limit.
SET odps.sql.ai.treat.as.common.model=true;
SET odps.namespace.schema=true;
SELECT AI_SUMMARIZE(
bigdata_public_modelset.default.`Qwen3-4B-GGUF`,
DEFAULT_VERSION,
'MaxCompute (formerly ODPS) is a fast, fully managed, multi-tenant big data processing platform that can handle data from terabytes to petabytes. MaxCompute provides various computing models, including SQL, MapReduce, Graph, and machine learning. It uses a Serverless architecture to elastically scale computing resources based on load, eliminating the need for users to manage infrastructure. The platform is deeply integrated with other Alibaba Cloud services such as DataWorks (for data development), PAI (a machine learning platform), and Quick BI (for data visualization).'
) AS summary;
-- Result
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| summary |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| MaxCompute is a scalable, fully managed big data platform with SQL, MapReduce, and machine learning capabilities, integrated with Alibaba Cloud services. |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+Example 2: Generate a summary with a specified limit
Calls the Qwen3-4B-GGUF public model from MaxCompute to generate 30-word summaries for multiple articles.
-- Sample data
CREATE TABLE articles (
article STRING
);
INSERT INTO articles VALUES
('Artificial intelligence is reshaping the global economy. Industries from healthcare to finance are adopting AI solutions to automate processes, reduce costs, and improve decision-making. Machine learning models can analyze vast amounts of data to identify patterns that are difficult for humans to detect. However, the rapid adoption of AI also raises concerns about job displacement, data privacy, and algorithm bias. Governments and organizations are actively developing ethical guidelines and regulatory frameworks to ensure the responsible development of AI.'),
('Cloud computing has become critical infrastructure for modern enterprises. By migrating to the cloud, businesses can reduce hardware capital expenditures, achieve elastic scaling of resources on demand, and access cutting-edge technologies with low upfront investment. Major cloud service providers like Alibaba Cloud, AWS, and Azure offer a rich portfolio of services spanning computing, storage, databases, and AI. The rise of cloud-native architecture has also driven the widespread adoption of technologies such as microservices, containers, and Serverless.');
-- Generate summaries for the articles in the table
SET odps.sql.ai.treat.as.common.model=true;
SET odps.namespace.schema=true;
SELECT
AI_SUMMARIZE(
bigdata_public_modelset.default.`Qwen3-4B-GGUF`,
DEFAULT_VERSION,
article,
30
) AS summary,
article
FROM articles;
-- Result
+--------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|summary |article |
+--------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| AI is reshaping the economy, improving efficiency but raising ethical concerns. | Artificial intelligence is reshaping the global economy. Industries from healthcare to finance are adopting AI solutions to automate processes, reduce costs, and improve decision-making. Machine learning models can analyze vast amounts of data to identify patterns that are difficult for humans to detect. However, the rapid adoption of AI also raises concerns about job displacement, data privacy, and algorithm bias. Governments and organizations are actively developing ethical guidelines and regulatory frameworks to ensure the responsible development of AI. |
| Cloud computing reduces business costs by providing elastic resources and easy access to advanced technologies. | Cloud computing has become critical infrastructure for modern enterprises. By migrating to the cloud, businesses can reduce hardware capital expenditures, achieve elastic scaling of resources on demand, and access cutting-edge technologies with low upfront investment. Major cloud service providers like Alibaba Cloud, AWS, and Azure offer a rich portfolio of services spanning computing, storage, databases, and AI. The rise of cloud-native architecture has also driven the widespread adoption of technologies such as microservices, containers, and Serverless. |
+--------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+