Snowflake Gen AI Functions · Topic 8 of 26

AI_EMBED and AI_SIMILARITY - Embeddings and Semantic Comparison

Create vector embeddings with AI_EMBED and compare text or images with AI_SIMILARITY. Know models, input types, return values, access roles and billing.

  • 4 min
In a nutshell
  • AI_EMBED(model, input) returns a VECTOR; it replaces EMBED_TEXT_768 and EMBED_TEXT_1024.
  • Image embedding uses only voyage-multimodal-3.
  • AI_SIMILARITY returns a FLOAT from -1 to 1 and defaults to snowflake-arctic-embed-l-v2.0 for text.

What it is

An embedding is a list of numbers (a vector) that captures the meaning of a text or an image. Texts with similar meaning get vectors that point in similar directions, so you can find related content by comparing vectors instead of keywords.

AI_EMBED creates the embedding. AI_SIMILARITY goes one step further and returns a score for how close two inputs are, without you handling the vectors yourself. Snowflake says AI_EMBED replaces EMBED_TEXT_768 and EMBED_TEXT_1024.

Text or imageembedAI_EMBEDmodel argumentreturnsVECTOR valuestored in a columncompare withVector functionsranked matchesText A and text BcompareAI_SIMILARITYreturnsScoreminus 1 to 1

How it works

AI_EMBED

AI_EMBED(<model>, <input>)

The model is a string. The input is a string, or an image passed as a FILE value made with TO_FILE. The function returns a VECTOR value.

SELECT AI_EMBED('snowflake-arctic-embed-l-v2.0', 'How do I reset my password?');

CREATE TABLE doc_vectors AS
SELECT doc_id,
       AI_EMBED('snowflake-arctic-embed-l-v2.0', chunk_text) AS embedding
FROM doc_chunks;

Text models listed in the documentation:

  • snowflake-arctic-embed-l-v2.0 and snowflake-arctic-embed-l-v2.0-8k
  • snowflake-arctic-embed-m-v1.5 and snowflake-arctic-embed-m
  • nv-embed-qa-4
  • multilingual-e5-large
  • voyage-multilingual-2
  • e5-base-v2

For images the only supported model is voyage-multimodal-3. Image files must be JPEG, WEBP, PNG or BMP, no larger than 10 MB and no larger than 8,000 by 8,000 pixels. Image input is available in fewer regions than text. In open preview, text only, you can name a Snowpark Container Services inference service that hosts your own sentence transformer model.

Exam tip

A single model must be used for both the stored vectors and the query vector. Vectors from different models cannot be compared meaningfully.

Access

The caller needs the SNOWFLAKE.CORTEX_USER database role or the narrower SNOWFLAKE.CORTEX_EMBED_USER role. The second role covers embedding functions and Cortex Search services with managed embeddings, and is not granted to PUBLIC.

AI_SIMILARITY

AI_SIMILARITY(<input1>, <input2> [, <config_object>])

Both inputs are strings, or both are FILE images. A text input and an image input cannot be compared. The result is a FLOAT from -1 to 1, computed as the cosine similarity of the embeddings.

SELECT AI_SIMILARITY('refund my order', 'I want my money back');

SELECT t.ticket_id, k.article_id,
       AI_SIMILARITY(t.text, k.title,
         {'model': 'multilingual-e5-large'}) AS score
FROM tickets t CROSS JOIN kb_articles k
ORDER BY score DESC;

The config object has one documented key, model. Its default is snowflake-arctic-embed-l-v2.0 for text and voyage-multimodal-3 for images. Other text models allowed are nv-embed-qa-4, multilingual-e5-large, voyage-multilingual-2, snowflake-arctic-embed-m-v1.5, snowflake-arctic-embed-m and e5-base-v2.

AI_EMBED or AI_SIMILARITY

NeedUse
Store vectors for later search or clusteringAI_EMBED
Compare one pair of values, or rank a small setAI_SIMILARITY
Search a large table repeatedlyAI_EMBED once, then vector functions on the stored vectors

AI_SIMILARITY recomputes embeddings every call. For repeated searches over a big table, embed once and store the result. This is also what a Cortex Search service does with its managed embeddings.

Where embeddings are used next

Embeddings are the building block for several later designs. A table of chunk vectors supports semantic search with the vector functions. A Cortex Search service builds and refreshes embeddings for you, so you do not manage the column yourself. Clustering and duplicate detection also work by comparing vectors.

Because AI_EMBED is billed per input token, embedding once and storing the vectors is cheaper than recomputing them at query time. Use AI_COUNT_TOKENS with ai_embed and the model name to estimate the cost of embedding a large table before you run it.

Billing and limits

Both functions are billed on input tokens only, and their credits show in SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_FUNCTIONS_USAGE_HISTORY (the older CORTEX_FUNCTIONS_USAGE_HISTORY view is no longer updated). Files from user stages, table stages, stages with double quoted names and certain client side encrypted stages cannot be used.

Watch out

If you change the embedding model, you must re-embed the stored data. Old and new vectors cannot be compared meaningfully.

Common mistakes

Mixing embedding models. Always embed the query with the same model as the stored vectors.

Calling AI_SIMILARITY in a large cross join. Every pair triggers embedding work; embed once and compare vectors instead.

Comparing a string to an image with AI_SIMILARITY. Both inputs must be the same kind.

Forgetting TO_FILE for images. Images must be FILE values.

Assuming CORTEX_EMBED_USER allows AI_COMPLETE. It covers embedding only.

What to remember for the exam

  • AI_EMBED(model, input) returns a VECTOR; it replaces EMBED_TEXT_768 and EMBED_TEXT_1024.
  • Image embedding uses only voyage-multimodal-3.
  • AI_SIMILARITY returns a FLOAT from -1 to 1 and defaults to snowflake-arctic-embed-l-v2.0 for text.
  • Roles: CORTEX_USER or CORTEX_EMBED_USER for AI_EMBED.
  • Billing is on input tokens only.
  • Embed once and store for repeated searches.

Check yourself

  • Which function turns a text chunk into a vector?

    AI_EMBED, which returns a VECTOR value.

  • What range does AI_SIMILARITY return?

    A FLOAT between -1 and 1, the cosine similarity of the two embeddings.

  • Which database role is limited to embedding use?

    SNOWFLAKE.CORTEX_EMBED_USER.

Topic 8 of 26 in Snowflake Gen AI Functions

Test yourself on Snowflake Gen AI Functions

The full Snowflake GES-C02 question bank has 585 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.