@@ -13,6 +13,7 @@ let serverConfiguration = {};
13
13
const execPlan = pbb . execPlan ;
14
14
15
15
describe ( 'tests for annTopK' , function ( ) {
16
+ this . timeout ( 5000 )
16
17
before ( function ( done ) {
17
18
try {
18
19
testlib . findServerConfiguration ( serverConfiguration ) ;
@@ -27,22 +28,83 @@ describe('tests for annTopK', function () {
27
28
}
28
29
} ) ;
29
30
30
- it ( 'happy path ' , function ( done ) {
31
+ it ( 'annTopK without PlanAnnTopKOptions ' , function ( done ) {
31
32
execPlan ( p
32
33
. fromView ( 'vectors' , 'persons' , '' )
33
- . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) , 0.5 )
34
+ . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) )
34
35
. orderBy ( p . col ( 'name' ) )
35
36
)
36
37
. then ( function ( response ) {
37
- const rows = response . rows ;
38
- assert ( rows . length === 2 , 'Expecting both rows in the view to be returned.' ) ;
39
- assert ( rows [ 0 ] . name . value === 'Alice' ) ;
40
- assert ( rows [ 0 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
41
- assert ( rows [ 1 ] . name . value === 'Bob' ) ;
42
- assert ( rows [ 1 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
43
- done ( ) ;
38
+ verifyResults ( response . rows , done ) ;
39
+ } )
40
+ . catch ( error => done ( error ) ) ;
41
+ } ) ;
42
+
43
+ it ( 'annTopK with PlanAnnTopKOptions as a single string' , function ( done ) {
44
+ execPlan ( p
45
+ . fromView ( 'vectors' , 'persons' , '' )
46
+ . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) , 'onlyIndex' )
47
+ . orderBy ( p . col ( 'name' ) )
48
+ )
49
+ . then ( function ( response ) {
50
+ verifyResults ( response . rows , done ) ;
44
51
} )
45
- . catch ( done ) ;
52
+ . catch ( error => done ( error ) ) ;
53
+ } ) ;
54
+
55
+ it ( 'annTopK with PlanAnnTopKOptions as an array of string' , function ( done ) {
56
+ execPlan ( p
57
+ . fromView ( 'vectors' , 'persons' , '' )
58
+ . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) ,
59
+ [ 'onlyIndex' , "maxDistance=0.15" , "searchFactor=1.0" ] )
60
+ . orderBy ( p . col ( 'name' ) )
61
+ ) . then ( function ( response ) {
62
+ verifyResults ( response . rows , done ) ;
63
+ } ) . catch ( error => done ( error ) ) ;
46
64
} ) ;
47
65
66
+ it ( 'annTopK with PlanAnnTopKOptions as a map' , function ( done ) {
67
+ const planAnnTopKOptionsMap = new Map ( ) ;
68
+ planAnnTopKOptionsMap . set ( "maxDistance" , 0.158454656600952 ) ;
69
+ planAnnTopKOptionsMap . set ( "searchFactor" , 10.0 ) ;
70
+ execPlan ( p
71
+ . fromView ( 'vectors' , 'persons' , '' )
72
+ . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) ,
73
+ planAnnTopKOptionsMap )
74
+ . orderBy ( p . col ( 'name' ) )
75
+ )
76
+ . then ( function ( response ) {
77
+ verifyResults ( response . rows , done ) ;
78
+ } )
79
+ . catch ( error => done ( error ) ) ;
80
+ } ) ;
81
+
82
+ it ( 'annTopK with invalid PlanAnnTopKOptions' , function ( done ) {
83
+ const planAnnTopKOptionsMap = new Map ( ) ;
84
+ planAnnTopKOptionsMap . set ( 'invalid' , 10.0 ) ;
85
+ try {
86
+ execPlan ( p
87
+ . fromView ( 'vectors' , 'persons' , '' )
88
+ . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) ,
89
+ planAnnTopKOptionsMap )
90
+ . orderBy ( p . col ( 'name' ) )
91
+ ) ;
92
+ } catch ( error ) {
93
+ assert ( error . message . toString ( ) . includes ( 'options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid' ) )
94
+ done ( ) ;
95
+ }
96
+ } ) ;
97
+
98
+ function verifyResults ( rows , done ) {
99
+ try {
100
+ assert ( rows . length === 2 , 'Expecting both rows in the view to be returned.' ) ;
101
+ assert ( rows [ 0 ] . name . value === 'Alice' ) ;
102
+ assert ( rows [ 0 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
103
+ assert ( rows [ 1 ] . name . value === 'Bob' ) ;
104
+ assert ( rows [ 1 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
105
+ done ( ) ;
106
+ } catch ( error ) {
107
+ done ( error )
108
+ }
109
+ }
48
110
} ) ;
0 commit comments