Building AI-Powered Data Analytics with Snowflake Cortex

Building AI-Powered Data Analytics with Snowflake Cortex

使用 Snowflake Cortex 构建人工智能驱动的数据分析

Introduction 引言

Data analytics has evolved far beyond creating dashboards from spreadsheets and traditional databases. Organizations today generate massive amounts of structured and unstructured data, and they need to turn that data into insights quickly. At the same time, generative AI is changing how people interact with data. Instead of writing complex queries for every question, users increasingly expect to ask questions in natural language, summarize information automatically, and discover patterns that may not be immediately visible. 数据分析已经远远超越了从电子表格和传统数据库创建仪表板的范畴。如今,企业产生海量的结构化和非结构化数据,他们需要快速将这些数据转化为洞察。与此同时,生成式 AI 正在改变人们与数据交互的方式。用户不再满足于为每个问题编写复杂的查询,而是越来越期望通过自然语言提问、自动汇总信息,并发现那些原本难以察觉的模式。

This is where Snowflake and Snowflake Cortex can work together. Snowflake provides a modern cloud data platform for storing, processing, and analyzing data, while Cortex brings AI capabilities closer to enterprise data. This combination allows organizations to build analytics workflows where data can be prepared, analyzed, and enhanced with AI within the same platform. In this article, we’ll explore how to approach AI-powered analytics with Snowflake, using a simple sales analytics scenario as an example. 这就是 Snowflake 和 Snowflake Cortex 可以协同工作的地方。Snowflake 提供了一个现代化的云数据平台,用于存储、处理和分析数据,而 Cortex 则将 AI 能力带到了企业数据身边。这种结合使企业能够构建分析工作流,在同一个平台内完成数据的准备、分析和 AI 增强。在本文中,我们将以一个简单的销售分析场景为例,探讨如何利用 Snowflake 实现 AI 驱动的分析。

Why Combine Data Analytics and AI? 为什么要结合数据分析与 AI?

Traditional analytics generally follows a workflow like this: Data → SQL → Reports → Human Interpretation. For example, an analyst may have a sales table containing: Customer information, Product details, Order dates, Revenue, Region, Sales representative. The analyst can use SQL to calculate total revenue, identify the best-performing products, and compare regional performance. 传统的分析通常遵循这样的工作流:数据 → SQL → 报告 → 人工解读。例如,分析师可能拥有一个包含客户信息、产品详情、订单日期、收入、地区和销售代表的销售表。分析师可以使用 SQL 计算总收入、识别表现最好的产品,并比较区域业绩。

However, there are questions that require additional interpretation. For example: “Which products are performing poorly, and what are the likely reasons?” A SQL query can identify products with declining revenue, but understanding customer feedback or other unstructured information may require AI. An AI-powered analytics workflow can therefore look like: Data → SQL Analytics → AI Processing → Insights → Decisions. The important idea is that AI doesn’t replace analytics. Instead, AI can complement traditional analytical workflows. 然而,有些问题需要额外的解读。例如:“哪些产品表现不佳,可能的原因是什么?”SQL 查询可以识别收入下降的产品,但要理解客户反馈或其他非结构化信息,可能需要 AI。因此,AI 驱动的分析工作流可以是:数据 → SQL 分析 → AI 处理 → 洞察 → 决策。核心理念是:AI 并不会取代分析,相反,AI 可以补充传统的分析工作流。

Understanding Snowflake’s Role 了解 Snowflake 的角色

Snowflake provides the foundation for the analytics workflow. At a high level, a Snowflake environment can organize data using objects such as: Database → Schema → Tables → Views. For example: Snowflake 为分析工作流提供了基础。从宏观层面来看,Snowflake 环境可以使用以下对象来组织数据:数据库 → 模式 (Schema) → 表 → 视图。例如:

CREATE DATABASE SALES_ANALYTICS;
CREATE SCHEMA SALES_ANALYTICS.PUBLIC;

A sales table could contain columns such as: 销售表可以包含如下列:

CREATE TABLE SALES_ANALYTICS.PUBLIC.SALES (
    ORDER_ID INTEGER,
    CUSTOMER_NAME VARCHAR,
    PRODUCT_NAME VARCHAR,
    REGION VARCHAR,
    ORDER_DATE DATE,
    QUANTITY INTEGER,
    REVENUE NUMBER(12,2)
);

Once data is available in Snowflake, SQL can be used to perform analytical operations. For example, to calculate revenue by region: 一旦数据在 Snowflake 中就绪,就可以使用 SQL 执行分析操作。例如,按地区计算收入:

SELECT REGION, SUM(REVENUE) AS TOTAL_REVENUE 
FROM SALES_ANALYTICS.PUBLIC.SALES 
GROUP BY REGION 
ORDER BY TOTAL_REVENUE DESC;

This gives analysts a structured view of business performance. But we can take the workflow further by introducing AI. 这为分析师提供了业务绩效的结构化视图。但通过引入 AI,我们可以进一步提升工作流。

