@@ -13,6 +13,7 @@ let serverConfiguration = {};
1313const execPlan = pbb . execPlan ;
1414
1515describe ( 'tests for annTopK' , function ( ) {
16+ this . timeout ( 5000 )
1617 before ( function ( done ) {
1718 try {
1819 testlib . findServerConfiguration ( serverConfiguration ) ;
@@ -27,22 +28,83 @@ describe('tests for annTopK', function () {
2728 }
2829 } ) ;
2930
30- it ( 'happy path ' , function ( done ) {
31+ it ( 'annTopK without PlanAnnTopKOptions ' , function ( done ) {
3132 execPlan ( p
3233 . 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' ) )
3435 . orderBy ( p . col ( 'name' ) )
3536 )
3637 . 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 ) ;
4451 } )
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 ) ) ;
4664 } ) ;
4765
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+ }
48110} ) ;
0 commit comments