Science - Cortex Analyst
In this tutorial we will go through an introduction to setting up cortex analyst. We'll show two ways to deploy it via streamlit in Snowflake and Flask.
Video
Video still in development.
Requirements
- Snowflake account, you can use a free trial. We also assume no complex security needs.
Download
- Sales Semantic Layer (Link)
Setup
Lets create some example data first the our chatbot (Cortex Analyst) can use later on.
If you don't have a database, schema or warehouse yet.
status |
---|
Table SALES successfully created. |
Lets now insert some data to those tables.
number of rows inserted |
---|
3 |
Building Cortex Analyst
Now that we have our data loaded into our tables lets build the semantic layer and play with it in the Cortex Analyst playground.
To start lets upload our example semantic layer to our stage. We can do that by clicking "+ Files".
Select the example semantic layer called sales.
Now that we have our example uploaded we can head to cortex analyst under the AI / ML Studio.
We'll select our semantic layer from our stage and click open.
Now that it's open we can immediately start playing with the semantic layer / chatbot.
We can see that the chatbot gives us example questions we can click and get results from. These examples are in the semantic layer.
We can also leave edit mode to show what it can potentially look like when we deploy the applicaiton.
You can see that our chatbot not only gives us the data in a table but also as a query. This can be changed in the future to remove the sql and or add a diagram / chart.
Edit Semantic Layer
In the playground we can also edit the semantic layer by using the GUI interface or by code. A great note here is that I found it helpful to use chatgpt to write my semantic layer code for me. I just provided it the table defenitions and it built the rest. Took me only 15 mins to get it to my liking with some great example quries.
Monitoring
You can monitor the usage of this semantic layer by going to the monitoring tab, this allows you to see how people are using your chatbot to help correct it without asking for feedback.
Deployment
Now that we have our cortex analyst chatbot built we'll want to deploy it. In this section we have two example platforms but you can deploy to many more.
Streamlit in Snowflake
Lets deploy our semantic layer / chatbot in streamlit in Snowflake.
Downloads
- Streamlit Application (Link)
Streamlit
To start lets create a new streamlit application in Snowflake.
Lets give our streamlit app a name, where to put it and finally the warehouse that will be used.
Note
If you put your semantic file somewhere else you'll just update it the string of the location.
Now that we have the app, lets copy in the code from the example application that we downloaded earlier and hit run.
Now you can see the chatbot and start using it and sharing it with any team who needs a sales chatbot.
Flask Website
Lets move to a build use case where we want to add our semantic layer into our application. In this example we'll build two additional semantic layers and then deploy them in our flask application. Make sure we download the necessary files for this section.
Downloads
Snowflake
Lets adding some new tables for our new semantic layers.
Lets add data to those tables.
Next lets upload the new semantic layers to our stage.
Flask
Lets walk throught the process of setting up the example files and starting our flask application. First we'll want to update our Snowflake account information in the app.py
file.
Next we'll want to start a python virtual environment and install the packages we need. This may be different on windows.
Now that we have everything for the application, lets run it.
Now we can go to the I.P address provided and see our flask application with multiple semantic models.