AI Model Wiki

    Skip to main content
    18 min
    Lesson 2 of 4

    Building AI Pipelines with Cortex

    From the course Snowflake Cortex AI

    Cortex AI enables you to build complete AI data pipelines that process, analyze, and enrich your data at scale.

    Text Processing at Scale

    Batch Sentiment Analysis

    CREATE TABLE enriched_reviews AS
    SELECT
      review_id,
      review_text,
      SNOWFLAKE.CORTEX.SENTIMENT(review_text) as sentiment_score,
      SNOWFLAKE.CORTEX.CLASSIFY_TEXT(
        review_text,
        ['product quality', 'shipping', 'customer service', 'pricing']
      ):label::STRING as category
    FROM raw_reviews;
    

    Document Summarization Pipeline

    1. Ingest documents into a Snowflake stage
    2. Parse with Cortex Document AI
    3. Summarize each document with CORTEX.COMPLETE
    4. Store summaries in a structured table
    5. Create a Cortex Search index for retrieval

    Building RAG Applications

    Step 1: Create a Search Service

    CREATE CORTEX SEARCH SERVICE knowledge_base
      ON documents_table
      WAREHOUSE = 'AI_WH'
      TARGET_LAG = '1 hour'
    AS (
      SELECT
        doc_id,
        content,
        metadata
      FROM documents_table
    );
    

    Step 2: Query with Context

    SELECT SNOWFLAKE.CORTEX.COMPLETE(
      'mistral-large',
      CONCAT(
        'Based on the following context, answer the question.\n\n',
        'Context: ', search_results.content, '\n\n',
        'Question: What is our return policy?'
      )
    ) as answer
    FROM TABLE(knowledge_base!SEARCH('return policy', 3)) as search_results;
    

    ML Functions

    Beyond LLMs, Cortex provides ML capabilities:

    • Forecasting: Time series predictions
    • Anomaly Detection: Identify unusual patterns
    • Classification: Supervised ML models
    • Contribution Explorer: Understand what drives metric changes

    Forecasting Example

    SELECT *
    FROM TABLE(SNOWFLAKE.ML.FORECAST(
      INPUT_DATA => TABLE(SELECT date, revenue FROM daily_sales),
      TIMESTAMP_COLNAME => 'date',
      TARGET_COLNAME => 'revenue',
      FORECASTING_PERIODS => 30
    ));
    

    Key Takeaways

    • •Process text at scale with SQL-native sentiment, classification, and summarization
    • •Build RAG applications using Cortex Search for semantic retrieval
    • •ML functions provide forecasting, anomaly detection, and classification
    • •All AI processing runs within Snowflake's governed compute infrastructure
    0 of 4 lessons marked complete

    Progress is kept in this browser only.