Microsoft Dev Blogs

Vector Search with Azure SQL, Semantic Kernel and Entity Framework Core

thumbnail

Azure SQL Database Vector Search Sample App

This GitHub repository is a practical example of how to use the native vector type in Azure SQL Database to perform embeddings and Retrieval-Augmented Generation (RAG) with Azure OpenAI. The repository showcases how vectors are saved and retrieved using Entity Framework Core with the EFCore.SqlServer.VectorSearch library. It also integrates Embedding and Chat Completion functionalities with Semantic Kernel to allow users to track their interactions and refine their queries as needed.

Features

  • Full chat interface with Embedding and Chat Completion functionalities.
  • REST API for all features, allowing integration with any frontend application.
  • Detailed information about token usage to understand consumption during interactions.

Getting Started

To run the application in your environment:

  1. Clone the repository.
  2. Create an Azure SQL Database.
  3. Open the appsettings.json file and set the connection string to the database and other required Azure OpenAI settings.
  4. Set the Dimensions property in the appsettings.json file to the corresponding value if your embedding model supports shortening (e.g., text-embedding-3-small or text-embedding-3-large). The default value is 1536, and the maximum allowed value is 1998.
  5. If you change the Dimensions property, remember to update the Database Migration accordingly.
  6. Use the /api/ask or /api/ask-streaming endpoints to ask questions.

GitHub Repository: marcominerva/SqlDatabaseVectorSearch

By following these steps, you can set up and explore the Azure SQL Database Vector Search Sample App in your own environment.