Week 151 - Cortex Agents

Challenge

Coach Frosty just inherited a basketball analytics database from a retiring stats guru. Problem is, the old-timer had a... unique naming convention. Every column is just C1, C2, C3, and so on. Renaming columns isn't an option -- half theleague's reporting tools depend on the current schema.

The front office needs answers -- fast -- and they don't want to learn SQL. They want to ask plain English questions like "Who scored the most total points?" and get instant answers.

Assignment

Your mission: use a Semantic View to give meaning to the cryptic columns, then wire up a Cortex Agent that the front office can query in natural language.

Setup Code

Column Mapping

Here's what the old stats guru's columns actually mean:

PLAYERS

┌────────┬──────────────────────────────┐

│ Column │ Meaning │

├────────┼──────────────────────────────┤

│ C1 │ player_id (primary key) │

├────────┼──────────────────────────────┤

│ C2 │ player_name │

├────────┼──────────────────────────────┤

│ C3 │ team │

├────────┼──────────────────────────────┤

│ C4 │ position (PG, SG, SF, PF, C) │

├────────┼──────────────────────────────┤

│ C5 │ jersey_number │

└────────┴──────────────────────────────┘

GAME_LOG

┌────────┬───────────────────────────────────────┐

│ Column │ Meaning │

├────────┼───────────────────────────────────────┤

│ C1 │ game_id (primary key) │

├────────┼───────────────────────────────────────┤

│ C2 │ player_id (foreign key to PLAYERS.C1) │

├────────┼───────────────────────────────────────┤

│ C3 │ game_date │

├────────┼───────────────────────────────────────┤

│ C4 │ opponent │

├────────┼───────────────────────────────────────┤

│ C5 │ minutes_played │

├────────┼───────────────────────────────────────┤

│ C6 │ points │

├────────┼───────────────────────────────────────┤

│ C7 │ rebounds │

├────────┼───────────────────────────────────────┤

│ C8 │ assists │

├────────┼───────────────────────────────────────┤

│ C9 │ steals │

├────────┼───────────────────────────────────────┤

│ C10 │ turnovers │

└────────┴───────────────────────────────────────┘

Your Objective

Step 1 -- Create a Semantic View

Create a Semantic View called SPORTS_ANALYTICS in FROSTY_DB.WEEK_151 that maps the cryptic column names to meaningful business concepts.

Your semantic view should include:

• Both tables with primary keys and a relationship joining them on player_id

• Dimensions: player name, team, position, game date, opponent, jersey number

• Facts: points, rebounds, assists, steals, turnovers, minutes played

• At least 3 Metrics with aggregations (e.g. total points, average points per game, total assists)

• Synonyms and comments on your dimensions and facts so the agent can understand the data

Step 2 -- Create a Cortex Agent

Create a Cortex Agent called HOOPS_AGENT in FROSTY_DB.WEEK_151 that uses your semantic view to answer basketball questions.

Your agent should have:

• A Cortex Analyst tool connected to your SPORTS_ANALYTICS semantic view

• A description that tells users what the agent is for


Step 3 -- Prove it works

Open your agent's chat interface and ask:

Who scored the most total points across all games?

Expected Output

The agent should answer: Luka Frostbite with 124 total points.

Hints

• Read the Snowflake docs on Semantic Views and Snowflake Intelligence

• If you get model availability errors, ask your ACCOUNTADMIN to run: ALTER ACCOUNT SET CORTEX_ENABLED_CROSS_REGION = 'ANY_REGION';

• Your synonyms and comments are what help the agent understand that C6 means "points", don't skip them

Previous
Previous

Week 152 - SQL & Query Techniques

Next
Next

week 150 - Cortex (AI / ML)