全部產品
Search
文件中心

ApsaraDB for SelectDB:AI_SIMILARITY

更新時間:Feb 04, 2026

判斷兩個文本之間的語義相似性。

文法

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