8000 Merge branch 'main' of https://github.com/Azure-Samples/azure-sql-db-… · doraig/azure-sql-db-openai@d41465f · GitHub
[go: up one dir, main page]

Skip to content

Commit d41465f

Browse files
committed
2 parents 4846135 + c991d15 commit d41465f

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,5 @@ FodyWeavers.xsd
401401
*.local.txt
402402
*.local.sql
403403
.venv/
404-
.env
404+
.env
405+
__pycache__/

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Azure SQL database can be used to significatly speed up vectors operations using
2323

2424
## Download and import the Wikipedia Article with Vector Embeddings
2525

26-
Download the [wikipedia embeedings from here](https://cdn.openai.com/API/examples/data/vector_database_wikipedia_articles_embedded.zip), unzip it and upload it (using [Azure Storage Explorer](https://learn.microsoft.com/azure/vs-azure-tools-storage-manage-with-storage-explorer?tabs=windows) for example) to an Azure Blob Storage container.
26+
Download the [wikipedia embeddings from here](https://cdn.openai.com/API/examples/data/vector_database_wikipedia_articles_embedded.zip), unzip it and upload it (using [Azure Storage Explorer](https://learn.microsoft.com/azure/vs-azure-tools-storage-manage-with-storage-explorer?tabs=windows) for example) to an Azure Blob Storage container.
2727

28-
In the example the unzipped csv file to `vector_database_wikipedia_articles_embedded.csv` is assumed to be uploaded to a blob container name `playground` and in a folder named `wikipedia`.
28+
In the example the unzipped csv file `vector_database_wikipedia_articles_embedded.csv` is assumed to be uploaded to a blob container name `playground` and in a folder named `wikipedia`.
2929

3030
Once the file is uploaded, get the [SAS token](https://learn.microsoft.com/azure/storage/common/storage-sas-overview) to allow Azure SQL database to access it. (From Azure storage Explorer, right click on the `playground` container and than select `Get Shared Access Signature`. Set the expiration date to some time in future and then click on "Create". Copy the generated query string somewhere, for example into the Notepad, as it will be needed later)
3131

@@ -36,7 +36,7 @@ Make sure to replace the `<account>` and `<sas-token>` placeholders with the val
3636
- `<account>` is the name of the storage account where the CSV file has been uploaded
3737
- `<sas-token>` is the Share Access Signature obtained before
3838

39-
Run each section (each section starts with a comment) separately. At the end of the process (will take a few minutes) you will have all the CSV data imported in the `wikipedia_articles_embeddings` table.
39+
Run each section (each section starts with a comment) separately. At the end of the process (will take up to a couple of minutes) you will have all the CSV data imported in the `wikipedia_articles_embeddings` table.
4040

4141
## Create Vectors Table
4242

@@ -139,3 +139,7 @@ Make sure to setup the database for this sample using the `./python/00-setup-dat
139139
Azure SQL database, and by extension SQL Server, already has a great support for vector operations thanks to columnstore and its usage of [SIMD](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data) [AVX-512 instructions](https://www.intel.com/content/www/us/en/architecture-and-technology/avx-512-overview.html).
140140

141141
A vector is nothing more than a list numbers (in this scope) and list of numbers can be perfectly stored in a column and even better in a columnstore index. You can start to take advantange of optimized vectors operations right now, directly in Azure SQL database, taking also advantage of all other features that it offers to developers.
142+
143+
## Community Samples
144+
145+
[Use a Poor Developers Vector Database to Implement The RAG Pattern](https://blazorhelpwebsite.com/ViewBlogPost/5066)

vector-embeddings/04-create-get-embeddings-procedure.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ create or alter procedure dbo.get_embedding
88
as
99
declare @retval int, @response nvarchar(max);
1010
declare @payload nvarchar(max) = json_object('input': @inputText);
11-
declare @url nvarchar(1000) = 'https://<your-app-name>.openai.azure.com/openai/deployments/' + @deployedModelName + '/embeddings?api-version=2023-03-15-preview'
11+
declare @url nvarchar(1000) = 'https://<your-api-name>.openai.azure.com/openai/deployments/' + @deployedModelName + '/embeddings?api-version=2023-03-15-preview'
1212
exec @retval = sp_invoke_external_rest_endpoint
1313
@url = @url,
1414
@method = 'POST',

vector-embeddings/05-find-similar-articles.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
22
Get the embeddings for the input text by calling the OpenAI API
3+
Note: <deployment-id> needs to be replaced with the deployment name of your embedding model in Azure OpenAI
34
*/
45
declare @inputText nvarchar(max) = 'the foundation series by isaac asimov';
56
declare @retval int, @response nvarchar(max);
67

7-
exec @retval = dbo.get_embedding 'embeddings', @inputText, @response output;
8+
exec @retval = dbo.get_embedding '<deployment-id>', @inputText, @response output;
89

910
drop table if exists #response;
1011
select @response as [response] into #response;

0 commit comments

Comments
 (0)
0