1
1
/*
2
2
Create database credentials to store API key
3
3
*/
4
- if exists (select * from sys.[database_scoped_credentials] where name = ' https://<your-app-name>.openai.azure.com/openai/deployments/<deployment-id> ' )
4
+ if exists (select * from sys.[database_scoped_credentials] where name = ' https://<your-app-name>.openai.azure.com' )
5
5
begin
6
- drop database scoped credential [https://<your-app-name>.openai.azure.com/openai/deployments/<deployment-id> ];
6
+ drop database scoped credential [https://<your-app-name>.openai.azure.com];
7
7
end
8
- create database scoped credential [https://<your-app-name>.openai.azure.com/openai/deployments/<deployment-id> ]
8
+ create database scoped credential [https://<your-app-name>.openai.azure.com]
9
9
with identity = ' HTTPEndpointHeaders' , secret = ' {"api-key": "<api-key>"}' ;
10
10
go
11
11
@@ -18,7 +18,7 @@ declare @payload nvarchar(max) = json_object('input': @inputText);
18
18
exec @retval = sp_invoke_external_rest_endpoint
19
19
@url = ' https://<your-app-name>.openai.azure.com/openai/deployments/<deployment-id>?api-version=2023-03-15-preview' ,
20
20
@method = ' POST' ,
21
- @credential = [https://<your-app-name>.openai.azure.com/openai/deployments/<deployment-id> ],
21
+ @credential = [https://<your-app-name>.openai.azure.com],
22
22
@payload = @payload,
23
23
@response = @response output ;
24
24
drop table if exists #response;
48
48
drop table if exists #results;
49
49
select top (50 )
50
50
v2 .article_id ,
51
- SUM (v1.[vector_value] * v2.[vector_value]) /
51
+ sum (v1.[vector_value] * v2.[vector_value]) /
52
52
(
53
- SQRT ( SUM (v1.[vector_value] * v1.[vector_value]))
53
+ sqrt ( sum (v1.[vector_value] * v1.[vector_value]))
54
54
*
55
- SQRT ( SUM (v2.[vector_value] * v2.[vector_value]))
55
+ sqrt ( sum (v2.[vector_value] * v2.[vector_value]))
56
56
) as cosine_distance
57
57
into
58
58
#results
0 commit comments