SnowPro Specialty: Gen AI Question 36
Single answerSQLA data engineering team is building a retrieval-augmented generation (RAG) pipeline in Snowflake. They store support articles in a table named KB_ARTICLES with columns ARTICLE_ID, TITLE, BODY, and EMBEDDING. EMBEDDING contains VECTOR values generated using the same embedding model for both the stored articles and incoming user questions. For each user question, the team wants to return the 5 most semantically similar articles using SQL only. Which query pattern is the most appropriate?
- A
SELECT ARTICLE_ID, TITLE FROM KB_ARTICLES ORDER BY VECTOR_COSINE_SIMILARITY(EMBEDDING, :QUESTION_EMBEDDING) DESC LIMIT 5;
- B
SELECT ARTICLE_ID, TITLE FROM KB_ARTICLES WHERE EMBEDDING = :QUESTION_EMBEDDING LIMIT 5;
- C
SELECT ARTICLE_ID, TITLE FROM KB_ARTICLES ORDER BY EDITDISTANCE(BODY, :QUESTION_TEXT) ASC LIMIT 5;
- D
SELECT ARTICLE_ID, TITLE FROM KB_ARTICLES GROUP BY ARTICLE_ID, TITLE HAVING MAX(EMBEDDING) = :QUESTION_EMBEDDING LIMIT 5;
Show answer and explanation
Correct answer: A
Explanation
For RAG in Snowflake, the practical SQL pattern is to store embeddings in a VECTOR column and rank candidate rows with a vector similarity function such as VECTOR_COSINE_SIMILARITY. The query then sorts descending by similarity and limits to the desired top-k results. This approach aligns with Snowflake documentation on VECTOR data and vector similarity functions used for semantic search workloads. The key implementation detail is that the compared embeddings must come from the same embedding model so they share the same vector space and dimensions. Exact equality, lexical string comparison, or aggregate logic are not valid substitutes for nearest-neighbor style retrieval in a GenAI pipeline.
- A. Correct.
Correct. In Snowflake, semantic retrieval over embeddings is typically performed by comparing VECTOR values with a similarity function such as VECTOR_COSINE_SIMILARITY and ordering results by the highest similarity score. Because both article embeddings and the question embedding were produced by the same model, cosine similarity is an appropriate SQL-based retrieval method for returning the top-k nearest matches.
- B. Incorrect.
Incorrect. Exact equality on VECTOR embeddings is not how semantic search works. Even semantically similar text will almost never produce identical embedding vectors, so using '=' would only find exact vector matches, not nearest neighbors. This reflects a common misconception that embeddings are looked up like keys rather than compared by distance or similarity.
- C. Incorrect.
Incorrect. EDITDISTANCE compares strings lexically, not semantically. It may be useful for typo correction or near-exact text matching, but it does not use the EMBEDDING column and is not appropriate for RAG retrieval based on semantic meaning. A candidate might choose this if they confuse text similarity with embedding similarity.
- D. Incorrect.
Incorrect. GROUP BY and HAVING with MAX(EMBEDDING) do not implement vector similarity search. VECTOR values are not retrieved by aggregating to find semantically nearest content. This option is a plausible SQL distractor because it looks analytical, but it does not solve the retrieval problem.