CertSafari
    Snowflake SnowPro Advanced: Data Scientist (DSA-C03)· Lessons

    Domain 3 · Lesson 10/16

    Vector embeddings, RAG and Cortex fine-tuning

    Leverage GenAI and LLM models in Snowflake.

    15 min read
    6.2% of exam
    5 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    What you will be able to do

    • Pick an embedding model whose dimension and language support fit the data, and declare a matching VECTOR column
    • Rank rows by semantic similarity with the right function and sort direction
    • Build a retrieval-augmented generation query that feeds retrieved text into AI_COMPLETE
    • Create, monitor and pay for a Cortex fine-tuning job with FINETUNE

    1.Embeddings and the VECTOR data type

    An embedding is a list of numbers that represents a piece of text, produced so that texts with similar meaning get vectors pointing in a similar direction. This is what lets a help desk find earlier tickets about the same problem when the wording differs. Matching goes beyond keywords to meaning. In Snowflake, embeddings are created with the Cortex function AI_EMBED(model, text), which needs the same Cortex privileges as the other AI functions. They are stored in a column of type VECTOR(FLOAT, n).

    The model you choose fixes three things: the number of dimensions, how much text fits in one call, and which languages it understands. The legacy functions put the dimension in their names. SNOWFLAKE.CORTEX.EMBED_TEXT_768 serves the 768-dimension models and EMBED_TEXT_1024 serves the 1024-dimension ones. AI_EMBED replaces both.

    Cortex text embedding models
    ModelOutput dimensionsContext window (tokens)Language support
    snowflake-arctic-embed-m-v1.5768512English-only
    snowflake-arctic-embed-m768512English-only
    e5-base-v2768512English-only
    snowflake-arctic-embed-l-v2.01024512Multilingual
    voyage-multilingual-2102432000Multilingual
    nv-embed-qa-41024512English-only

    Language support decides which model you can use. A column with reviews in English, German, Japanese and Portuguese needs a model marked Multilingual, such as snowflake-arctic-embed-l-v2.0, so that every review goes through one model and is compared on the same terms. Running an English-only model such as e5-base-v2 or nv-embed-qa-4 over that column, or running it once per language, does not give you comparable multilingual vectors.

    The column's declared dimension must match the model's output. Writing a 1024-dimension embedding into a VECTOR(FLOAT, 768) column fails. There are only two ways to fix it: change the column to VECTOR(FLOAT, 1024), or switch to a 768-dimension model such as snowflake-arctic-embed-m-v1.5. Casting to VARIANT, wrapping the call in another function or using a bigger warehouse does not reconcile the dimensions. Embeddings are also stored values. When documents are added or edited, regenerate their vectors, or search results will drift from the current content.

    Adding a 768-dimension vector column and filling it with a 768-dimension modelsql
    ALTER TABLE issues ADD COLUMN issue_vec VECTOR(FLOAT, 768);
    
    UPDATE issues
      SET issue_vec = AI_EMBED('snowflake-arctic-embed-m', issue_text);

    Embeddings are useful beyond search: the same vectors can feed clustering and classification, the way any engineered numeric feature would (feature engineering). Embedding is billed on input tokens only.

    Checkpoint 1 of 7· Fill the gap

    The new column is declared as VECTOR(FLOAT, 768). Which embedding model fills the blank so the UPDATE writes vectors that fit the column?

    ALTER TABLE issues ADD COLUMN issue_vec VECTOR(FLOAT, 768);
    
    UPDATE issues
      SET issue_vec = AI_EMBED(' ? ', issue_text);

    Checkpoint 2 of 7· Exam question

    A global retailer keeps product reviews in English, German, Japanese and Portuguese in one column. A data scientist wants a single embedding model so that semantically similar reviews match across languages in a vector similarity search. Which approach is MOST appropriate?

    Checkpoint 3 of 7· Exam question

    A pipeline inserts embeddings into a table with the column emb VECTOR(FLOAT, 768) using the statement below, and the insert fails with a type error. INSERT INTO docs(id, emb) SELECT id, SNOWFLAKE.CORTEX.EMBED_TEXT_1024('snowflake-arctic-embed-l-v2.0', body) FROM raw_docs; Select TWO changes that resolve the failure.(Select 2)

    0 of 2 selected

    Sources1234

    A similarity search embeds the search term with the same model used for the stored vectors. It then scores every candidate row against that vector and keeps the top k with ORDER BY and LIMIT. Cortex provides four comparison functions, and they don't all point the same way.

    Vector comparison functions and how to sort them
    FunctionKindNearest rows first
    VECTOR_COSINE_SIMILARITYSimilarity: higher means more alignedORDER BY ... DESC
    VECTOR_INNER_PRODUCTSimilarity that also grows with vector magnitudeORDER BY ... DESC
    VECTOR_L2_DISTANCEDistance: smaller means closerORDER BY ... ASC
    VECTOR_L1_DISTANCEDistance: smaller means closerORDER BY ... ASC
    Finding the stored vector closest to [1,2,3] by cosine similarity, highest score firstsql
    SELECT a, VECTOR_COSINE_SIMILARITY(a, [1,2,3]::VECTOR(FLOAT, 3)) AS similarity
        FROM vectors
    ORDER BY similarity DESC
    LIMIT 1;

    Inner product is not a drop-in substitute for cosine. On the same table, [1,2.2,3] against [4,6,8] gives an inner product of 41.2, far above [1.1,2.2,3] against [1,1,1] at 6.3. Much of that gap comes from the longer vector, not from better alignment. Swapping cosine for inner product while keeping ASC is wrong twice over: inner product is not a distance either.

    Where the similarity call goes affects cost. Put it in the SELECT list with an alias, then use other WHERE conditions, such as "logged in the last 90 days", to cut the row set. That way the function runs only on rows that pass those conditions. A minimum-score threshold such as similarity > 0.7 then filters on the alias. The similarity functions carry no token charge; only creating the embeddings is billed.

    Checkpoint 4 of 7· Check yourself

    A help desk search must return up to five issues from the last 90 days that have a cosine similarity of at least 0.7 to the search term. The issues table holds millions of rows. Which query design keeps the similarity function from running on rows that don't need it?

    Checkpoint 5 of 7· Exam question

    An analyst runs the query below to find the five support articles most similar to a user question, but the results are the least relevant articles in the table. SELECT title FROM kb_articles ORDER BY VECTOR_COSINE_SIMILARITY(embedding, :query_vec) ASC LIMIT 5; What is the cause and the correct fix?

    Sources1

    3.Retrieval-augmented generation in SQL

    Retrieval-augmented generation (RAG) answers a question with an LLM after first retrieving relevant text from your own data. It chains the two previous steps into a completion. The corpus is embedded once and stored. Each incoming question is embedded with the same model. A cosine-similarity ranking picks the best chunk or chunks, and that text is concatenated into the prompt sent to AI_COMPLETE. The model then answers from material it was never trained on, which can make the response much more appropriate.

    Retrieve the most similar wiki row, then pass it to AI_COMPLETE as contextsql
    WITH result AS (
        SELECT
            w.content,
            $query AS query_text,
            VECTOR_COSINE_SIMILARITY(w.vec, q.query_vec) AS similarity
        FROM wiki w, query_table q
        ORDER BY similarity DESC
        LIMIT 1
    )
    
    -- Pass to large language model as context
    SELECT AI_COMPLETE('mistral-7b',
        CONCAT('Answer this question: ', query_text, ' using this text: ', content)) FROM result;

    Costs fall in three places. Embedding the corpus is billed once on input tokens, plus again whenever documents change. Each question is billed once for its own embedding. The completion is billed on input and output tokens, and the retrieved text is part of its input. So raising LIMIT from 1 to 5 chunks gives the model more context, but every extra chunk adds to the input tokens of every answer.

    Checkpoint 6 of 7· Put it in order

    Put these steps of a SQL-only RAG pipeline in order, from preparing the data to returning an answer to a user's question.

    1. 1.Embed the incoming question with the same embedding model used for the corpus
    2. 2.CONCAT the question and the retrieved text into a prompt and send it to AI_COMPLETE
    3. 3.Embed the document corpus with AI_EMBED and store the vectors in a VECTOR(FLOAT, n) column
    4. 4.Score the stored vectors against the question vector with VECTOR_COSINE_SIMILARITY, sort DESC and keep the top chunk with LIMIT

    Sources14

    4.Fine-tuning a base model with FINETUNE

    Fine-tuning is the next option when prompt engineering and RAG still miss on quality or latency, and training a model from scratch is too expensive. Cortex Fine-tuning uses parameter-efficient fine-tuning (PEFT). It trains a small customised adaptor on top of a pre-trained base model, using your own prompt and completion examples, and runs as a fully managed service inside Snowflake. llama3.1-8b is a base model you can fine-tune. It is suited to low-to-moderate reasoning, with a 24K context window split into 20k for the prompt and 4k for the completion.

    Training data comes from a query over a table or view. The result must have columns named exactly prompt and completion, or the job errors. Use AS aliases when the source columns are named differently. Any other columns are ignored, so select only these two. Start with a few hundred examples, because many more can drastically lengthen tuning for little gain. Keep each pair well within the context window, because pairs that exceed it are truncated and can hurt quality. A separate validation query is optional; held-out evaluation is covered in model validation.

    Creating a fine-tuning job, aliasing source columns to prompt and completionsql
    SELECT SNOWFLAKE.CORTEX.FINETUNE(
      'CREATE',
      'my_tuned_model',
      'llama3.1-8b',
      'SELECT a AS prompt, d AS completion FROM train',
      'SELECT a AS prompt, d AS completion FROM validation'
    );

    FINETUNE manages the job through its first argument:

    • 'CREATE' starts a job and returns its ID.
    • 'SHOW' lists every fine-tuning job in the account.
    • 'DESCRIBE' reports a job's progress, status and trained-token count.
    • 'CANCEL' stops a job, taking the job ID as its second argument.

    Jobs run for a long time and aren't tied to the worksheet session, so closing the worksheet doesn't stop them. You can also start a job from Snowsight under AI & ML » AI Studio.

    Permissions and cost each come in two parts. The creating role needs SNOWFLAKE.CORTEX_USER, USAGE on the database the data comes from, and CREATE MODEL (or OWNERSHIP) on the schema where the model is saved. Other roles can use the tuned model only after they are granted usage on it. Training is billed on trained tokens, where trained tokens = input tokens × epochs. The default is 3 epochs, which also caps the training data: 50k rows for llama3.1-8b, against 150k at one epoch. Once training finishes, the model name from Cortex Fine-tuning goes in the model argument of AI_COMPLETE, and each of those calls is billed on tokens processed. Storage for the adaptor and warehouse time for the SQL are billed on top.

    Checkpoint 7 of 7· Check yourself

    Your table support_pairs stores past tickets in the columns question, answer and ticket_id. You want to fine-tune llama3.1-8b so it answers questions the way your agents did. Which training-data query, passed to SNOWFLAKE.CORTEX.FINETUNE('CREATE', ...), will run without error?

    Sources5

    Practise it for real

    Build a semantic search over a support-issues table and use the best match as context for AI_COMPLETE.

    1. 1.Run ALTER TABLE issues ADD COLUMN issue_vec VECTOR(FLOAT, 768);

      Why: The column's dimension must match the 768-dimension model you will embed with.

      You should see: The issues table has a new, empty issue_vec column.

    2. 2.Run UPDATE issues SET issue_vec = AI_EMBED('snowflake-arctic-embed-m', issue_text);

      Why: Stores one embedding per issue so later searches only need to embed the query.

      You should see: Every row with issue_text now holds a 768-value vector; only input tokens are billed.

    3. 3.Select issue and VECTOR_COSINE_SIMILARITY(issue_vec, AI_EMBED('snowflake-arctic-embed-m', 'User could not install Facebook app on his phone')) AS similarity, then ORDER BY similarity DESC LIMIT 5.

      Why: The query is embedded with the same model, and DESC puts the highest similarity first.

      You should see: Five issues about app installation, with similarity values falling from the top row down.

    4. 4.Wrap the top-1 version of that query in a CTE that also selects the search text AS query_text, then call AI_COMPLETE('mistral-7b', CONCAT('Answer this question: ', query_text, ' using this text: ', issue)) on it.

      Why: This is the RAG step: the retrieved text becomes context for the completion.

      You should see: An answer that draws on the retrieved issue text rather than general knowledge.

    Stuck? Get a nudge

    If step 3 returns unrelated issues, check the sort direction before suspecting the model.

    Sources

    (5)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “it goes beyond keyword matching to semantic similarity”
      ↩︎ Embeddings and the VECTOR data type
      “Keep the embeddings up to date when documents are added or edited.”
      ↩︎ Embeddings and the VECTOR data type
      “Snowflake Cortex provides four vector similarity functions: VECTOR_INNER_PRODUCT, VECTOR_L1_distance, VECTOR_L2_DISTANCE, and VECTOR_COSINE_SIMILARITY.”
      ↩︎ Ranking with vector similarity functions
      “Generally, the call to the vector similarity function should appear in the SELECT clause, not in the WHERE clause.”
      ↩︎ Ranking with vector similarity functions
      “Vector similarity functions do not incur token-based costs.”
      ↩︎ Ranking with vector similarity functions
      “providing context for the generative response (completion). This can improve the appropriateness of the response significantly.”
      ↩︎ Retrieval-augmented generation in SQL
      “Use ORDER BY and LIMIT clauses to select the top k matching documents”
      ↩︎ Exam trap 1
      “ORDER BY similarity DESC”
      ↩︎ Prediction
      “a user’s query is used to find similar documents using vector similarity. The top document is then passed to a large language model (LLM)”
      ↩︎ Checkpoint
    2. 2.
      “AI_EMBED is the updated version of EMBED_TEXT_1024 and EMBED_TEXT_768.”
      ↩︎ Embeddings and the VECTOR data type
    3. 3.
      “The output dimension is set by the model, so match your VECTOR(FLOAT, n) column”
      ↩︎ Embeddings and the VECTOR data type
      “The output dimension is set by the model, so match your VECTOR(FLOAT, n) column”
      ↩︎ Exam trap 2
    4. 4.
      “For AI_SIMILARITY, AI_EMBED, and the SNOWFLAKE.CORTEX.EMBED_* functions, only input tokens are counted.”
      ↩︎ Embeddings and the VECTOR data type
      “both input and output tokens are billable.”
      ↩︎ Retrieval-augmented generation in SQL
    5. 5.
      “Cortex Fine-tuning allows users to leverage parameter-efficient fine-tuning (PEFT) to create customized adaptors for use with pre-trained models on more specialized tasks.”
      ↩︎ Fine-tuning a base model with FINETUNE
      “All columns other than the prompt and completion columns will be ignored by the FINETUNE function.”
      ↩︎ Fine-tuning a base model with FINETUNE
      “Start with a few hundred examples.”
      ↩︎ Fine-tuning a base model with FINETUNE
      “Fine-tuning jobs are often long running and are not attached to a worksheet session.”
      ↩︎ Fine-tuning a base model with FINETUNE
      “Fine-tuning trained tokens = number of input tokens * number of epochs trained”
      ↩︎ Fine-tuning a base model with FINETUNE
      “running the AI_COMPLETE function on a fine-tuned model incurs compute costs based on the number of tokens processed”
      ↩︎ Fine-tuning a base model with FINETUNE
      “To give other roles access to use the fine-tuned model, you must grant usage on the model.”
      ↩︎ Fine-tuning a base model with FINETUNE
      “the query result must contain columns named prompt and completion”
      ↩︎ Exam trap 3
      “You will get an error if the results do not contain prompt and completion column names.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise the 22 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.