SnowPro Specialty: Gen AI Question 120
Single answerVector functionsA retail company stores product-description embeddings in a Snowflake table to power semantic search. The embeddings were generated by the same model and stored in a VECTOR column. During testing, analysts notice that some queries return poor matches because the SQL ranks results using the wrong similarity logic. The team wants a query pattern that correctly returns the top 10 most semantically similar products for a given query embedding while keeping the computation inside Snowflake. Which approach should they use?
- A
Use VECTOR_COSINE_SIMILARITY(product_embedding, query_embedding) in the SELECT list and ORDER BY the result DESC, then LIMIT 10.
- B
Use VECTOR_L2_DISTANCE(product_embedding, query_embedding) in the SELECT list and ORDER BY the result DESC, then LIMIT 10.
- C
Cast both vectors to ARRAY and compare them with ARRAY_INTERSECTION to find the most overlapping dimensions.
- D
Convert the VECTOR values to VARCHAR and use LIKE to find embeddings with similar prefixes.
Show answer and explanation
Correct answer: A
Explanation
Snowflake provides native vector data types and vector similarity/distance functions so semantic matching can be executed directly in SQL without exporting data to an external system. For a top-N semantic search use case, the key is choosing a function whose output aligns with the ORDER BY logic. VECTOR_COSINE_SIMILARITY returns larger values for more similar embeddings, so the correct retrieval pattern is to sort in descending order and take the top rows. By contrast, VECTOR_L2_DISTANCE and other distance-based metrics require ascending sort order because smaller distances mean closer matches. Snowflake documentation on vector data types and vector similarity functions emphasizes using native VECTOR functions for embedding comparisons rather than string or array-based workarounds. In practice, teams should ensure the query embedding and stored embeddings were produced by the same embedding model and have the same dimensionality before applying similarity search.
- A. Correct.
Correct. For semantic search, cosine similarity is a standard metric when comparing embeddings from the same model because it measures directional similarity between vectors. In Snowflake, VECTOR_COSINE_SIMILARITY returns a higher value for more similar vectors, so ordering DESC and applying LIMIT 10 is the appropriate pattern for retrieving the most relevant matches directly in SQL.
- B. Incorrect.
Incorrect. VECTOR_L2_DISTANCE is a valid vector function in Snowflake, but distance metrics work in the opposite direction from similarity metrics: smaller values indicate closer vectors. Ordering by L2 distance DESC would return the least similar items first. A candidate might choose this option because L2 distance is commonly used with embeddings, but the ordering logic here is wrong for the stated requirement.
- C. Incorrect.
Incorrect. Casting embeddings to ARRAY and using ARRAY_INTERSECTION does not perform semantic comparison. Embedding dimensions are continuous numeric values, not token sets where overlap is meaningful. This distractor reflects a common misconception that vector similarity can be approximated with generic semi-structured functions rather than dedicated vector functions.
- D. Incorrect.
Incorrect. VARCHAR prefix matching has no semantic meaning for vector embeddings. The string representation of an embedding is just a serialized form of numeric values, and lexical prefix similarity does not correspond to semantic closeness. This option is a plausible but fundamentally incorrect workaround that ignores how vector search works.