@@ -13,99 +13,89 @@ let serverConfiguration = {};
1313const execPlan = pbb . execPlan ;
1414
1515describe ( 'tests for annTopK' , function ( ) {
16- this . timeout ( 5000 )
17- before ( function ( done ) {
18- try {
19- testlib . findServerConfiguration ( serverConfiguration ) ;
20- setTimeout ( ( ) => {
21- if ( serverConfiguration . serverVersion < 12 ) {
22- this . skip ( ) ;
23- }
24- done ( ) ;
25- } , 3000 ) ;
26- } catch ( error ) {
27- done ( error ) ;
16+ this . timeout ( 5000 ) ;
17+ before ( async function ( ) {
18+ await testlib . findServerConfigurationPromise ( serverConfiguration ) ;
19+
20+ if ( serverConfiguration . serverVersion < 12 ) {
21+ this . skip ( ) ;
2822 }
2923 } ) ;
3024
31- it ( 'annTopK without PlanAnnTopKOptions' , function ( done ) {
32- execPlan ( p
25+ it ( 'annTopK without PlanAnnTopKOptions' , async function ( ) {
26+ const response = await execPlan ( p
3327 . fromView ( 'vectors' , 'persons' , '' )
3428 . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) )
3529 . orderBy ( p . col ( 'name' ) )
36- )
37- . then ( function ( response ) {
38- verifyResults ( response . rows , done ) ;
39- } )
40- . catch ( error => done ( error ) ) ;
30+ ) ;
31+ verifyResults ( response . rows ) ;
4132 } ) ;
4233
43- it ( 'annTopK with PlanAnnTopKOptions as a single string' , function ( done ) {
44- execPlan ( p
34+ it ( 'annTopK with PlanAnnTopKOptions as a single string' , async function ( ) {
35+ const response = await execPlan ( p
4536 . fromView ( 'vectors' , 'persons' , '' )
4637 . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) , 'onlyIndex' )
4738 . orderBy ( p . col ( 'name' ) )
48- )
49- . then ( function ( response ) {
50- verifyResults ( response . rows , done ) ;
51- } )
52- . catch ( error => done ( error ) ) ;
39+ ) ;
40+ verifyResults ( response . rows ) ;
5341 } ) ;
5442
55- it ( 'annTopK with PlanAnnTopKOptions as an array of string' , function ( done ) {
56- execPlan ( p
43+ it ( 'annTopK with PlanAnnTopKOptions as an array of string' , async function ( ) {
44+ const response = await execPlan ( p
5745 . fromView ( 'vectors' , 'persons' , '' )
5846 . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) ,
5947 [ 'onlyIndex' , "maxDistance=0.15" , "searchFactor=1.0" ] )
6048 . orderBy ( p . col ( 'name' ) )
61- ) . then ( function ( response ) {
62- verifyResults ( response . rows , done ) ;
63- } ) . catch ( error => done ( error ) ) ;
49+ ) ;
50+ verifyResults ( response . rows ) ;
6451 } ) ;
6552
66- it ( 'annTopK with PlanAnnTopKOptions as a map' , function ( done ) {
53+ it ( 'annTopK with PlanAnnTopKOptions as a map' , async function ( ) {
6754 const planAnnTopKOptionsMap = new Map ( ) ;
6855 planAnnTopKOptionsMap . set ( "maxDistance" , 0.158454656600952 ) ;
6956 planAnnTopKOptionsMap . set ( "searchFactor" , 10.0 ) ;
70- execPlan ( p
57+ const response = await execPlan ( p
7158 . fromView ( 'vectors' , 'persons' , '' )
7259 . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) ,
7360 planAnnTopKOptionsMap )
7461 . orderBy ( p . col ( 'name' ) )
75- )
76- . then ( function ( response ) {
77- verifyResults ( response . rows , done ) ;
78- } )
79- . catch ( error => done ( error ) ) ;
62+ ) ;
63+ verifyResults ( response . rows ) ;
8064 } ) ;
8165
82- it ( 'annTopK with invalid PlanAnnTopKOptions' , function ( done ) {
66+ it ( 'annTopK with invalid PlanAnnTopKOptions' , async function ( ) {
8367 const planAnnTopKOptionsMap = new Map ( ) ;
8468 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- done ( new Error ( 'Expecting an error to be thrown due to invalid key in options argument' ) ) ;
93- } catch ( error ) {
94- assert ( error . message . toString ( ) . includes ( 'options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid' ) )
95- done ( ) ;
96- }
69+
70+ await assert . rejects (
71+ async ( ) => {
72+ await execPlan ( p
73+ . fromView ( 'vectors' , 'persons' , '' )
74+ . annTopK ( 10 , p . col ( 'embedding' ) , p . vec . vector ( [ 1.1 , 2.2 , 3.3 ] ) , p . col ( 'distance' ) ,
75+ planAnnTopKOptionsMap )
76+ . orderBy ( p . col ( 'name' ) )
77+ ) ;
78+ } ,
79+ ( error ) => {
80+ return error . message . toString ( ) . includes ( 'options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid' ) ;
81+ }
82+ ) ;
9783 } ) ;
9884
99- function verifyResults ( rows , done ) {
100- try {
101- assert ( rows . length === 2 , 'Expecting both rows in the view to be returned.' ) ;
102- assert ( rows [ 0 ] . name . value === 'Alice' ) ;
103- assert ( rows [ 0 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
104- assert ( rows [ 1 ] . name . value === 'Bob' ) ;
105- assert ( rows [ 1 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
106- done ( ) ;
107- } catch ( error ) {
108- done ( error )
109- }
85+ function verifyResults ( rows ) {
86+
87+ assert ( Array . isArray ( rows ) , 'Expected rows to be an array' ) ;
88+ assert ( rows . length === 2 , 'Expecting both rows in the view to be returned.' ) ;
89+ assert ( rows [ 0 ] . name . value === 'Alice' ) ;
90+ assert ( rows [ 0 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
91+ assert ( rows [ 1 ] . name . value === 'Bob' ) ;
92+ assert ( rows [ 1 ] . distance . type === 'xs:float' , 'Verifying that the distance column was populated.' ) ;
93+
94+ // Verify each row has the expected structure
95+ rows . forEach ( ( row , index ) => {
96+ assert ( row . name && row . name . value , `Row ${ index } should have a name with a value` ) ;
97+ assert ( row . distance && row . distance . type === 'xs:float' ,
98+ `Row ${ index } should have a distance column of type xs:float` ) ;
99+ } ) ;
110100 }
111101} ) ;
0 commit comments