Chat with your data in Azure SQL Database

Muazma Zahid

Welcome to the exploration of how to chat with your data in Azure SQL Database. Being able to interact with your data more intuitively and conversationally can significantly enhance your data analysis and decision-making processes. This blog post will guide you through the process of setting up a chat interface for your Azure SQL Database, using an eCommerce database as an example. Whether you’re a data scientist, a developer, or just a curious learner, this guide will provide you with a new perspective on interacting with your data.

The first step is to create an Azure AI search resource, Learn more here.

Data Source

Our journey begins with our data source from Kaggle’s product dataset. This dataset has product names, descriptions, categories, prices, and more. It’s the perfect playground for a chat interface, allowing users to ask about products, compare prices, and even get recommendations for products for an occasion or scenario. This data is loaded into the Azure SQL Database. In an e-commerce website, this database can be a sales and product catalog.

Image Data preview 2

Connect Azure SQL Database

To start chatting with our data, we first need to establish a connection to our Azure SQL Database. This is done by setting up a connection string, and a query. Once the connection string is set up, we can use it to establish a connection to the database. To learn more about how to connect Azure SQL Database to Azure Search using Indexers, read here.

Add search fields to an Index

In a search index, add fields that correspond to the fields in the SQL database. Ensure that the search index schema is compatible with the source schema by using equivalent data types. It will look like this:

Image AI Search Index 1

Create Indexer

Now that we have our index, we need an indexer to populate it. In Azure Search, an indexer is a crawler that automatically goes through our data source and populates our index. Once the indexer is up and running, our index will always be up-to-date with the latest data.

Indexing new, changed, and deleted rows

If your SQL database supports change tracking, a search indexer can pick up just the new and updated content on subsequent indexer runs.

To enable incremental indexing, set the “dataChangeDetectionPolicy” property in your data source definition. This property tells the indexer which change tracking mechanism is used on your table or view.

For Azure SQL indexers, there are two change detection policies:

  • “SqlIntegratedChangeTrackingPolicy” (applies to tables only)
  • “HighWaterMarkChangeDetectionPolicy” (works for tables and views)

Chat playground (Preview)

With our index populated, it’s time to start chatting! After ingesting your data, you can start chatting with the model on your data using the chat playground in Azure OpenAI studio, or the following methods:

Web app | REST API | C# | Java | JavaScript | PowerShell | Python

Go to Azure AI studio, select Build from the top menu and then select Deployments > Create. In the playground, make sure that Chat is selected from the Mode dropdown. Select your deployed GPT chat model from the Deployment dropdown. Detailed steps are listed here.

Screenshot of the chat playground with the chat mode and model selected.

On the Assistant setup pane, select Add your data (preview) > + Add a data source. Choose the AI Search Index created above. You are ready to chat with your data.

In our chat playground, we can ask our database questions, like “What are some good products for a kid’s birthday?” or “What’s the best product for living room decor?” The chat interface will query the database and return the results in a user-friendly format, making data exploration as easy as having a conversation.

Image Chat playground Azure OpenAI Studio

Learning and optimizing

As we chat with our data, we’ll start to see patterns and gain insights. We can use these insights to optimize our data and our chatbot. Maybe we need to add more data to our database, or maybe we need to refine our index to make our searches more efficient. Or perhaps our chatbot needs to better understand user queries. Whatever the case may be, there’s always room for learning and optimizing.

Connect with Web App

Finally, we’ll want to connect our chat interface with a web application. Detailed steps are listed here. Once that’s done, users will be able to chat with our data right from our web app, making data exploration more accessible than ever before.

And there you have it – a chat interface for your Azure SQL Database! With this setup, you can make your data more accessible and interactive, opening up new possibilities for data exploration.

Clean up Resources

To avoid incurring unnecessary Azure costs, you should delete the resources you created in this quickstart if they’re no longer needed. To manage resources, you can use the Azure portal

Key Learnings

  1. Ease of Interaction: A chat interface allows for a more intuitive interaction with your data, making data analysis more accessible to non-technical users.
  2. Real-time Insights: Understanding data changes and frequency to keep your chat up to date is a balance between accuracy and optimization.
  3. Continuous Learning and Optimization: The more you interact with your data, the more insights you gain. These insights can be used to continuously optimize your data and chatbot.
  4. Integration with Web Apps: A chat interface can be integrated with web applications, making your data accessible from anywhere.

Remember, the journey of data exploration is endless, and there’s always something new to learn. So keep chatting, keep exploring, and keep learning. Happy chatting!

 

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • Jay Warshaw 1

    Muazma, thanks for a great a post. I’m trying to go to the next level and build a SQL database Analyst bot, similar to OpenAI Data Analyst GPT. In the Azure AI Studio Assistant playground, there are no data connections to SQL. Any advice/tips how to achieve this?

    • Muazma ZahidMicrosoft employee 1

      Thanks Jay for the feedback and question. Currently you can use AI search indexer on SQL data for that scenario in Azure AI Studio. We are working on native SQL connector to be released in the coming months, so depending on timing you can decide (wait or use the AI search SQL indexer as source).

Feedback usabilla icon