Introducing Snowflake Cortex 引入 Snowflake Cortex

Snowflake Cortex provides AI and machine learning capabilities that can be used with data stored in Snowflake. One of the interesting aspects of Cortex is that organizations can bring AI capabilities into their existing data workflows rather than necessarily moving data into a completely separate environment. Depending on the use case and available features, Cortex can support tasks such as: Text summarization, Text classification, Sentiment analysis, Natural-language processing, AI-powered applications, Machine learning workflows, Intelligent search and retrieval. Snowflake Cortex 提供了可用于 Snowflake 存储数据的 AI 和机器学习能力。Cortex 的一个有趣之处在于,企业可以将 AI 能力引入现有的数据工作流中,而不必非得将数据移动到完全独立的外部环境中。根据用例和可用功能,Cortex 可以支持以下任务:文本摘要、文本分类、情感分析、自然语言处理、AI 驱动的应用、机器学习工作流以及智能搜索与检索。

This opens up interesting possibilities for analytics teams. For example, imagine a company stores customer reviews alongside sales data. Traditional SQL can answer: “Which products generated the most revenue?” AI can help answer: “What are customers saying about those products?” Combining both creates a much richer analytical workflow. 这为分析团队开启了令人兴奋的可能性。例如,想象一家公司将客户评论与销售数据存储在一起。传统的 SQL 可以回答:“哪些产品产生的收入最高?”而 AI 可以帮助回答:“客户对这些产品有什么评价?”将两者结合起来,可以创造出更丰富的分析工作流。

Step 1: Preparing Analytical Data 第一步:准备分析数据

Let’s imagine our company sells electronic products. Our sales table contains transactional information: 假设我们的公司销售电子产品。我们的销售表包含交易信息:

SELECT PRODUCT_NAME, REGION, SUM(QUANTITY) AS UNITS_SOLD, SUM(REVENUE) AS REVENUE 
FROM SALES_ANALYTICS.PUBLIC.SALES 
GROUP BY PRODUCT_NAME, REGION;

We can use this information to identify high-performing and low-performing products. For example, we might discover that a particular product has high sales volume in one region but significantly lower performance in another. This immediately gives the analyst a starting point for investigation. 我们可以利用这些信息来识别表现优异和表现不佳的产品。例如,我们可能会发现某款产品在某个地区销量很高,但在另一个地区表现却明显较差。这立即为分析师提供了调查的切入点。

Step 2: Adding Unstructured Data 第二步:添加非结构化数据

Not all valuable business information is structured. Customer reviews, support tickets, survey responses, and product feedback are examples of unstructured or semi-structured information. Suppose we have a customer feedback table: 并非所有有价值的业务信息都是结构化的。客户评论、支持工单、调查问卷回复和产品反馈都是非结构化或半结构化信息的例子。假设我们有一个客户反馈表:

CREATE TABLE CUSTOMER_FEEDBACK (
    FEEDBACK_ID INTEGER,
    PRODUCT_NAME VARCHAR,
    CUSTOMER_REVIEW VARCHAR,
    CREATED_DATE DATE
);

A record might look conceptually like: 记录在概念上可能如下所示:

ProductCustomer Review
Laptop ABattery life is excellent but the keyboard feels uncomfortable.
Laptop AGreat performance, but the device gets hot during long usage.
Phone BCamera quality is excellent and the battery lasts all day.

A traditional SQL query can retrieve these reviews, but interpreting hundreds or thousands of reviews manually is inefficient. This is where AI-powered text analysis becomes useful. 传统的 SQL 查询可以检索这些评论,但手动解读成百上千条评论效率极低。这就是 AI 驱动的文本分析发挥作用的地方。

Step 3: Applying AI to Customer Feedback 第三步:将 AI 应用于客户反馈

Snowflake Cortex capabilities can be used to analyze text and generate useful information from unstructured data. For example, an organization could use AI to determine the sentiment of customer feedback. Conceptually, the workflow becomes: Snowflake Cortex 的功能可用于分析文本,并从非结构化数据中生成有用的信息。例如,企业可以使用 AI 来确定客户反馈的情感倾向。在概念上,工作流变为:

Customer Review → Snowflake Table → Cortex AI Analysis → Sentiment / Summary / Classification → Analytics → Business Decision 客户评论 → Snowflake 表 → Cortex AI 分析 → 情感/摘要/分类 → 分析 → 业务决策

A feedback dataset could therefore be enriched with AI-generated information such as: Sentiment, Topic, Summary, Category, Customer intent. Instead of looking at thousands of reviews individually, analysts can aggregate these AI-generated insights. For example: 因此,反馈数据集可以通过 AI 生成的信息进行丰富,例如:情感、主题、摘要、类别、客户意图。分析师无需逐一查看数千条评论,而是可以汇总这些 AI 生成的洞察。例如:

SELECT PRODUCT_NAME, SENT...