Get startedGet started for free

Creating Your Semantic View

1. Creating Your Semantic View

Our agents need to query structured data, but they don't understand your business. They don't know what win rate means or how to calculate it. That's where semantic views come in. A semantic view is a business context layer that maps your business terms to database tables. Let's build one and see how it works. I'm in Snowflake. I'm going to go ahead and click on AI and ML, then Cortex Analyst. This is where we're going to build a semantic view. I'm going to go ahead and create the view on top right, create semantic view. First, we need to choose where to store the semantic view. We're going to select the sales intelligence database, then the data schema. I'll name this sales metrics view. For description, I'll write semantic view for B2B sales metrics and deal analysis. This next screen lets us provide context. You can add example SQL queries here if you have them, but we will just skip through for now. The important part is selecting our data source. Under select tables, click Add table and navigate to sales, underscore intelligence, then data, and select the sales metrics. This is our structured sales data. Click Next. Now, we select which columns to include. You can select individual columns or select the entire table to include everything. For our sales intelligence agent, we want all the details, so select all the columns. Below this column selection, you'll see two checkboxes. The first asks you if you want to add sample values from each column. I recommend checking this box because sample values help Cortex analysts understand your data better and provide more accurate results. The second checkbox asks if you want AI-generated descriptions for the tables and columns. Check this box as well. The AI will analyze your column names and sample values to generate helpful descriptions automatically. Click Create and Save. Snowflake will now generate your semantic view. You will see a progress indicator showing what the generator is doing. This process takes a minute or two, so let's let it complete. Before we dive deeper, let me explain the two main concepts of this semantic view. Dimensions and measures. Dimensions are the by what in your questions, product line, sales rep, customer names. These are categories you slice your data by. Measures are the show me calculations. Deal value, win rate, total deals. These are the numbers you want to see. The AI system generator did much of the work for us. It analyzed our table and created initial dimensions and measures. We need to review and enhance what it created. Click on the Semantic Information tab to see what it generated. You will see a logical table called Sales Metrics. Click the little menu icon next to it, then Edit Logical Table. Here, you can see the description that AI generated. If any fields are empty, you can click Generate Fields to have the AI fill them in. Now, let us look at the dimensions. The AI should have identified columns like customer name, sales stage, and product lines as dimensions. If it missed any, we can add them. Here is where we add real power, synonyms. Click on the customer's name to edit it. Let's click Generate Fields. There, it added synonyms. It added a client name, customer account, and more. This means when someone says any of these terms, the model knows what they mean. Click Save. Let's add synonyms to more dimensions. Click on Sales Stage. Let's click Generate Fields. Again, it added the synonyms. For me, it added deal stage, opportunity stage, pipeline stage, and more. Click Save. Next, we'll do Sales Rep. Here, we're going to generate fields again. Then it added sales representative, account managers, sales agents, and et cetera. These are the common terms sales teams use. Let's go ahead and click Save. Lastly, let's do product line. Again, generate fields, save. Let's look at measures. The AI should have identified deal value as a measure with some aggregation. But we need to add some custom measures that requires formulas. Click the plus sign next to the metrics to add a new measure. We're going to name it win rate. For the expression, type sum of case when win underscore status equals true, then one else end, divided by count of asterisk. This calculates one deals divided by the total deals. Click Add. That formula now lives in the semantic view. Anyone can ask, what is our win rate? An agent uses this exact calculation. They do not need to know SQL. Let us add two more measures. Click the plus sign again. Name this one average underscore deal, underscore size. For the expression, use average of deal underscore value. Click Add. One more. This one will name total underscore deals. For the expression, use count of asterisk. Click Add. Now, click Save on the top right to save all the changes. Let us test it. Click the Playground tab on the top right. This opens a test interface where we can ask questions in natural language. Type, what is our win rate by product line? Watch the SQL it generates. You can see it created a select statement with our product line dimension and the win rate calculation that we defined. The results show with our premium security package, our win rate is 67 percent. For enterprise suite, again, another 67 percent. Our Analytics Pro is 50 percent. For the basic package, it's 50 percent. This is the insight our sales leaders need, generated automatically from natural language. Let's try another one. Type, show me average deal size by sales rep. It generates the correct SQL with the average aggregation and group by class. The results show each rep and their average deal size. Your semantic view is now ready for agent use. You mapped business terms to tables, defined complex calculations, and added synonyms for natural language flexibility. Let's recap what you've just built. You mapped business terms to database tables, so agents can understand questions in natural language. You defined five dimensions that let users slice by customer, product, sales rep, stage, and date. You created three measures, including the win rate calculations that would normally require complex SQL. And you added synonyms so people can ask questions using their own terminology. This semantic view is now the bridge between natural language and your structured data. In the next video, we'll build the search service for unstructured conversation data.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.