すべてのプロダクト
Search
ドキュメントセンター

ApsaraDB for SelectDB:AI_SIMILARITY

最終更新日:Feb 04, 2026

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

構文

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

パラメーター

パラメーター

説明

<resource_name>

指定されたリソース名です。

<text_1>

文字列です。

<text_2>

テキストです。

戻り値

  • 0 ~ 10 の範囲の浮動小数点数を返します。0 は類似性がまったくないことを示し、10 は高い類似性を示します。値が大きいほど類似度が高くなります。

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

  • 結果は大規模言語モデル (LLM) によって生成されるため、出力が変動する可能性があります。

配送会社の顧客コメントを格納する次のテーブルがあるとします。

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 |
+-------------------------------------------------+-------+