Enhanced app with Vector Search support

- Updated README.md with details on Vector Support in Azure SQL Database, application functionalities, and setup instructions.
- Removed inheritance of `Question` class from `Search` class and deleted `Search` class.
- Minor adjustment in Program.cs for endpoint description consistency.
- Simplified appsettings.Development.json by removing the empty "ConnectionStrings" section.
- Enhanced Script.sql with SQL commands to create `DocumentChunks` and `Documents` tables, including schema for identifiers, content, embeddings, document names, creation dates, and established a foreign key relationship between the two tables.
This commit is contained in:
Marco Minerva
2024-06-14 17:42:37 +02:00
parent b6c898a3f5
commit dcccdf7365
7 changed files with 44 additions and 10 deletions
+12 -1
View File
@@ -1,2 +1,13 @@
# SQL Database Vector Search Sample # SQL Database Vector Search Sample
A repository that showcases the Vector Support in Azure SQL Database to perform embeddings and RAG A repository that showcases the Vector Support in Azure SQL Database to perform embeddings and RAG with Azure OpenAI.
> [!IMPORTANT]
> Usage of this application requires the Vector Support feature in Azure SQL Database, currently in EAP. [See this blog post](https://devblogs.microsoft.com/azure-sql/announcing-eap-native-vector-support-in-azure-sql-database/) for more details.
The application is a Minimal API that exposes endpoints to load documents, generate embeddings and save them into the database as Vectors, and perform searches using Vector Search and RAG. Database access is done using the [EFCore.SqlServer.VectorSearch](https://github.com/efcore/EfCore.SqlServer.VectorSearch) library.
### Setup
- Create an Azure SQL Database on a server that has the Vector Support feature enabled.
- Execute the [Scripts.sql](https://github.com/marcominerva/SqlDatabaseVectorSearch/blob/master/Scripts.sql) file to create the tables needed by the application.
- Open the [appsettings.json](https://github.com/marcominerva/SqlDatabaseVectorSearch/blob/master/SqlDatabaseVectorSearch/appsettings.json) file and set the connection string to the database and the other settings required by Azure OpenAI.
+30
View File
@@ -0,0 +1,30 @@
CREATE TABLE [dbo].[DocumentChunks](
[Id] [uniqueidentifier] NOT NULL,
[DocumentId] [uniqueidentifier] NOT NULL,
[Content] [nvarchar](max) NOT NULL,
[Embedding] [varbinary](8000) NOT NULL,
CONSTRAINT [PK_DocumentChunks] PRIMARY KEY CLUSTERED
(
[Id] ASC
))
GO
CREATE TABLE [dbo].[Documents](
[Id] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](255) NOT NULL,
[CreationDate] [datetimeoffset](7) NOT NULL,
CONSTRAINT [PK_Documents] PRIMARY KEY CLUSTERED
(
[Id] ASC
))
GO
ALTER TABLE [dbo].[DocumentChunks] ADD CONSTRAINT [DF_DocumentChunks_Id] DEFAULT (newid()) FOR [Id]
GO
ALTER TABLE [dbo].[Documents] ADD CONSTRAINT [DF_Documents_Id] DEFAULT (newid()) FOR [Id]
GO
ALTER TABLE [dbo].[DocumentChunks] WITH CHECK ADD CONSTRAINT [FK_DocumentChunks_Documents] FOREIGN KEY([DocumentId])
REFERENCES [dbo].[Documents] ([Id])
GO
+1 -1
View File
@@ -1,3 +1,3 @@
namespace SqlDatabaseVectorSearch.Models; namespace SqlDatabaseVectorSearch.Models;
public record class Question(Guid ConversationId, string Text) : Search(Text); public record class Question(Guid ConversationId, string Text);
-4
View File
@@ -1,4 +0,0 @@
namespace SqlDatabaseVectorSearch.Models;
public record class Search(string Text);
+1 -1
View File
@@ -101,7 +101,7 @@ documentsApiGroup.MapDelete("{documentId:guid}", async (Guid documentId, VectorS
.WithOpenApi(operation => .WithOpenApi(operation =>
{ {
operation.Summary = "Deletes a document"; operation.Summary = "Deletes a document";
operation.Description = "This endpoint deletes the document and all its chunks from SQL Server"; operation.Description = "This endpoint deletes the document and all its chunks from SQL Server.";
return operation; return operation;
}); });
@@ -1,7 +1,4 @@
{ {
"ConnectionStrings": {
"SqlConnection": ""
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB