1+ # TODO Most tests explicitly set k. Until knn function uses LIMIT as k, we need to explicitly set it to all values
2+ # in the dataset to avoid test failures due to docs allocation in different shards, which can impact results for a
3+ # top-n query at the shard level
4+
15knnSearch
26required_capability: knn_function
37
@@ -33,6 +37,7 @@ from colors metadata _score
3337| sort _score desc
3438// end::knn-function-options[]
3539| keep color, rgb_vector
40+ | limit 4
3641;
3742
3843color:text | rgb_vector:dense_vector
@@ -46,7 +51,7 @@ knnSearchWithSimilarityOption
4651required_capability: knn_function
4752
4853from colors metadata _score
49- | where knn(rgb_vector, [255,192,203], {"similarity": 40})
54+ | where knn(rgb_vector, [255,192,203], {"k": 140, " similarity": 40})
5055| sort _score desc
5156| keep color, rgb_vector
5257;
@@ -64,29 +69,31 @@ knnHybridSearch
6469required_capability: knn_function
6570
6671from colors metadata _score
67- | where match(color, "violet") or knn(rgb_vector, [238,130,238], {"boost": 10.0, "k": 5 })
72+ | where match(color, "violet") or knn(rgb_vector, [238,130,238], {"boost": 10.0, "k": 140 })
6873| sort _score desc
6974| eval round_score = round(_score, 4)
7075| keep color, rgb_vector, round_score
76+ | limit 10
7177;
7278
7379color:text | rgb_vector:dense_vector | round_score:double
74- violet | [238.0, 130.0, 238.0] | 13.9457
75- blue violet | [138.0, 43.0, 226.0] | 3.0871
76- dark violet | [148.0, 0.0, 211.0] | 3.0871
77- medium violet red | [199.0, 21.0, 133.0] | 2.5355
78- pale violet red | [219.0, 112.0, 147.0] | 2.5355
79- orchid | [218.0, 112.0, 214.0] | 0.0083
80- plum | [221.0, 160.0, 221.0] | 0.0071
81- hot pink | [255.0, 105.0, 180.0] | 0.0024
82- thistle | [216.0, 191.0, 216.0] | 0.0021
80+ violet | [238.0, 130.0, 238.0] | 13.9457
81+ blue violet | [138.0, 43.0, 226.0] | 3.0877
82+ dark violet | [148.0, 0.0, 211.0] | 3.0877
83+ pale violet red | [219.0, 112.0, 147.0] | 2.5366
84+ medium violet red | [199.0, 21.0, 133.0] | 2.5359
85+ orchid | [218.0, 112.0, 214.0] | 0.0083
86+ plum | [221.0, 160.0, 221.0] | 0.0071
87+ hot pink | [255.0, 105.0, 180.0] | 0.0024
88+ thistle | [216.0, 191.0, 216.0] | 0.0021
89+ light pink | [255.0, 182.0, 193.0] | 0.0021
8390;
8491
8592knnWithMultipleFunctions
8693required_capability: knn_function
8794
8895from colors metadata _score
89- | where knn(rgb_vector, [128,128,0]) and match(color, "olive")
96+ | where knn(rgb_vector, [128,128,0], {"k": 140} ) and match(color, "olive")
9097| sort _score desc
9198| eval round_score = round(_score, 4)
9299| keep color, rgb_vector, round_score
@@ -103,7 +110,7 @@ required_capability: knn_function
103110
104111from colors metadata _score
105112| keep rgb_vector, color, _score
106- | where knn(rgb_vector, [128,128,0])
113+ | where knn(rgb_vector, [128,128,0], {"k": 140})
107114| eval round_score = round(_score, 4)
108115| sort round_score desc, color asc
109116| keep rgb_vector, round_score
@@ -123,8 +130,9 @@ required_capability: knn_function
123130
124131from colors metadata _score
125132| drop color
126- | where knn(rgb_vector, [128,128,0])
133+ | where knn(rgb_vector, [128,128,0], {"k": 140})
127134| eval round_score = round(_score, 4)
135+ | sort round_score desc
128136| keep rgb_vector, round_score
129137| limit 5
130138;
@@ -142,80 +150,81 @@ required_capability: knn_function
142150
143151from colors metadata _score
144152| eval composed_name = locate(color, " ") > 0
145- | where knn(rgb_vector, [128,128,0])
146- | sort _score, color desc
153+ | where knn(rgb_vector, [128,128,0], {"k": 140})
154+ | sort _score desc , color asc
147155| keep color, composed_name
156+ | limit 10
148157;
149158
150159color:text | composed_name:boolean
151- peru | false
152- yellow green | true
153- chocolate | false
154- dim gray | true
155- saddle brown | true
156- sienna | false
157- dark golden rod | true
158- dark olive green | true
159- olive drab | true
160- olive | false
160+ olive | false
161+ olive drab | true
162+ dark olive green | true
163+ dark golden rod | true
164+ sienna | false
165+ saddle brown | true
166+ dim gray | true
167+ chocolate | false
168+ yellow green | true
169+ peru | false
161170;
162171
163172knnWithConjunction
164173required_capability: knn_function
165174
166175# TODO We need kNN prefiltering here so we get more candidates that pass the filter
167176from colors metadata _score
168- | where knn(rgb_vector, [255,255,238]) and hex_code like "#FFF*"
177+ | where knn(rgb_vector, [255,255,238], {"k": 140}) and hex_code like "#FFF*"
178+ | sort _score desc, color asc
169179| keep color, hex_code, rgb_vector
170180;
171181ignoreOrder:true
172182
173- color:text | hex_code: keyword | rgb_vector:dense_vector
174- light yellow | #FFFFE0 | [255.0, 255.0, 224.0]
175- lavender blush | #FFF0F5 | [255.0, 240.0, 245.0]
176- sea shell | #FFF5EE | [255.0, 245.0, 238.0]
177- floral white | #FFFAF0 | [255.0, 250.0, 240.0]
178- ivory | #FFFFF0 | [255.0, 255.0, 240.0]
179- snow | #FFFAFA | [255.0, 250.0, 250.0]
180- white | #FFFFFF | [255.0, 255.0, 255.0]
183+ color:text | hex_code:keyword | rgb_vector:dense_vector
184+ corn silk | #FFF8DC | [255.0, 248.0, 220.0]
185+ floral white | #FFFAF0 | [255.0, 250.0, 240.0]
186+ ivory | #FFFFF0 | [255.0, 255.0, 240.0]
187+ lavender blush | #FFF0F5 | [255.0, 240.0, 245.0]
188+ lemon chiffon | #FFFACD | [255.0, 250.0, 205.0]
189+ light yellow | #FFFFE0 | [255.0, 255.0, 224.0]
190+ sea shell | #FFF5EE | [255.0, 245.0, 238.0]
191+ snow | #FFFAFA | [255.0, 250.0, 250.0]
192+ white | #FFFFFF | [255.0, 255.0, 255.0]
193+ yellow | #FFFF00 | [255.0, 255.0, 0.0]
181194;
182195
183196knnWithDisjunctionAndFiltersConjunction
184197required_capability: knn_function
185198
186199# TODO We need kNN prefiltering here so we get more candidates that pass the filter
187200from colors metadata _score
188- | where (knn(rgb_vector, [0,255,255]) or knn(rgb_vector, [128, 0, 255])) and primary == true
201+ | where (knn(rgb_vector, [0,255,255], {"k": 140} ) or knn(rgb_vector, [128, 0, 255], {"k": 140} )) and primary == true
189202| keep color, rgb_vector, _score
203+ | sort _score desc, color asc
204+ | limit 10
190205;
191206
192207color:text | rgb_vector:dense_vector | _score:double
193- cyan | [0.0, 255.0, 255.0] | 1.0
194- blue | [0.0, 0.0, 255.0] | 9.922293975250795E-5
195- ;
196-
197- knnWithDisjunctionAndConjunction
198- required_capability: knn_function
199- required_capability: full_text_functions_disjunctions
200-
201- # TODO We need kNN prefiltering here so we get more candidates that pass the filter
202- from colors metadata _score
203- | where (knn(rgb_vector, [0,255,255]) or knn(rgb_vector, [0, 0, 255])) and knn(rgb_vector, [0, 255, 0])
204- | keep color, rgb_vector, _score
205- ;
206-
207- color:text | rgb_vector:dense_vector | _score:double
208- medium spring green | [0.0, 250.0, 154.0] | 1.6871128173079342E-4
208+ red | [255.0, 0.0, 0.0] | 2.1994377675582655E-5
209+ yellow | [255.0, 255.0, 0.0] | 1.867113314801827E-5
210+ green | [0.0, 128.0, 0.0] | 2.9579907277366146E-5
211+ cyan | [0.0, 255.0, 255.0] | 1.000016689300537
212+ blue | [0.0, 0.0, 255.0] | 1.1921183613594621E-4
213+ magenta | [255.0, 0.0, 255.0] | 7.578763325000182E-5
214+ black | [0.0, 0.0, 0.0] | 2.6632071239873767E-5
215+ gray | [128.0, 128.0, 128.0] | 6.426929758163169E-5
216+ white | [255.0, 255.0, 255.0] | 3.5320219467394054E-5
209217;
210218
211219knnWithNonPushableConjunction
212220required_capability: knn_function
213221
214222from colors metadata _score
215223| eval composed_name = locate(color, " ") > 0
216- | where knn(rgb_vector, [128,128,0]) and composed_name == false
224+ | where knn(rgb_vector, [128,128,0], {"k": 140} ) and composed_name == false
217225| eval round_score = round(_score, 4)
218226| keep color, composed_name, round_score
227+ | sort round_score desc, color asc
219228;
220229
221230color:text | composed_name:boolean | round_score:double
@@ -229,7 +238,7 @@ testKnnWithNonPushableDisjunctions
229238required_capability: knn_function
230239
231240from colors metadata _score
232- | where knn(rgb_vector, [128,128,0], {"k": 5 }) or length(color) > 17
241+ | where knn(rgb_vector, [128,128,0], {"k": 140, "similarity": 30 }) or length(color) > 17
233242| sort _score desc, color asc
234243| eval round_score = round(_score, 4)
235244| keep color, round_score
@@ -238,9 +247,6 @@ from colors metadata _score
238247color:text | round_score:double
239248olive | 1.0
240249olive drab | 0.0014
241- dark olive green | 4.0E-4
242- dark golden rod | 3.0E-4
243- sienna | 3.0E-4
244250light golden rod yellow | 0.0
245251medium aqua marine | 0.0
246252medium spring green | 0.0
@@ -250,25 +256,16 @@ testKnnWithNonPushableDisjunctionsOnComplexExpressions
250256required_capability: knn_function
251257
252258from colors metadata _score
253- | where (knn(rgb_vector, [128,128,0]) and length(color) > 12 ) or (knn(rgb_vector, [128,0,128]) and primary == false)
259+ | where (knn(rgb_vector, [128,128,0], {"k": 140, "similarity": 40} ) and length(color) > 5 ) or (knn(rgb_vector, [128,0,128], {"k": 140, "similarity": 40} ) and primary == false)
254260| sort _score desc
255261| eval round_score = round(_score, 4)
256262| keep color, primary, round_score
257263;
258264
259- color: text | primary: boolean | round_score: double
260- purple | false | 1.0
261- dark magenta | false | 0.0045
262- dark olive green | false | 4.0E-4
263- indigo | false | 4.0E-4
264- dark golden rod | false | 3.0E-4
265- dim gray | false | 3.0E-4
266- dark slate blue | false | 2.0E-4
267- medium violet red | false | 2.0E-4
268- dark orchid | false | 1.0E-4
269- dark violet | false | 1.0E-4
270- brown | false | 1.0E-4
271- blue violet | false | 1.0E-4
265+ color:text | primary:boolean | round_score:double
266+ purple | false | 1.0
267+ dark magenta | false | 0.0045
268+ olive drab | false | 0.0014
272269;
273270
274271testKnnInStatsNonPushable
0 commit comments