mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-06-20 12:23:10 +00:00
b5c7ea57c3c7c3381f7838b79be81a6299479bad
Updated Program.cs to use ConfigureAndGet for settings and added TokenizerService singleton. Modified ChatService to include TokenizerService and updated prompt logic for token limits. Added TokenizerService class using TiktokenTokenizer. Updated AppSettings and AzureOpenAISettings with new token and model settings. Updated SqlDatabaseVectorSearch.csproj with new package references and version bump. Updated appsettings.json with new settings.
SQL Database Vector Search Sample
A repository that showcases the native VECTOR type in Azure SQL Database to perform embeddings and RAG with Azure OpenAI.
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. Currently, only PDF files are supported. Vectors are saved and retrieved with Entity Framework Core using the EFCore.SqlServer.VectorSearch library. Embedding and Chat Completion are integrated with Semantic Kernel.
Note
If you prefer to use straight SQL, check out the sql branch.
Setup
- Create an Azure SQL Database on a server that has the Vector Support feature enabled
- Execute the Scripts.sql file to create the tables needed by the application
- You may need to update the size of the
VECTORcolumn to match the size of the embedding model. Currently, the maximum allowed value is 1998.
- You may need to update the size of the
- Open the appsettings.json file and set the connection string to the database and the other settings required by Azure OpenAI
- If your embedding model supports shortening, like text-embedding-3-small and text-embedding-3-large, and you want to use this feature, you need to set the
Dimensionsproperty to match the value you have used in the SQL script. If your model doesn't provide this feature, or do you want to use the default size, just leave theDimensionsproperty to NULL. Keep in mind that text-embedding-3-small has a dimension of 1536, while text-embedding-3-large uses 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).
- If your embedding model supports shortening, like text-embedding-3-small and text-embedding-3-large, and you want to use this feature, you need to set the
- Run the application and start importing your PDF documents.
Description
Languages
C#
54.5%
HTML
32.7%
CSS
9.4%
JavaScript
2.5%
TSQL
0.9%
