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