Skip to content

Commit 899f8d8

Browse files
author
Davide Mauri
committed
updated import scripts
1 parent 4f09666 commit 899f8d8

3 files changed

Lines changed: 34 additions & 20 deletions

File tree

DiskANN/Wikipedia/002b-import-data-azure-storage.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ create external data source [sample_data]
1818
with
1919
(
2020
type = blob_storage,
21-
location = 'https://dmstore2.blob.core.windows.net/sample-data/',
21+
location = 'https://<account>.blob.core.windows.net/sample-data/',
2222
credential = [sample_data]
2323
);
2424
go

DiskANN/Wikipedia/004a-generate-search-vector-local.sql

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@
55
"The foundation series by Isaac Asimov" using the "ada2-text-embedding" model
66
Uncomment the following text if you don't have access to a OpenAI model,
77
otherwise it is recommended to use the new "ai_generate_embedding" function
8-
by using the code in the "Option 2" section below
8+
by using the code in the file '004c-generate-search-vector-openai.sql'
99
*/
1010
use WikipediaTest
1111
go
1212

13-
drop table if exists dbo.wikipedia_search_vectors
13+
-- Save embeddings for future use
14+
drop table if exists dbo.wikipedia_search_vectors;
15+
create table dbo.wikipedia_search_vectors (id int primary key, q nvarchar(max), v vector(1536))
1416
go
1517

1618
declare @j json = (select BulkColumn from
17-
openrowset(bulk 'C:\samples\rc1\datasets\reference-embedding.json', single_clob) as j)
18-
declare @qv vector(1536) = json_query(@j, '$."embedding-vector"')
19-
drop table if exists #t;
20-
create table #t (v vector(1536));
21-
insert into #t values (@qv);
22-
select * from #t;
19+
openrowset(bulk 'C:\Work\git\azure-sql-db-vector-search\DiskANN\Wikipedia\reference-embedding.json', single_clob) as j)
20+
21+
insert into dbo.wikipedia_search_vectors (id, q, v)
22+
select 1, * from openjson(@j) with
23+
(
24+
[q] nvarchar(max) '$."source-text"',
25+
[v] nvarchar(max) '$."embedding-vector"' as json
26+
)
27+
go
28+
29+
select * from dbo.wikipedia_search_vectors;
2330
go
31+
32+

DiskANN/Wikipedia/004b-generate-search-vector-github.sql

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
use WikipediaTest
1111
go
1212

13-
-- Enable external rest endpoint used by sp_invoke_external_rest_endpoint procedure
14-
exec sp_configure 'external rest endpoint enabled', 1
15-
reconfigure
16-
go
17-
18-
drop table if exists dbo.wikipedia_search_vectors
13+
-- Save embeddings for future use
14+
drop table if exists dbo.wikipedia_search_vectors;
15+
create table dbo.wikipedia_search_vectors (id int primary key, q nvarchar(max), v vector(1536))
1916
go
2017

2118
-- Download pre-generated search vector from GitHub
@@ -25,9 +22,17 @@ exec sp_invoke_external_rest_endpoint
2522
@method = 'GET',
2623
@response = @response output
2724

28-
declare @qv vector(1536) = json_query(@response, '$.result."embedding-vector"')
29-
drop table if exists #t;
30-
create table #t (v vector(1536));
31-
insert into #t values (@qv);
32-
select * from #t;
25+
declare @j json = json_query(@response, '$.result')
26+
27+
insert into dbo.wikipedia_search_vectors (id, q, v)
28+
select 1, * from openjson(@j) with
29+
(
30+
[q] nvarchar(max) '$."source-text"',
31+
[v] nvarchar(max) '$."embedding-vector"' as json
32+
)
33+
go
34+
35+
select * from dbo.wikipedia_search_vectors;
36+
go
37+
3338

0 commit comments

Comments
 (0)