{"id":2989,"date":"2024-04-03T05:00:43","date_gmt":"2024-04-03T12:00:43","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=2989"},"modified":"2024-04-02T20:37:20","modified_gmt":"2024-04-03T03:37:20","slug":"vanna-ai-and-azure-sql-database","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/vanna-ai-and-azure-sql-database\/","title":{"rendered":"Vanna.ai and Azure SQL Database"},"content":{"rendered":"<h2>Vanna.ai and Microsoft SQL<\/h2>\n<p><a href=\"https:\/\/vanna.ai\/\">Vanna.ai<\/a>, in partnership with <span style=\"font-size: 12pt\"><span style=\"text-align: var(--bs-body-text-align)\">Azure SQL Database Product Management, bring you a collaboration for using Vanna&#8217;s natural language to SQL (NL2SQL) agent with the Azure SQL Database.<\/span><\/span><\/p>\n<h2>How does Vanna.ai work?<\/h2>\n<p><span style=\"font-size: 12pt\"><span style=\"text-align: var(--bs-body-text-align)\">First, Vanna is an open-source Python RAG (Retrieval-Augmented Generation) framework for SQL generation\/natural language to SQL (NL2SQL) and provides a fully hosted platform for application development. Get started for free <\/span><a style=\"background-color: #f7f7f9;text-align: var(--bs-body-text-align)\" href=\"https:\/\/vanna.ai\/account\/login?next=\/account\/profile\" target=\"_blank\" rel=\"noopener\">here<\/a><span style=\"text-align: var(--bs-body-text-align)\">.<\/span><\/span><\/p>\n<p>(From the <a href=\"https:\/\/vanna.ai\/docs\/\" target=\"_blank\" rel=\"noopener\">documentation<\/a>)<\/p>\n<p>At its core, Vanna is a Python package that uses retrieval augmentation to help you generate accurate SQL queries for your database using LLMs.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/vanna.ai\/docs\/img\/how-vanna-works.gif\" alt=\"How Vanna Works\" width=\"937\" height=\"672\" \/><\/p>\n<p>Vanna works in two easy steps &#8211; train a RAG &#8220;model&#8221; on your data, and then ask questions which will return SQL queries that can be set up to automatically run on your database.<\/p>\n<h2>BYOLLM<\/h2>\n<p>Already have an LLM and want to bring your own? Or have a vector DB for storage? Or both? No problem! Easily configure an environment <a href=\"https:\/\/vanna.ai\/#configure\" target=\"_blank\" rel=\"noopener\">here<\/a> and out comes the python notebook needed to get started (Vanna has created <a href=\"https:\/\/github.com\/vanna-ai\/notebooks\" target=\"_blank\" rel=\"noopener\">notebooks for EVERY combination<\/a>!).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Untitled.gif\"><img decoding=\"async\" class=\"aligncenter wp-image-2996 size-full\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Untitled.gif\" alt=\"Choosing a database, LLM and vector DB on vanna.ai\" width=\"993\" height=\"585\" \/><\/a><\/p>\n<p>Vanna.ai has always been simple to use, but now, with the addition of Microsoft SQL Server\/Azure SQL as a database connecter, it&#8217;s even easier.<\/p>\n<h4><b>Why use AI to chat with your database in the first place?\u00a0<\/b><\/h4>\n<p>To start, it allows you spend less time writing SQL and more time generating insights on your data. You no longer have to be an expert in SQL to get information from the database. And if you are an expert, save some time writing a query when you can just ask for it. In fact, everyone benefits by being able to ask the database about business questions and getting the answer; have Vanna find the relevant tables and columns across your data estate.<\/p>\n<p><b style=\"color: inherit;font-family: inherit;font-size: 1.5rem;text-align: var(--bs-body-text-align)\">And why Vanna?\u00a0<\/b><\/p>\n<div>\n<p>With it&#8217;s retrieval framework and feedback loop, allows you to quickly train up an &#8220;AI Analyst&#8221; in much the same way that you would onboard a human analyst by supervising it. While using it, you can give instant feedback if the generated SQL was correct and have those answers help train the AI for future questions. And as will be seen in the blog, <span style=\"font-size: 1rem;text-align: var(--bs-body-text-align)\">Vanna c<\/span>an be used as a standalone web app, in Jupyter, as part of an embedded widget, or as part of a MS Teams bot. See examples of this at <a title=\"Original URL: https:\/\/github.com\/vanna-ai Click to follow link.\" href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fgithub.com%2Fvanna-ai&amp;data=05%7C02%7Cbspendolini%40microsoft.com%7Ccb54b9cc3a1b4bdc7b2708dc47772240%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638463824221915721%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&amp;sdata=1Im8b99OKJvPO9XTcNo0fBgCbQnIu5hpKxNwXiESFEg%3D&amp;reserved=0\" target=\"_blank\" rel=\"noopener\" data-outlook-id=\"801ea6a0-5aed-4196-b742-0435c7276b9a\">https:\/\/github.com\/vanna-ai<\/a>.<\/p>\n<\/div>\n<h2>Vanna x SQL x Codespace<\/h2>\n<p>This blog post will go over creating a NL2SQL agent using Vanna.ai and SQL Server\/Azure SQL using a python notebook and a GitHub codespace. The notebook will be based off of the one hosted by Vanna <a href=\"https:\/\/github.com\/vanna-ai\/notebooks\/blob\/main\/mssql-openai-vanna-vannadb.ipynb\" target=\"_blank\" rel=\"noopener\">here<\/a> which uses Vanna&#8217;s hosted LLM and vector database with SQL Server\/Azure SQL. The codespace will also be using a local free instance of SQL Server using docker in docker loaded with the Adventure Works sample data.<\/p>\n<p>Get started by:<\/p>\n<ol>\n<li>Going to this <a href=\"https:\/\/github.com\/Azure-Samples\/SQL-AI-samples\" target=\"_blank\" rel=\"noopener\">GitHub repository<\/a><\/li>\n<li>Clicking on the <strong>green Code button<\/strong><\/li>\n<li>Clicking the <strong>3 dots<\/strong><\/li>\n<li>Selecting <strong>+ New with options<\/strong>.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.20.23\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3000\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.20.23\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 9 20 23 AM\" width=\"642\" height=\"389\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.20.23\u202fAM.png 642w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.20.23\u202fAM-300x182.png 300w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><\/a><\/p>\n<p>Then on the following page:<\/p>\n<ol>\n<li>Click the <strong>Default project configuration button<\/strong><\/li>\n<li>Select <strong>Python<\/strong> (we will be adding many more configurations as we add to this repository)<\/li>\n<li>Click the <strong>green Create codespace button<\/strong><\/li>\n<\/ol>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.22.47\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3001\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.22.47\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 9 22 47 AM\" width=\"860\" height=\"485\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.22.47\u202fAM.png 860w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.22.47\u202fAM-300x169.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.22.47\u202fAM-768x433.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Once the codespace has started, use the terminal to run the following code to install sqlcmd:<\/p>\n<pre>curl https:\/\/packages.microsoft.com\/keys\/microsoft.asc <span class=\"pl-k\">|<\/span> sudo tee \/etc\/apt\/trusted.gpg.d\/microsoft.asc\r\nsudo add-apt-repository <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span><span class=\"pl-pds\">$(<\/span>wget -qO- https:\/\/packages.microsoft.com\/config\/ubuntu\/20.04\/prod.list<span class=\"pl-pds\">)<\/span><span class=\"pl-pds\">\"<\/span><\/span>\r\nsudo apt-get update\r\nsudo apt-get install sqlcmd<\/pre>\n<p>then, create the database with the following command:<\/p>\n<pre>sqlcmd create mssql --accept-eula --using https:\/\/aka.ms\/AdventureWorksLT.bak\r\n\r\n<a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.00.09\u202fAM.png\"><img decoding=\"async\" class=\"wp-image-3006 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.00.09\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 00 09 AM\" width=\"1010\" height=\"174\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.00.09\u202fAM.png 1341w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.00.09\u202fAM-300x52.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.00.09\u202fAM-1024x176.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.00.09\u202fAM-768x132.png 768w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/a><\/pre>\n<p>and once the database is finished creating, the connection string for ODBC will be needed for the notebook, run the following command to get the connection string:<\/p>\n<pre>sqlcmd config connection-strings<\/pre>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.59.46\u202fAM.png\"><img decoding=\"async\" class=\"wp-image-3007 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.59.46\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 9 59 46 AM\" width=\"1038\" height=\"280\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.59.46\u202fAM.png 1138w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.59.46\u202fAM-300x81.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.59.46\u202fAM-1024x276.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-9.59.46\u202fAM-768x207.png 768w\" sizes=\"(max-width: 1038px) 100vw, 1038px\" \/><\/a><\/p>\n<p>sss<\/p>\n<p><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Security Check<\/strong><\/p>In the connect string, there is TrustServerCertificate=yes. For local development environments, this is OK but <strong>NEVER<\/strong> use this setting in live\/production environments. More on this <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/networking\/tds-8?view=sql-server-ver16#strict-connection-encryption\" target=\"_blank\" rel=\"noopener\">here<\/a><\/div><\/p>\n<p>One of the files included in this directory is the odbcDriverInstallUbuntu.txt file. This file contains the commands for installing the Microsoft ODBC driver for SQL Server on Ubuntu (Linux). Run the contents of this file in the terminal to install the driver. Once installed, run the following command for checking the version to ensure it has been installed successfully:<\/p>\n<pre>more \/etc\/odbcinst.ini<\/pre>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.18.46\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3010\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.18.46\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 18 46 AM\" width=\"1073\" height=\"130\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.18.46\u202fAM.png 1073w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.18.46\u202fAM-300x36.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.18.46\u202fAM-1024x124.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.18.46\u202fAM-768x93.png 768w\" sizes=\"(max-width: 1073px) 100vw, 1073px\" \/><\/a><\/p>\n<h2>Open your notebook to&#8230;<\/h2>\n<p>Now that the database is created with the Adventure Works data, open the <strong>vanna_and_sql.ipynb notebook<\/strong> in the code editor by clicking on it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.22.18\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3011\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.22.18\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 22 18 AM\" width=\"471\" height=\"105\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.22.18\u202fAM.png 471w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.22.18\u202fAM-300x67.png 300w\" sizes=\"(max-width: 471px) 100vw, 471px\" \/><\/a><\/p>\n<p>The first Setup step installs the vanna and pyodbc python libraries to be used in the notebook. Click on the Execute Cell button to run this command.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.24.50\u202fAM-1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3013\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.24.50\u202fAM-1.png\" alt=\"Image Screenshot 2024 03 15 at 10 24 50 AM\" width=\"541\" height=\"116\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.24.50\u202fAM-1.png 541w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.24.50\u202fAM-1-300x64.png 300w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/a><\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Choose a Kernel<\/strong><\/p>You may see a dialog box asking you to choose a Python Kernal for the notebook. Choose python environment for the first choice and then the python version installed in this codespace.<\/div><\/p>\n<p>Next, execute the following cell that prepares the libraries to be used for the python commands that follow:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.28.13\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3014\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.28.13\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 28 13 AM\" width=\"585\" height=\"162\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.28.13\u202fAM.png 585w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.28.13\u202fAM-300x83.png 300w\" sizes=\"(max-width: 585px) 100vw, 585px\" \/><\/a><\/p>\n<p>The last cell in the Setup section of the notebook sets the Vanna API key and model name to be used for the Vanna hosted LLM and vector database. Remember, you can sign up for these free services here. Once you enter this information, execute the cell with the run button.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.31.10\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3015\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.31.10\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 31 10 AM\" width=\"1122\" height=\"214\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.31.10\u202fAM.png 1122w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.31.10\u202fAM-300x57.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.31.10\u202fAM-1024x195.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.31.10\u202fAM-768x146.png 768w\" sizes=\"(max-width: 1122px) 100vw, 1122px\" \/><\/a><\/p>\n<p>The next step in the notebook defines the database connection. Vanna has help out MS SQL\/Azure SQL users here with <span style=\"font-size: 1rem;text-align: var(--bs-body-text-align)\">vn.connect_to_mssql. All that needs to be passed to this function is the ODBC string that was shown previously by running <strong>sqlcmd config connection-strings<\/strong>. Copy and paste the ODBC connection string into this cell of the notebook then run it.<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.41.18\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3017\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.41.18\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 41 18 AM\" width=\"1170\" height=\"143\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.41.18\u202fAM.png 1170w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.41.18\u202fAM-300x37.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.41.18\u202fAM-1024x125.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.41.18\u202fAM-768x94.png 768w\" sizes=\"(max-width: 1170px) 100vw, 1170px\" \/><\/a><\/p>\n<h2>Training Grounds<\/h2>\n<p>Moving to the training section, if the previous sections were filled out correctly, executing this cell should result in seeing all the tables in the database that the user in the connection string allows (which should be all of Adventure Works tables and views).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.43.03\u202fAM.png\"><img decoding=\"async\" class=\"wp-image-3019 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.43.03\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 43 03 AM\" width=\"902\" height=\"504\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.43.03\u202fAM.png 1469w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.43.03\u202fAM-300x167.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.43.03\u202fAM-1024x572.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.43.03\u202fAM-768x429.png 768w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/a><\/p>\n<p>The next cell uses some training to remind the NL2SQL agent to use tables with their schema names. As before, execute this cell:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.55.49\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3020\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.55.49\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 55 49 AM\" width=\"1249\" height=\"204\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.55.49\u202fAM.png 1249w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.55.49\u202fAM-300x49.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.55.49\u202fAM-1024x167.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.55.49\u202fAM-768x125.png 768w\" sizes=\"(max-width: 1249px) 100vw, 1249px\" \/><\/a><\/p>\n<h2>Free Apps!<\/h2>\n<p>Part of the Vanna python package is a flask app that can be used as a chat session. Execute this cell to start the flask application:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.59.45\u202fAM.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3021\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.59.45\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 10 59 45 AM\" width=\"575\" height=\"175\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.59.45\u202fAM.png 575w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-10.59.45\u202fAM-300x91.png 300w\" sizes=\"(max-width: 575px) 100vw, 575px\" \/><\/a><\/p>\n<p>Once the application has started, a dialog box will appear at the bottom of the code space:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.00.25\u202fAM-2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3024\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.00.25\u202fAM-2.png\" alt=\"Image Screenshot 2024 03 15 at 11 00 25 AM\" width=\"694\" height=\"170\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.00.25\u202fAM-2.png 694w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.00.25\u202fAM-2-300x73.png 300w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><\/a><\/p>\n<p>Click the <strong>Open in Browser<\/strong> button to try out the application.<\/p>\n<p>Using the chat box, ask the application a question about the Adventure Work data. For example, &#8220;What are the top 10 products sold and their colors? Format any currency columns as dollars.&#8221;.<\/p>\n<p>The result is the SQL query itself, a table with the data as asked:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.05.24\u202fAM.png\"><img decoding=\"async\" class=\"size-full wp-image-3025 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.05.24\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 11 05 24 AM\" width=\"912\" height=\"873\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.05.24\u202fAM.png 912w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.05.24\u202fAM-300x287.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.05.24\u202fAM-768x735.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.05.24\u202fAM-24x24.png 24w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><\/a><\/p>\n<p>as well as a nice chart!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.07.28\u202fAM.png\"><img decoding=\"async\" class=\"size-full wp-image-3026 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.07.28\u202fAM.png\" alt=\"Image Screenshot 2024 03 15 at 11 07 28 AM\" width=\"816\" height=\"480\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.07.28\u202fAM.png 816w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.07.28\u202fAM-300x176.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/03\/Screenshot-2024-03-15-at-11.07.28\u202fAM-768x452.png 768w\" sizes=\"(max-width: 816px) 100vw, 816px\" \/><\/a><\/p>\n<p><div class=\"alert alert-success\">If the agent doesn&#8217;t add the schema to the table name and you get an error, just give it a quick reminder in the question. Ask &#8220;What are the top 10 products sold and their colors? Format any currency columns as dollars. Use the schema and table name&#8221;<\/div><\/p>\n<h2>Wrap-up<\/h2>\n<p>Again, a huge thank you to Vanna for adding the simple, one line of code function for accessing SQL databases. It makes an already easy to use NL2SQL tool even easier (if that was possible!). The notebook sample is in the Azure SQL AI Samples repository <a href=\"https:\/\/github.com\/Azure-Samples\/SQL-AI-samples\/tree\/main\/AzureSQLDatabase\/Vanna.ai\" target=\"_blank\" rel=\"noopener\">here<\/a> for anyone to try out and start using with their applications. As always, tell us how it goes, and we appreciate any feedback you may have.<\/p>\n<h3>Resources<\/h3>\n<ul>\n<li><a href=\"https:\/\/vanna.ai\/\">Vanna.ai<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/vanna-ai\" target=\"_blank\" rel=\"noopener\">Vanna.ia&#8217;s Github Repository<\/a><\/li>\n<li><a href=\"https:\/\/vanna.ai\/docs\/\" target=\"_blank\" rel=\"noopener\">Vanna.ai Documentation<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Azure-Samples\/SQL-AI-samples\" target=\"_blank\" rel=\"noopener\">Azure SQL AI Samples GitHub Repository<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Vanna.ai and Microsoft SQL Vanna.ai, in partnership with Azure SQL Database Product Management, bring you a collaboration for using Vanna&#8217;s natural language to SQL (NL2SQL) agent with the Azure SQL Database. How does Vanna.ai work? First, Vanna is an open-source Python RAG (Retrieval-Augmented Generation) framework for SQL generation\/natural language to SQL (NL2SQL) and provides a [&hellip;]<\/p>\n","protected":false},"author":95874,"featured_media":3030,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[590,602,510,465,469,30,449,613,561,407,612,611],"class_list":["post-2989","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-sql","tag-ai","tag-azure-openai","tag-azure-sql-database","tag-azuresql","tag-azuresqldb","tag-developers","tag-development","tag-nl2sql","tag-openai","tag-python","tag-vanna","tag-vanna-ai"],"acf":[],"blog_post_summary":"<p>Vanna.ai and Microsoft SQL Vanna.ai, in partnership with Azure SQL Database Product Management, bring you a collaboration for using Vanna&#8217;s natural language to SQL (NL2SQL) agent with the Azure SQL Database. How does Vanna.ai work? First, Vanna is an open-source Python RAG (Retrieval-Augmented Generation) framework for SQL generation\/natural language to SQL (NL2SQL) and provides a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/2989","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\/95874"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=2989"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/2989\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/3030"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=2989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=2989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=2989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}