Skip to content

Commit 1a9b44c

Browse files
committed
First CSV tests
1 parent 6cc2115 commit 1a9b44c

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Tests for cosine similarity function
2+
3+
similarityWithVectorField
4+
required_capability: cosine_vector_similarity_function
5+
6+
from colors
7+
| where color != "black"
8+
| eval similarity = round(v_cosine(rgb_vector, [0, 255, 255]), 3)
9+
| sort similarity desc, color asc
10+
| limit 10
11+
| keep color, similarity
12+
;
13+
14+
color:text | similarity:double
15+
cyan | 1.0
16+
teal | 1.0
17+
turquoise | 0.989
18+
aqua marine | 0.965
19+
azure | 0.916
20+
lavender | 0.914
21+
honeydew | 0.912
22+
mint cream | 0.912
23+
gainsboro | 0.908
24+
gray | 0.908
25+
;
26+
27+
# TODO Need to implement a conversion function to convert a non-foldable row to a dense_vector
28+
similarityWithRow-Ignore
29+
required_capability: cosine_vector_similarity_function
30+
31+
row vector = [1, 2, 3]
32+
| eval similarity = round(v_cosine(vector, [0, 1, 2]), 3)
33+
| sort similarity desc, color asc
34+
| limit 10
35+
| keep color, similarity
36+
;
37+
38+
color:text | similarity:double
39+
cyan | 1.0
40+
teal | 1.0
41+
turquoise | 0.989
42+
aqua marine | 0.965
43+
azure | 0.916
44+
lavender | 0.914
45+
honeydew | 0.912
46+
mint cream | 0.912
47+
gainsboro | 0.908
48+
gray | 0.908
49+
;
50+
51+
similarityWithLiteralVectors
52+
required_capability: cosine_vector_similarity_function
53+
54+
row a = 1
55+
| eval similarity = round(v_cosine([1, 2, 3], [0, 1, 2]), 3)
56+
| keep similarity
57+
;
58+
59+
similarity:double
60+
0.978
61+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/vector/VectorWritables.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ public final class VectorWritables {
2121

2222
private VectorWritables() {
2323
// Utility class
24+
throw new UnsupportedOperationException();
2425
}
2526

2627
public static List<NamedWriteableRegistry.Entry> getNamedWritables() {
2728
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
2829

2930
if (EsqlCapabilities.Cap.KNN_FUNCTION_V2.isEnabled()) {
30-
return List.of(Knn.ENTRY);
31+
entries.add(Knn.ENTRY);
3132
}
3233
if (EsqlCapabilities.Cap.COSINE_VECTOR_SIMILARITY_FUNCTION.isEnabled()) {
3334
entries.add(CosineSimilarity.ENTRY);

0 commit comments

Comments
 (0)