に最終更新
AI_AGG
説明
ユーザーが指定した指示に従い、大規模言語モデルを使用して特定の列を集約します。
構文
AI_AGG([<resource_name>], <expr>, <instruction>)
パラメータ
| パラメータ | 説明 |
|---|---|
<resource_name> | 指定されたリソース名。省略可能です。 |
<expr> | 集約対象のテキスト列。単一のテキストの文字数は 128K 未満である必要があります。 |
<instruction> | 実行する指示。リテラルのみ受け付けます。 |
戻り値
バージョン 4.1.5 以降、AI_AGG はモデルが生成した完全なテキストを単一の結果として返します。テキストに JSON 配列が含まれていても、その配列を複数の集約結果に分割しません。OpenAI Responses 形式では、reasoning や tool 項目などのテキスト以外の出力をスキップし、message 項目の output_text を連結します。レスポンスにステータスが含まれる場合は completed でなければならず、未完了のレスポンスやテキストを含まないレスポンスではエラーが報告されます。
集約結果を含む文字列を返します。
すべての入力値が NULL の場合は NULL を返します。
結果は言語モデルによって生成されるため、出力は固定されません。
例
次のテーブルは、カスタマーサポートチケットをシミュレートしたものです。
CREATE TABLE support_tickets (
ticket_id BIGINT,
customer_name VARCHAR(100),
subject VARCHAR(200),
details TEXT
)
DUPLICATE KEY(ticket_id)
DISTRIBUTED BY HASH(ticket_id) BUCKETS 5
PROPERTIES (
"replication_num" = "1"
);
INSERT INTO support_tickets VALUES
(1, 'Alice', 'Login Failure', 'Cannot log in after password reset. Tried clearing cache and different browsers.'),
(2, 'Bob', 'Login Failure', 'Same problem as Alice. Also seeing 502 errors on the SSO page.'),
(3, 'Carol', 'Payment Declined', 'Credit card charged twice but order still shows pending.'),
(4, 'Dave', 'Slow Dashboard', 'Dashboard takes >30 seconds to load since the last release.'),
(5, 'Eve', 'Login Failure', 'Getting redirected back to login after entering 2FA code.');
問題の件名ごとに顧客の問題を要約するには、AI_AGG を使用できます。
SELECT
subject,
AI_AGG(
'ai_resource_name',
details,
'Summarize every ticket detail into one short paragraph of 40 words or less.'
) AS ai_summary
FROM support_tickets
GROUP BY subject;
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| subject | ai_summary |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Slow Dashboard | The dashboard loading time has significantly increased to over 30 seconds following the latest release, indicating a potential issue with the recent update. |
| Login Failure | User experiences login issues, including redirection post-2FA, inability to log in after password reset despite using different browsers and clearing cache, and encountering 502 errors on the SSO page. |
| Payment Declined | The customer's credit card was charged twice, but the order status remains pending, indicating a potential issue with the transaction processing or system update. |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
例 2:
次のテーブルは、eコマースプラットフォームのユーザーレビューテーブルをシミュレートしたものです。
CREATE TABLE product_reviews (
review_id BIGINT,
product_id BIGINT,
rating TINYINT,
comment STRING
)
DUPLICATE KEY(review_id)
DISTRIBUTED BY HASH(product_id) BUCKETS 10
PROPERTIES (
"replication_num" = "1"
);
INSERT INTO product_reviews VALUES
(1, 1001, 5, '鞋子尺码刚好,穿着舒服,颜色也好看,物流很快!'),
(2, 1001, 4, '质量不错,就是鞋底有点硬,需要磨合几天。'),
(3, 1001, 3, '外观和图片一样,但收到时有轻微胶味。'),
(4, 1002, 5, '杯子小巧,出汁快,清洗也方便,上班带着刚好。'),
(5, 1002, 3, '声音有点大,不过能接受,充满电只能榨 5 杯。'),
(6, 1002, 2, '用了两周就充不进电,售后换货流程太慢。'),
(7, 1003, 5, '面料透气不闷热,袖口设计很贴心,UPF50+ 确实晒不黑。'),
(8, 1003, 4, '颜色好看,但拉链有点卡顿,需要用力。'),
(9, 1004, 5, '降噪给力,地铁里也能安静听歌,续航一周充一次。');
AI_AGG を使用して要約および評価を行います。
SET default_ai_resource = 'ai_resource_name';
SELECT
product_id,
AI_AGG(
comment,
'请把多条用户评价总结成一句话,突出买家最关心的优点和缺点,控制在50字以内。'
) AS 评价摘要
FROM product_reviews
GROUP BY product_id;
+------------+--------------------------------------------------------------------------------------------------------------+
| product_id | 评价摘要 |
+------------+--------------------------------------------------------------------------------------------------------------+
| 1003 | 该产品面料透气、防晒效果好且颜色美观,但拉链使用不顺畅。 |
| 1004 | 用户评价该产品降噪效果好,续航能力强,一周充一次电。 |
| 1001 | 买家普遍认为鞋子穿着舒适、外观好看且物流快,但鞋底偏硬且有轻微胶味。 |
| 1002 | 买家认为该榨汁杯小巧便携、出汁快且易清洗,但电池续航短且售后换货流程慢。 |
+------------+--------------------------------------------------------------------------------------------------------------+