- Categories:
String & binary functions (AI Functions)
AI_ SIMILARITY¶
基于输入嵌入向量的余弦相似度值,计算相似度分数。目前支持文本和图像相似度计算。
语法
将 AI_SIMILARITY 应用于字符串或图像输入:
指定配置对象:
实参
必填:
如果您要指定输入字符串:
input1,input2包含您正在比较的文本的字符串,用于计算相似度分数。
如果您要指定输入图像:
input1,input2FILE data type referencing the images to be compared.
Note
AI_SIMILARITY 不支持计算文本和图像输入之间的相似度。
可选:
config_objectAn OBJECT containing key-value pairs used to configure the model.
| Key | Type | Default | Description |
|---|---|---|---|
model | STRING | For STRING input, default to ‘snowflake-arctic-embed-l-v2.0’. For IMAGE input, default to ‘voyage-multimodal-3’ | 用于嵌入的嵌入模型。支持的值包括:
|
返回
返回介于 -1 到 1 之间的浮点值,该浮点值表示使用输入的两个嵌入向量之间的向量相似度计算的相似度分数。
访问控制要求
Users must use a role that has been granted the SNOWFLAKE.CORTEX_USER database role. See Cortex LLM privileges for more information on this privilege.
示例
AI_ SIMILARITY:文本¶
In this example, the function is computing a similarity score between the two statement inputs ‘I like this dish’ and ‘This dish is very good’.
我们还可以计算文本列的相似度。
AI_ SIMILARITY:图像¶
In this example, the function computes a similarity score between the two images, cat.jpg and 2cats.jpg, stored in a Snowflake stage @file_stage.
对于包含图像的暂存区,我们还可以使用 Snowflake Directory Table 计算图像之间的相似度。
限制
- Snowflake AI 函数不适用于通过以下暂存区类型的暂存区文件创建的 FILEs:
-
Internal stages with encryption mode
TYPE = 'SNOWFLAKE_FULL' -
使用任何客户端加密模式的外部暂存区:
TYPE = 'AWS_CSE'TYPE = 'AZURE_CSE'
-
用户暂存区、表暂存区
-
带有双引号名称的暂存区
-
计费
AI_SIMILARITY is currently billed under the AI_EMBED line item in SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_USAGE_HISTORY view.