In this Quickstart guide, you will be help the fictitious food truck company, Tasty Bytes, to identify where their customer experience may be falling short at the truck and business level by leveraging Snowflake Cortex. The company gathers customer reviews across multiple sources and languages to assess their food truck operations. This comprehensive feedback helps them identify areas for improvement, ultimately boosting customer satisfaction and loyalty. Leveraging Snowflake Cortex's advanced language AI capabilities, they can automatically process reviews through real-time translation, generate actionable insights through intelligent summarization, and analyze customer sentiment at scale – transforming diverse, unstructured feedback into strategic business decisions that drive their food truck operations forward.
You will need the following things before beginning:
In this quickstart, you will learn:
You will use Snowsight, the Snowflake web interface, to:
You will use Snowsight, the Snowflake web interface, to create Snowflake notebook by importing notebook.
tb_voc
, schema analytics
and warehouse tasty_ds_wh
You will leverage Translate - one of the Snowflake Cortex specialized LLM functions are available in Snowpark ML:
This is done within the notebook using following code snippet in cell CORTEX_TRANSLATE
.
# Conditionally translate reviews that are not english using Cortex Translate
reviews_df = reviews_df.withColumn('TRANSLATED_REVIEW',when(F.col('LANGUAGE') != F.lit("en"), \
cortex.translate(F.col('REVIEW'), \
F.col('LANGUAGE'), \
"en")) \
.otherwise(F.col('REVIEW')))
reviews_df.filter(F.col('LANGUAGE') != F.lit("en")).select(["REVIEW","LANGUAGE","TRANSLATED_REVIEW"]).show(3)
-- Add the TRANSLATED_REVIEW column with conditional translation
WITH TRANSLATED_REVIEWS AS (
SELECT
REVIEW,
LANGUAGE,
CASE
WHEN LANGUAGE != 'en' THEN SNOWFLAKE.CORTEX.TRANSLATE(REVIEW, LANGUAGE, 'en')
ELSE REVIEW
END AS TRANSLATED_REVIEW
FROM TRUCK_REVIEWS_V
)
-- Filter rows where the LANGUAGE is not English and select the desired columns
SELECT
REVIEW,
LANGUAGE,
TRANSLATED_REVIEW
FROM TRANSLATED_REVIEWS
WHERE LANGUAGE != 'en'
LIMIT 3;
In this section, you will leverage Snowflake Cortex LLM - AI_SUMMARIZE_AGG to quickly understand what the customers are saying:
summarized_reviews_df = session.table("TRUCK_REVIEWS_V") \
.group_by("TRUCK_BRAND_NAME") \
.agg(ai_summarize_agg(F.col("REVIEW")).alias("SUMMARY"))
summarized_reviews_df.select(["TRUCK_BRAND_NAME", "SUMMARY"]).show(3)
WITH SUMMARIZED_REVIEWS AS (
SELECT
TRUCK_BRAND_NAME,
AI_SUMMARIZE_AGG(REVIEW) AS SUMMARY
FROM TRUCK_REVIEWS_V
GROUP BY TRUCK_BRAND_NAME
)
SELECT * FROM SUMMARIZED_REVIEWS;
In this section, you will make use of Snowflake Cortex LLM - AI_CLASSIFY to categories reviews to understand:
# To understand whether a customer would recommend food truck based on their review
reviews_df = reviews_df.withColumn('RECOMMEND', ai_classify(prompt("Tell me based on the following food truck customer review {0}, will they recommend the food truck to their friends and family?", F.col('REVIEW')),["Likely","Unlikely","Unsure"])["labels"][0])
reviews_df.select(["REVIEW","CLEAN_RECOMMEND"]).show(3)
WITH CLASSIFIED_REVIEWS AS (
SELECT
REVIEW,
AI_CLASSIFY(
REVIEW,
['Likely', 'Unlikely', 'Unsure'],
OBJECT_CONSTRUCT('task_description',
'Tell me based on the following food truck customer review, will they recommend the food truck to their friends and family?'
)
):labels[0]::TEXT AS RECOMMEND
FROM TRUCK_REVIEWS_V
)
SELECT * FROM CLASSIFIED_REVIEWS LIMIT 3;
In this section, you will leverage Snowflake Cortex LLM - AI_COMPLETE to get answers to your specific questions:
question = "What is the number one dish positively mentioned in the feedback?"
summarized_reviews_df = session.table("CONCATENATED_REVIEWS").select(
F.col("TRUCK_BRAND_NAME"),
ai_complete(
"openai-gpt-4.1",
F.concat(
F.lit("Context: "),
F.col("ALL_REVIEWS_TEXT"),
F.lit(f" Question: {question} Answer briefly and concisely and only name the dish:")
)
).alias("NUMBER_ONE_DISH")
)
summarized_reviews_df.show(3)
-- Gain Learnings from a specific question
WITH GAIN_LEARNINGS AS (
SELECT
TRUCK_BRAND_NAME,
AI_COMPLETE(
'openai-gpt-4.1',
'Context:' || ALL_REVIEWS_TEXT || ' Question: What is the number one dish positively mentioned in the feedback? Answer briefly and concisely and only name the dish:'
) AS NUMBER_ONE_DISH
FROM CONCATENATED_REVIEWS
)
SELECT TRUCK_BRAND_NAME, NUMBER_ONE_DISH FROM GAIN_LEARNINGS LIMIT 3;
In this section, you will leverage Snowflake Cortex LLM - AI_COMPLETE to for analyzing images
SELECT
AI_COMPLETE (
'claude-3-5-sonnet',
'Please describe what you see in this image.',
TO_FILE ('@TB_VOC.MEDIA.IMAGES', IMAGE_PATH)
) AS IMAGE_DESCRIPTION
FROM
TB_VOC.MEDIA.IMAGE_TABLE
LIMIT
1;
In this section, you will leverage Snowflake Cortex LLM - AI_TRANSCRIBE to for transcription
SELECT
AI_TRANSCRIBE (
TO_FILE ('@TB_VOC.MEDIA.AUDIO', AUDIO_PATH)
) AS TRANSCRIPTION_RESULT
FROM
TB_VOC.MEDIA.AUDIO_TABLE
LIMIT
1;
Next, you will look at another task specific LLM function in Cortex - Sentiment/AI_SENTIMENT.
CORTEX_SENTIMENT
.# Understand the sentiment of customer review using Cortex Sentiment
reviews_df = reviews_df.withColumn('SENTIMENT', cortex.sentiment(F.col('REVIEW')))
reviews_df.select(["REVIEW","SENTIMENT"]).show(3)
SELECT
REVIEW,
AI_SENTIMENT(REVIEW) AS SENTIMENT
FROM TRUCK_REVIEWS_V
LIMIT 3;
Congratulations! You've mastered powerful customer analytics using Snowflake Cortex, processing multilingual reviews and extracting valuable insights – all while maintaining data security within Snowflake's ecosystem. By leveraging these built-in AI capabilities, you've eliminated the complexity of managing external infrastructure while keeping sensitive customer feedback protected within Snowflake's secure environment.
With the completion of this quickstart, you have now:
Want to learn more about the tools and technologies used in this quickstart? Check out the following resources: