メインコンテンツまでスキップ
に最終更新

AI_SIMILARITY

説明​

二つのテキスト間の意味的類似度を判定します。

構文​

AI_SIMILARITY([<resource_name>], <text_1>, <text_2>)

引数​

引数説明
<resource_name>指定するリソース名
<text_1>テキスト
<text_2>テキスト

戻り値​

0 から 10 の浮動小数点値を返します。0 は類似性がないことを、10 は類似性が高いことを示します。

いずれかの入力が NULL の場合は NULL を返します。

結果は大規模言語モデルによって生成されるため、出力は一定ではありません。

例​

配送会社に届いたコメントを表す次のテーブルがあるとします。

CREATE TABLE user_comments (
id INT,
comment VARCHAR(500)
) DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 10
PROPERTIES (
"replication_num" = "1"
);

顧客の感情に基づいてコメントを順位付けするには、次のようにします。

SELECT comment,
AI_SIMILARITY('resource_name', 'I am extremely dissatisfied with their service.', comment) AS score
FROM user_comments ORDER BY score DESC LIMIT 5;

クエリ結果の例:

+-------------------------------------------------+-------+
| comment | score |
+-------------------------------------------------+-------+
| It arrived broken and I am really disappointed. | 7.5 |
| Delivery was very slow and frustrating. | 6.5 |
| Not bad, but the packaging could be better. | 3.5 |
| It is fine, nothing special to mention. | 3 |
| Absolutely fantastic, highly recommend it. | 1 |
+-------------------------------------------------+-------+