Setting up the App
1. Setting up the App
Imagine I'm a product manager working with a data engineering team that is tracking feature adoption metrics. Before we had built our own Text-to-SQL workflow, my team wasted hours writing requests for data. Then we waited for analysts to process those requests, and then we would spend time clarifying follow-ups when the results were incorrect. This happened even for simple questions like how many users use FeatureX this week. We'd go back and forth with this, and it delayed decision-making, and it frustrated everyone involved. To solve this problem, we shifted and created a semantic model that powered a Text-to-SQL workflow. This model bridged the natural language queries of the users and the database, allowing team members to type queries like show active users last week. And this allowed us to immediately get accurate results. This workflow not only removed bottlenecks, but it also empowered my team to explore data on their own and make faster and more agile decisions. Everyone loved this. Pause the video here if you need a moment to log into your Snowflake trial account. Once you're logged in, go to Projects and select Notebooks. And then select the downward-facing caret on the right of the blue plus Notebook button in the top right of the screen, and select Import iPy Notebook File. Select the file, and then in the next window, choose a name, warehouse, and Python environment. Remember, this Notebook is owned by my user, as you can see at the top. And the Notebook will be stored in a personal database and schema, specially for Notebooks. Now click Create. Once we've opened the Notebook, we just need to install two libraries. We need Snowflake ML Python, and we need the Tabulate library. Let's do that now. In this cell, we choose the warehouse we want to use. We switch to the Security Admin role, and then create the Cortex user role, and assign the database role of Cortex user to this role. Once you've done that, we use Security Admin again to grant Cortex user role to the user, you. Notice that you need to change the user at the end of the grant role in line 10 to your own Snowflake username. This is the name that you'll be using to log into your Snowflake trial account. If you're not sure what your username is, an easy way to get this is to run the Show Users command in a separate cell above to see your name in the Name column. You can also see your username by clicking on the user circle with your initials in the bottom left of the Snowflake UI window. Enter your username in place of the carets and execute the cell. Before we run the next cell, let's take a look at what we're doing in it. We're going to set the role back to Account Admin, we're going to set the role back to Account Admin to get the permissions that we need for this part. From there, we'll create the Database Cortex Analyst Demo and the Schema Revenue Time Series. We're also going to create a new warehouse, Cortex Analyst Warehouse for us to use. Then we grant usage on the warehouse and operation on the warehouse to Cortex user role. We grant ownership of the schema and database to Cortex user role and then set the role to be used. We set the use commands for warehouse, database, and schema and then move on to creating the stage that we'll use to store our files. We start by creating the table Daily Revenue in the Revenue Time Series schema with the columns Date, Revenue, COGS, Forecast Revenue, Product ID, and Region ID. Then we move on to create the Product Dimensions table. For this table, we only need two columns, Product ID and Product Line, which is a bar chart. And we finish off creating the second dimension table we need, Region. This table has an ID, sales region, and state column. You can run the Show Tables command in a separate cell to check that everything is there. Looks good. We have our stage created, the warehouse we're going to use built, and the tables that we need in the database ready to have data loaded into them. Nice work. Dealing with the ambiguity of natural language is the challenge that Text to SQL overcomes. Users deal in natural language that does not map into database language precisely. And this is what makes the generation so difficult. Recent improvements in generation have come from the semantic models that we create for the LLM to use. Semantic models assist the generation of SQL in a much more efficient way than previous methods. And now that we have everything set up, you'll see how to build your own semantic model. Well done. You've built the foundational blocks, and now we can move on. I'll see you in the next video.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.