-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy path05-get-similar-items.sql
More file actions
38 lines (34 loc) · 964 Bytes
/
05-get-similar-items.sql
File metadata and controls
38 lines (34 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- How many products overall?
delete from [dbo].[walmart_ecommerce_product_details] where id >= 90000;
select count(*) from dbo.[walmart_ecommerce_product_details]
go
-- Similarity Search
drop table if exists dbo.similar_items
declare @top int = 50
declare @min_similarity decimal(19,16) = 0.75
drop table if exists ##s;
declare @text nvarchar(max) = 'anything for a teenager boy passionate about racing cars? he owns an XBOX, he likes to build stuff'
declare @qv vector(1536) = ai_generate_embeddings(@text use model Ada2Embeddings)
select top(@top)
p.id,
vector_distance('cosine', @qv, embedding) as distance,
p.[product_name],
p.[description],
p.category
into
dbo.similar_items
from
dbo.[walmart_ecommerce_product_details] p
where
vector_distance('cosine', @qv, embedding) <= 1-@min_similarity
order by
distance;
;
select
*,
similarity = 1-distance
from
dbo.similar_items
order by
distance;
go