{"id":4329,"date":"2025-03-19T07:53:01","date_gmt":"2025-03-19T14:53:01","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=4329"},"modified":"2025-03-19T07:59:53","modified_gmt":"2025-03-19T14:59:53","slug":"vector-search-with-azure-sql-semantic-kernel-and-entity-framework-core","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/vector-search-with-azure-sql-semantic-kernel-and-entity-framework-core\/","title":{"rendered":"Vector Search with Azure SQL, Semantic Kernel and Entity Framework Core"},"content":{"rendered":"<p><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Guest Post<\/strong><\/p>Marco Minerva has been using .NET since its first introduction. Today he works as a freelance consultant and is involved in designing and developing solutions for the Microsoft ecosystem. He is a speaker at technical events, writes books and articles about developing and makes live streaming about coding on Twitch. He is a Microsoft MVP since 2013. Thanks Marco! <\/div><\/p>\n<p>Vector databases like Qdrant and Milvus are specifically designed to efficiently store, manage, and retrieve embeddings. However, many applications already use relational databases like SQL Server or SQL Azure. In such cases, installing and managing another database can be challenging, especially since these vector databases may not offer all the features of a modern relational database like Azure SQL or SQL Server.<\/p>\n<p>This is where the new vector data type in SQL Azure becomes extremely useful. It allows you to create Retrieval-Augmented Generation (RAG) solutions by storing embeddings in the same place as your other data, eliminating the need for an external vector database.<\/p>\n<h2>Database Vector Search Sample App<\/h2>\n<p>For a practical example, check out the GitHub repository <a href=\"https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch\">https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch<\/a> showcases how to use the native vector type in Azure SQL Database to perform embeddings and RAG with Azure OpenAI.<\/p>\n<p><img decoding=\"async\" width=\"480\" height=\"360\" class=\"wp-image-4330 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search.jpeg\" alt=\"SQL Database Vector Search\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search.jpeg 480w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-300x225.jpeg 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/p>\n<p>The application enables users to load documents, generate embeddings, and save them into the database as vectors. It also supports performing searches using Vector Search and Retrieval-Augmented Generation (RAG). Currently, the application supports PDF, DOCX, TXT, and MD file formats. Vectors are saved and retrieved using Entity Framework Core with the <a href=\"https:\/\/github.com\/efcore\/EFCore.SqlServer.VectorSearch\">EFCore.SqlServer.VectorSearch<\/a> library. Additionally, Embedding and Chat Completion functionalities are integrated with <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\">Semantic Kernel<\/a>.<\/p>\n<p>This repository includes a Blazor Web App and a Minimal API, which allow for programmatic interaction with embeddings and RAG.<\/p>\n<h3><strong>Supported features<\/strong><\/h3>\n<ul>\n<li><strong>Conversation History with Question Reformulation<\/strong>: This feature allows users to view the history of their conversations, including the ability to reformulate questions for better clarity and understanding. This ensures that users can track their interactions and refine their queries as needed.<\/li>\n<li><strong>Information about Token Usage<\/strong>: Users can access detailed information about token usage, which helps in understanding the consumption of tokens during interactions. This feature provides transparency and helps users manage their token usage effectively.<\/li>\n<li><strong>Response Streaming<\/strong>: This feature enables real-time streaming of responses, allowing users to receive information as it is being processed. This ensures a seamless and efficient flow of information, enhancing the overall user experience.<\/li>\n<\/ul>\n<h2><strong>Web App<\/strong><\/h2>\n<p>The Blazor applications provide fully functional chat interface:<\/p>\n<p><img decoding=\"async\" width=\"1137\" height=\"906\" class=\"wp-image-4331\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-web-app.png\" alt=\"SQL Database Vector Search Web App\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-web-app.png 1137w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-web-app-300x239.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-web-app-1024x816.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-web-app-768x612.png 768w\" sizes=\"(max-width: 1137px) 100vw, 1137px\" \/><\/p>\n<h3><strong>Web API<\/strong><\/h3>\n<p>Aside from the fronted app, all the features are available also via REST API so that you integrate the sample with any fronted you many want to create by yourself:<\/p>\n<p><img decoding=\"async\" width=\"1093\" height=\"673\" class=\"wp-image-4332\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-api.png\" alt=\"SQL Database Vector Search API\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-api.png 1093w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-api-300x185.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-api-1024x631.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2025\/03\/sql-database-vector-search-api-768x473.png 768w\" sizes=\"(max-width: 1093px) 100vw, 1093px\" \/><\/p>\n<h2>Getting Started<\/h2>\n<p>To run the application in your own environment make sure to follow the following steps:<\/p>\n<ul>\n<li>Clone the repository<\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/azure-sql\/database\/single-database-create-quickstart\">Create an Azure SQL Database<\/a><\/li>\n<li>Open the\u00a0<a href=\"https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch\/blob\/master\/SqlDatabaseVectorSearch\/appsettings.json\">appsettings.json<\/a>\u00a0file and set the connection string to the database and the other settings required by Azure OpenAI\n<ul>\n<li>If your embedding model supports shortening, like\u00a0<strong>text-embedding-3-small<\/strong>\u00a0and\u00a0<strong>text-embedding-3-large<\/strong>, and you want to use this feature, you need to set the\u00a0<a href=\"https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch\/blob\/master\/SqlDatabaseVectorSearch\/appsettings.json#L17\">Dimensions<\/a>\u00a0property to the corresponding value. If your model doesn&#8217;t provide this feature, or do you want to use the default size, just leave the\u00a0<a href=\"https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch\/blob\/master\/SqlDatabaseVectorSearch\/appsettings.json#L17\">Dimensions<\/a>\u00a0property to NULL. Keep in mind that\u00a0<strong>text-embedding-3-small<\/strong>\u00a0has a dimension of 1536, while\u00a0<strong>text-embedding-3-large<\/strong>\u00a0uses vectors with 3072 elements, so with this latter model it is mandatory to specify a value (that, as said, must be less or equal to 1998).<\/li>\n<\/ul>\n<\/li>\n<li>You may need to update the size of the\u00a0<a href=\"https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch\/blob\/master\/SqlDatabaseVectorSearch\/DataAccessLayer\/ApplicationDbContext.cs?plain=1#L42C1-L42C47\">VECTOR<\/a>\u00a0column to match the size of the embedding model. The default value is 1536. Currently, the maximum allowed value is 1998. If you change it, remember to update also the\u00a0<a href=\"https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch\/blob\/master\/SqlDatabaseVectorSearch\/DataAccessLayer\/Migrations\/00000000000000_Initial.cs?plain=1#L35C1-L35C92\">Database Migration<\/a>.<\/li>\n<li>Run the application and start importing your documents<\/li>\n<li>If you want to directly use the APIs:\n<ul>\n<li>import your documents with the\u00a0<em>\/api\/documents<\/em>\u00a0endpoint.<\/li>\n<li>Ask questions using\u00a0<em>\/api\/ask<\/em>\u00a0or\u00a0<em>\/api\/ask-streaming<\/em>\u00a0endpoints.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>And then you&#8217;re good to go!<\/p>\n<p style=\"text-align: center;\"><div  class=\"d-flex justify-content-left\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/github.com\/marcominerva\/SqlDatabaseVectorSearch\" target=\"_blank\">Get the repo!<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vector databases like Qdrant and Milvus are specifically designed to efficiently store, manage, and retrieve embeddings. However, many applications already use relational databases like SQL Server or SQL Azure. In such cases, installing and managing another database can be challenging, especially since these vector databases may not offer all the features of a modern relational [&hellip;]<\/p>\n","protected":false},"author":24720,"featured_media":4332,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[444,601,599,1,634],"tags":[629,561,627,647],"class_list":["post-4329","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-ai","category-azure-openai","category-azure-sql","category-semantic-kernel","tag-chatbot","tag-openai","tag-rag","tag-vectors"],"acf":[],"blog_post_summary":"<p>Vector databases like Qdrant and Milvus are specifically designed to efficiently store, manage, and retrieve embeddings. However, many applications already use relational databases like SQL Server or SQL Azure. In such cases, installing and managing another database can be challenging, especially since these vector databases may not offer all the features of a modern relational [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/4329","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\/24720"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=4329"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/4329\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/4332"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=4329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=4329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=4329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}