Build a Semantic Model for Snowflake Cortex Analyst with DataGalaxy

Build a Snowflake Cortex Analyst semantic model from DataGalaxy glossary, dictionary, and lineage data.

2 min read

Building a semantic model for Snowflake Cortex Analyst takes time, but DataGalaxy already holds most of the pieces: the Business Glossary carries the business definitions, the Dictionary carries the logical column details, and Lineage shows which physical tables feed each concept.

What is left is connecting those pieces and filling the gaps Cortex Analyst needs — synonyms, join definitions and verified queries. The sections below cover the YAML structure Cortex Analyst expects and the order in which to fill it.

For a worked example, see Build a Snowflake Cortex Analyst Semantic Model for Finance.

What is a semantic model?

A semantic model bridges business language and technical data structures. It holds descriptions, synonyms, joins and query metadata so that natural language questions can be answered with SQL.

For Snowflake Cortex Analyst, the semantic model is defined in a YAML specification optimized for SQL-based star schemas.

What does a Cortex Analyst semantic model contain?

ElementDescription
Logical tableA view over a physical table with defined columns such as dimensions, time dimensions and measures
Physical tableAn actual table in Snowflake
Logical columnMaps to a physical column or a derived field (for example, profit = revenue - cost)
Verified queriesPredefined SQL queries tied to natural language, for accuracy
FiltersReusable filters (for example, currency IN ('USD', 'EUR'))
JoinsSupports left_outer, inner and other SQL join types

What does the YAML file look like?

The template below shows every section a semantic model YAML file can hold.

name: <name>
description: <string>

# Define logical tables
tables:
  - name: <name>
    description: <string>
    base_table:
      database: <database>
      schema: <schema>
      table: <base table name>

    dimensions:
      - name: <name>
        synonyms: <array of strings>
        description: <string>
        expr: <SQL expression>
        data_type: <data type>
        unique: <boolean>

    time_dimensions:
      - name: <name>
        description: <string>
        expr: <SQL expression>
        data_type: <data type>

    measures:
      - name: <name>
        description: <string>
        expr: <SQL expression>
        default_aggregation: <aggregate function>
        data_type: <data type>
        sample_values: <list of samples>

relationships:
  - name: <string>
    left_table: <string>
    right_table: <string>
    relationship_columns:
      - left_column: <string>
        right_column: <string>
    join_type: <join_type>
    relationship_type: <relationship_type>

How do you build the semantic model?

  1. Create one model per Business Glossary universe, then extract its physical tables with Lineage and map the logical details from the Dictionary.
  1. Populate the logical tables from the Business Glossary, which supplies the dimensions, measures and descriptions, and derive the logical columns from the dictionary definitions.
  1. Define the joins. Use lineage to suggest join candidates, then set join_type (for example, left_outer or inner) and relationship_type (for example, many_to_one) by hand.
  1. Add verified SQL queries to improve query accuracy, and reusable filters that match your business needs.

Read more

Related articles

Was this page helpful?