AI_SIMILARITY
functiondeferredAI & MLComputes 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
AI_SIMILARITY( <input1>, <input2> )
Specifying the config object
AI_SIMILARITY( <input1>, <input2>, <config_object> )
Parameters
| Name | Required | Description |
|---|---|---|
input1, input2 | required | The strings with the text that you’re comparing and using to compute the similarity score. |
input1, input2 | required | FILE data type referencing the images to be compared. |
config_object | optional | An OBJECT containing key-value pairs used to configure the model. |
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.
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.
Legal notices
Refer to Snowflake AI and ML for legal notices.
Known gaps
- The emulator does not run language, embedding, document or speech models, so Cortex AI functions have no model to answer with.