- Categories:
String & binary functions (AI Functions)
AI_SIMILARITY¶
Computes a similarity score based on the vector cosine similarity value of the inputs’ embedding vectors. Currently supports both text and image similarity computation.
Syntax¶
Applying AI_SIMILARITY to string or image inputs:
Specifying the config object:
Arguments¶
Required:
If you’re specifying input strings:
input1,input2The strings with the text that you’re comparing and using to compute the similarity score.
If you’re specifying input images:
input1,input2FILE data type referencing the images to be compared.
Note
AI_SIMILARITY does not support computing the similarity between text and image inputs.
Optional:
config_objectAn OBJECT containing key-value pairs used to configure the model.
Key |
Type |
Default |
Description |
|---|---|---|---|
|
For STRING input, default to |
The embedding model used for embedding. Supported values are:
|
Returns¶
Returns a float value of range -1 to 1 that represents the similarity score computed using vector similarity between two embedding vectors for the inputs.
Access control requirements¶
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.
Examples¶
AI_SIMILARITY: Text¶
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'.
We can also compute similarity on text columns.
AI_SIMILARITY: Images¶
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.
We can also compute similarity among the images using Snowflake Directory Table for the stage containing the images.
Limitations¶
Snowflake AI functions don’t work on FILEs created from stage files from the following stage types:
Internal stages with encryption mode
TYPE = 'SNOWFLAKE_FULL'External stages with any customer-side encrypted mode:
TYPE = 'AWS_CSE'TYPE = 'AZURE_CSE'
User stage, table stage
Stage with double-quoted names
Billing¶
AI_SIMILARITY is currently billed under the AI_EMBED line item in SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_USAGE_HISTORY view.