{"id":2787,"date":"2024-02-06T08:00:00","date_gmt":"2024-02-06T16:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=2787"},"modified":"2024-02-06T08:00:00","modified_gmt":"2024-02-06T16:00:00","slug":"chat-with-your-data-azure-sql-database","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/chat-with-your-data-azure-sql-database\/","title":{"rendered":"Chat with your data in Azure SQL Database"},"content":{"rendered":"<p>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\u2019re a data scientist, a developer, or just a curious learner, this guide will provide you with a new perspective on interacting with your data.<\/p>\n<h2>Create Azure AI Search<\/h2>\n<p>The first step is to create an Azure AI search resource, Learn more <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/search\/search-create-service-portal\">here<\/a>.<\/p>\n<h2>Data Source<\/h2>\n<p>Our journey begins with our data source from Kaggle\u2019s <a href=\"https:\/\/www.kaggle.com\/datasets\/mauridb\/product-data-from-walmart-usa-with-embeddings\">product dataset<\/a>. This dataset has product names, descriptions, categories, prices, and more. It\u2019s 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.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Data-preview-2.png\"><img decoding=\"async\" class=\"alignnone wp-image-2806\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Data-preview-2-300x64.png\" alt=\"Image Data preview 2\" width=\"469\" height=\"100\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Data-preview-2-300x64.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Data-preview-2-1024x218.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Data-preview-2-768x164.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Data-preview-2-1536x327.png 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Data-preview-2.png 1821w\" sizes=\"(max-width: 469px) 100vw, 469px\" \/><\/a><\/p>\n<h2>Connect Azure SQL Database<\/h2>\n<p>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 <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/search\/search-howto-connecting-azure-sql-database-to-azure-search-using-indexers\">here<\/a>.<\/p>\n<h2>Add search fields to an Index<\/h2>\n<p>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:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/AI-Search-Index-1.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-2804\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/AI-Search-Index-1-300x238.png\" alt=\"Image AI Search Index 1\" width=\"300\" height=\"238\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/AI-Search-Index-1-300x238.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/AI-Search-Index-1-1024x812.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/AI-Search-Index-1-768x609.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/AI-Search-Index-1.png 1102w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Create Indexer<\/h2>\n<p>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.<\/p>\n<div class=\"heading-wrapper\" data-heading-level=\"h2\">\n<h2 id=\"indexing-new-changed-and-deleted-rows\" class=\"heading-anchor\">Indexing new, changed, and deleted rows<\/h2>\n<\/div>\n<p>If your SQL database supports\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/track-changes\/about-change-tracking-sql-server\" data-linktype=\"absolute-path\">change tracking<\/a>, a search indexer can pick up just the new and updated content on subsequent indexer runs.<\/p>\n<p>To enable incremental indexing, set the &#8220;dataChangeDetectionPolicy&#8221; property in your data source definition. This property tells the indexer which change tracking mechanism is used on your table or view.<\/p>\n<p>For Azure SQL indexers, there are two change detection policies:<\/p>\n<ul>\n<li>&#8220;SqlIntegratedChangeTrackingPolicy&#8221; (applies to tables only)<\/li>\n<li>&#8220;HighWaterMarkChangeDetectionPolicy&#8221; (works for tables and views)<\/li>\n<\/ul>\n<h2>Chat playground (Preview)<\/h2>\n<p>With our index populated, it\u2019s time to start chatting!\u00a0After 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:<\/p>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/ai-services\/openai\/concepts\/use-your-data?tabs=ai-search#using-the-web-app\">Web app<\/a> | <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/ai-services\/openai\/reference#azure-ai-search\">REST API<\/a> | <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-net\/blob\/main\/sdk\/openai\/Azure.AI.OpenAI\/tests\/Samples\/AzureOnYourData.cs\">C#<\/a> | <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-java\/blob\/main\/sdk\/openai\/azure-ai-openai\/src\/samples\/java\/com\/azure\/ai\/openai\/ChatCompletionsWithYourData.java\">Java<\/a> | <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/blob\/main\/sdk\/openai\/openai\/samples\/v1-beta\/javascript\/bringYourOwnData.js\">JavaScript<\/a> | <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/ai-services\/openai\/use-your-data-quickstart?tabs=command-line,powershell&amp;pivots=programming-language-powershell#example-powershell-commands\">PowerShell<\/a> | <a href=\"https:\/\/github.com\/openai\/openai-cookbook\/blob\/main\/examples\/azure\/chat_with_your_own_data.ipynb\">Python<\/a><\/p>\n<p>Go to Azure AI studio, select\u00a0<strong>Build<\/strong>\u00a0from the top menu and then select\u00a0<strong>Deployments<\/strong>\u00a0&gt;\u00a0<strong>Create<\/strong>. In the playground, make sure that\u00a0<strong>Chat<\/strong>\u00a0is selected from the\u00a0<strong>Mode<\/strong>\u00a0dropdown. Select your deployed GPT chat model from the\u00a0<strong>Deployment<\/strong> dropdown. Detailed steps are listed <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/ai-studio\/tutorials\/deploy-chat-web-app\">here<\/a>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/learn.microsoft.com\/en-us\/azure\/ai-studio\/media\/tutorials\/chat-web-app\/playground-chat.png\" alt=\"Screenshot of the chat playground with the chat mode and model selected.\" \/><\/p>\n<p>On the\u00a0<strong>Assistant setup<\/strong>\u00a0pane, select\u00a0<strong>Add your data (preview)<\/strong>\u00a0&gt;\u00a0<strong>+ Add a data source<\/strong>. Choose the AI Search Index created above. You are ready to chat with your data.<\/p>\n<p>In our chat playground, we can ask our database questions, like <em><strong>\u201cWhat are some good products for a kid\u2019s birthday?\u201d<\/strong><\/em> or <em><strong>\u201cWhat\u2019s the best product for living room decor?\u201d<\/strong><\/em> 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.<\/p>\n<h2><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Chat-playground-_-Azure-OpenAI-Studio.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-2793\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/02\/Chat-playground-_-Azure-OpenAI-Studio.gif\" alt=\"Image Chat playground Azure OpenAI Studio\" width=\"2560\" height=\"1392\" \/><\/a><\/h2>\n<h2>Learning and optimizing<\/h2>\n<p>As we chat with our data, we\u2019ll 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\u2019s always room for learning and optimizing.<\/p>\n<h2>Connect with Web App<\/h2>\n<p>Finally, we\u2019ll want to connect our chat interface with a web application. Detailed steps are listed <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/ai-studio\/tutorials\/deploy-chat-web-app\">here<\/a>. Once that\u2019s done, users will be able to chat with our data right from our web app, making data exploration more accessible than ever before.<\/p>\n<p>And there you have it &#8211; 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.<\/p>\n<div class=\"heading-wrapper\" data-heading-level=\"h2\">\n<h2 id=\"clean-up-resources\" class=\"heading-anchor\">Clean up Resources<\/h2>\n<\/div>\n<p>To avoid incurring unnecessary Azure costs, you should delete the resources you created in this quickstart if they&#8217;re no longer needed. To manage resources, you can use the <a href=\"https:\/\/portal.azure.com\/?azure-portal=true\">Azure portal<\/a><\/p>\n<h2>Key Learnings<\/h2>\n<ol>\n<li><strong>Ease of Interaction<\/strong>: A chat interface allows for a more intuitive interaction with your data, making data analysis more accessible to non-technical users.<\/li>\n<li><strong>Real-time Insights<\/strong>: Understanding data changes and frequency to keep your chat up to date is a balance between accuracy and optimization.<\/li>\n<li><strong>Continuous Learning and Optimization<\/strong>: The more you interact with your data, the more insights you gain. These insights can be used to continuously optimize your data and chatbot.<\/li>\n<li><strong>Integration with Web Apps<\/strong>: A chat interface can be integrated with web applications, making your data accessible from anywhere.<\/li>\n<\/ol>\n<p>Remember, the journey of data exploration is endless, and there\u2019s always something new to learn. So keep chatting, keep exploring, and keep learning. Happy chatting!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, [&hellip;]<\/p>\n","protected":false},"author":99201,"featured_media":2817,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[590,588,561],"class_list":["post-2787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-sql","tag-ai","tag-azure-sql-db","tag-openai"],"acf":[],"blog_post_summary":"<p>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, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/2787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/users\/99201"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=2787"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/2787\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/2817"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=2787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=2787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=2787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}