{"id":3766,"date":"2024-11-06T21:49:33","date_gmt":"2024-11-07T05:49:33","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=3766"},"modified":"2024-11-08T17:17:51","modified_gmt":"2024-11-09T01:17:51","slug":"sql-vector-store-data-ingestion-and-retrieval-using-azure-logic-apps","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/sql-vector-store-data-ingestion-and-retrieval-using-azure-logic-apps\/","title":{"rendered":"RAG with SQL Vector Store: A Low-Code\/No-Code Approach using Azure Logic Apps"},"content":{"rendered":"<p>Data is at the heart of every AI application, and efficient data ingestion is critical for success. With over 1,400 enterprise connectors, Logic Apps offers unmatched access to a diverse range of systems, applications, and databases, whether hosted in the cloud or on-premises. These connectors give businesses the flexibility to keep their data where it resides while seamlessly powering AI experiences.<\/p>\n<p>By leveraging <a href=\"https:\/\/learn.microsoft.com\/azure\/logic-apps\/create-single-tenant-workflows-azure-portal\">Azure Logic Apps<\/a>&#8216; native capabilities, organizations can implement the Retrieval-Augmented Generation (RAG) pattern, enabling straightforward ingestion and retrieval of data from multiple sources to enrich AI-driven applications.<\/p>\n<h3>SQL as the vector store<\/h3>\n<p>Support for a dedicated vector data type in Azure SQL Database was recently <a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/exciting-announcement-public-preview-of-native-vector-support-in-azure-sql-database\/\">announced<\/a> in Public Preview, marking a significant step forward in data storage capabilities. Recognized for its robust, scalable, and secure infrastructure, Azure SQL continues to set the standard for enterprise-grade data solutions. But as AI evolves, so do the ways we interact with data. By transforming Azure SQL into a vector store, businesses can harness the power of relational databases to handle their existing data, enabling efficient document indexing and retrieval for Gen AI models. This approach opens doors to use cases where structured and unstructured data converge\u2014without the need to adopt new search platforms.<\/p>\n<h3>Logic Apps for Document Ingestion and Retrieval<\/h3>\n<p>Building AI applications with business context awareness requires two fundamental steps. The first step is data ingestion\u2014converting text data into vector embeddings and storing it in vector stores optimized for retrieval by large language models (LLMs). The second step is reasoning on this data using various LLMs to generate answers and insights.<\/p>\n<p>In this blog post, we\u2019ll demonstrate how Logic Apps can facilitate the data ingestion process to SQL to store data as vector embeddings. We\u2019ll also cover how Logic Apps enables seamless data retrieval and integrates with Azure OpenAI\u2019s LLMs for reasoning on the ingested data.<\/p>\n<p><strong>To demonstrate Logic Apps&#8217; capabilities in this solution, we\u2019ll use the <\/strong><a href=\"https:\/\/github.com\/Azure-Samples\/azure-sql-db-vector-search\/tree\/main\/RAG-with-Documents\"><strong>RAG with Documents example<\/strong><\/a><strong> from the Azure SQL DB Vector Search repository on GitHub. The table schema used is <\/strong><a href=\"https:\/\/github.com\/Azure-Samples\/azure-sql-db-vector-search\/blob\/main\/RAG-with-Documents\/CreateTable.sql\"><strong>here<\/strong><\/a><strong>.<\/strong><\/p>\n<h3><span style=\"color: #0000ff\">Document Ingestion into SQL<\/span><\/h3>\n<p style=\"padding-left: 40px\"><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-1.png\"><img decoding=\"async\" class=\"alignnone wp-image-3782\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-1.png\" alt=\"Image rag ingest\" width=\"1201\" height=\"378\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-1.png 1430w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-1-300x94.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-1-1024x322.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-1-768x242.png 768w\" sizes=\"(max-width: 1201px) 100vw, 1201px\" \/><\/a><\/p>\n<p>In RAG (Retrieval-Augmented Generation), the ingestion process involves several stages to ensure that documents are processed, retrieved, and used effectively by generative AI models. Here\u2019s a breakdown of each stage and how you can use Logic Apps Standard for them \u2013<\/p>\n<h4><strong>Data\/Document Collection<\/strong><\/h4>\n<p style=\"padding-left: 40px\">Leverage\u00a0<strong>1400+\u00a0<\/strong><a href=\"https:\/\/learn.microsoft.com\/en-us\/connectors\/connector-reference\/connector-reference-logicapps-connectors\"><strong>connectors<\/strong><\/a> in Logic Apps to gather relevant documents, datasets or other sources of information. You can read the data based on schedule or event (for example, when new files or records are added or updated at the data source).<\/p>\n<h4><strong>Document Parsing\/Chunking<\/strong><\/h4>\n<p style=\"padding-left: 40px\">Leverage\u00a0<a href=\"https:\/\/learn.microsoft.com\/azure\/logic-apps\/parse-document-chunk-text#parse-a-document\"><strong>Parse a document <\/strong><\/a>\u00a0action\u00a0 to convert content, such as PDF document, CSV file, PPT and so on, into a tokenized string.<\/p>\n<p style=\"padding-left: 40px\">Leverage <a href=\"https:\/\/learn.microsoft.com\/azure\/logic-apps\/parse-document-chunk-text\"><strong>Chunk text<\/strong><\/a> action to split tokenized content into smaller, manageable chunks for processing in the subsequent steps by AI models. The action provides options to choose chunking strategy, token size, etc so that users can configure the chunks so that they are optimal size and in accordance to their AI models<\/p>\n<h4><strong>Generating Embeddings<\/strong><\/h4>\n<p style=\"padding-left: 40px\">Leverage <a href=\"https:\/\/learn.microsoft.com\/azure\/logic-apps\/connectors\/azure-ai#connector-technical-reference\">Azure Open AI connector<\/a>, and specifically\u00a0<strong>Generate Embeddings<\/strong>\u00a0action to convert the tokenized chunks into vector embeddings. The\u00a0<a href=\"https:\/\/learn.microsoft.com\/azure\/ai-services\/openai\/concepts\/understand-embeddings\">embeddings<\/a> represent text in a way that AI can understand and optimal for advanced similarity searches for efficient retrieval.<\/p>\n<h4><strong>Store embeddings in vector store<\/strong><\/h4>\n<p style=\"padding-left: 40px\">Prepare data for ingestion using\u00a0<strong>Select <\/strong>action by mapping the generated embeddings to the SQL table schema.<\/p>\n<p style=\"padding-left: 40px\">Write the embeddings into SQL table using the Execute Query action in SQL connector. \u00a0The SQL query can be updated based on your specific table and its schema. Here is an example of the SQL action to insert records including vector embeddings in the SQL table<\/p>\n<p style=\"padding-left: 40px\"><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_store-1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3783\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_store-1.png\" alt=\"Image sql store\" width=\"626\" height=\"558\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_store-1.png 626w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_store-1-300x267.png 300w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/a><\/p>\n<p>This completes all the steps required for document ingestion with out of box connectors and actions. Here is a sample workflow that triggers when a new file is added or updated in Blob Storage. The document is indexed into SQL database vector store with all out of box actions.<\/p>\n<p style=\"padding-left: 40px\"><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/ingest_sql-2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3779\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/ingest_sql-2.png\" alt=\"Image ingest sql\" width=\"544\" height=\"1295\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/ingest_sql-2.png 544w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/ingest_sql-2-126x300.png 126w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/ingest_sql-2-430x1024.png 430w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/a><\/p>\n<h3><\/h3>\n<h3><span style=\"color: #0000ff\">Chat with your Data \u2013 Retrieval<\/span><\/h3>\n<p>With your business data indexed in vector stores, you can now leverage that data to build contextually aware AI applications.<\/p>\n<p style=\"padding-left: 40px\"><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-2.png\"><img decoding=\"async\" class=\"alignnone wp-image-3784\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-2.png\" alt=\"Image rag ingest\" width=\"1071\" height=\"337\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-2.png 1430w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-2-300x94.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-2-1024x322.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/rag_ingest-2-768x242.png 768w\" sizes=\"(max-width: 1071px) 100vw, 1071px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Here\u2019s a breakdown of each stage and how Logic Apps facilitates the process:<\/p>\n<p><strong>Question<\/strong>\nThe retrieval process is typically initiated by a question, which may come from chat agents, APIs, or other systems. Logic Apps supports this through its out-of-the-box connectors and actions, making it simple to receive and handle queries.<\/p>\n<p><strong>Prompt<\/strong>\nBased on the question, a prompt is generated. Using the SQL connector, you can write the Select query to perform a similarity search on the vector embeddings, retrieving the most relevant information.<\/p>\n<p style=\"padding-left: 40px\"><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_vector_search-1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3785\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_vector_search-1.png\" alt=\"Image sql vector search\" width=\"626\" height=\"559\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_vector_search-1.png 626w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_vector_search-1-300x268.png 300w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/a><\/p>\n<p><strong>Response Generation<\/strong>\nTo produce a contextual and grounded response, the &#8220;Get Chat Completions&#8221; API from the Azure OpenAI connector is used. This API processes the prompt, vector search results, and system instructions to deliver an accurate answer from the LLM.<\/p>\n<p>Below is a sample workflow that processes a question, retrieves relevant responses based on SQL vector search results, and enhances these results with insights from Azure OpenAI\u2019s LLM.<\/p>\n<p style=\"padding-left: 40px\"><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_retreive.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3780\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_retreive.png\" alt=\"Image sql retreive\" width=\"525\" height=\"818\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_retreive.png 525w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/sql_retreive-193x300.png 193w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/a><\/p>\n<h3><span style=\"color: #0000ff\">Sample Response<\/span><\/h3>\n<p>Logic Apps workflow for retrieval uses HTTP trigger which creates a REST endpoint for that workflow. It can be invoked from any application, and we are using Postman to call the API<\/p>\n<p style=\"padding-left: 40px\"><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/test-2.png\"><img decoding=\"async\" class=\"alignnone wp-image-3781\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/test-2.png\" alt=\"Image test\" width=\"1480\" height=\"900\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/test-2.png 1896w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/test-2-300x182.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/test-2-1024x622.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/test-2-768x467.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2024\/11\/test-2-1536x933.png 1536w\" sizes=\"(max-width: 1480px) 100vw, 1480px\" \/><\/a><\/p>\n<h3>Getting Started<\/h3>\n<p>Are you ready to try out these capabilities? Everything you need to configure SQL and other pre-requisites such as Azure Open AI are available here &#8211; <a href=\"https:\/\/github.com\/Azure-Samples\/azure-sql-db-vector-search\/tree\/main\/RAG-with-Documents\"><strong>RAG with Documents example<\/strong><\/a> . Here are the workflow JSON for both the Logic Apps covered in this blog<\/p>\n<ul>\n<li><a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fgist.github.com%2Fyorek%2F01d03d8db46df0f463f0b8af1b0d4fa2&amp;data=05%7C02%7CDivya.Swarnkar%40microsoft.com%7C163e979f29a7453202f008dd005a53f5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638667110137811492%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&amp;sdata=V5GFNdNJw6xhXH50xNK7n%2BX9X6zqPwAuD0IvVHtrq64%3D&amp;reserved=0\">Workflow for document ingestion into SQL<\/a><\/li>\n<li><a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fgist.github.com%2Fyorek%2Fd614497530078ccc4722d386070493c7&amp;data=05%7C02%7CDivya.Swarnkar%40microsoft.com%7C163e979f29a7453202f008dd005a53f5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638667110137853334%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&amp;sdata=1C4%2BHWNdlVWDNQYYU6kk8LX5eHgbXHg%2Bt1j71yrfNN4%3D&amp;reserved=0\">Workflow for data retrieval and Chat<\/a><\/li>\n<\/ul>\n<h3>Learn More<\/h3>\n<p>If you are new to Azure Logic Apps, here are few pointers to get started and use Logic Apps to accelerate developer productivity.<\/p>\n<ul>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/logic-apps\/create-single-tenant-workflows-azure-portal\">Azure Logic Apps &#8211; How to create a new Logic App<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/azure\/logic-apps\/connectors\/azure-ai\">Azure Logic Apps AI capabilities\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/logic-apps\/connectors\/built-in\/reference\/sql\/\">SQL connector<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Data is at the heart of every AI application, and efficient data ingestion is critical for success. With over 1,400 enterprise connectors, Logic Apps offers unmatched access to a diverse range of systems, applications, and databases, whether hosted in the cloud or on-premises. These connectors give businesses the flexibility to keep their data where it [&hellip;]<\/p>\n","protected":false},"author":173800,"featured_media":81,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[601,599,1,582,619,615],"tags":[602,510,588,499,591],"class_list":["post-3766","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-azure-openai","category-azure-sql","category-openai","category-t-sql","category-vectors","tag-azure-openai","tag-azure-sql-database","tag-azure-sql-db","tag-azure-logic-apps","tag-vector-search"],"acf":[],"blog_post_summary":"<p>Data is at the heart of every AI application, and efficient data ingestion is critical for success. With over 1,400 enterprise connectors, Logic Apps offers unmatched access to a diverse range of systems, applications, and databases, whether hosted in the cloud or on-premises. These connectors give businesses the flexibility to keep their data where it [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/3766","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\/173800"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=3766"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/3766\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/81"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=3766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=3766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=3766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}