-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathVectorFunctionTests170.sql
More file actions
55 lines (50 loc) · 1.2 KB
/
VectorFunctionTests170.sql
File metadata and controls
55 lines (50 loc) · 1.2 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
DECLARE @qv VECTOR(1536) = AI_GENERATE_EMBEDDINGS(N'Pink Floyd music style' USE MODEL Ada2Embeddings);
SELECT
t.id, s.distance, t.title
FROM
VECTOR_SEARCH(
TABLE = [dbo].[wikipedia_articles_embeddings] as t,
COLUMN = [content_vector],
SIMILAR_TO = @qv,
METRIC = 'cosine',
TOP_N = 10
) AS s
ORDER BY s.distance
SELECT
*
FROM
VECTOR_SEARCH(
TABLE = wikipedia_articles_embeddings,
COLUMN = dbo.wikipedia_articles_embeddings.content_vector,
SIMILAR_TO = @qv,
METRIC = 'dot',
TOP_N = 10
)
ORDER BY distance
-- Test TOP_N with parameter
DECLARE @k INT = 5;
SELECT
t.id, s.distance, t.title
FROM
VECTOR_SEARCH(
TABLE = graphnode AS src,
COLUMN = embedding,
SIMILAR_TO = @qv,
METRIC = 'cosine',
TOP_N = @k
) AS ann
ORDER BY s.distance
-- Test TOP_N with outer reference
SELECT outerref.id
FROM graphnode outerref
WHERE outerref.id IN (
SELECT src.id
FROM
VECTOR_SEARCH(
TABLE = graphnode AS src,
COLUMN = embedding,
SIMILAR_TO = @qv,
METRIC = 'cosine',
TOP_N = outerref.max_results
) AS ann
)