Skip to content

Commit 978cff3

Browse files
committed
Add knn retriever YAML tests
1 parent 9907aad commit 978cff3

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.retrievers/20_knn_retriever.yml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ setup:
1818
dims: 5
1919
index: true
2020
index_options:
21-
type: hnsw
21+
type: int8_hnsw
2222
similarity: l2_norm
2323

2424
- do:
@@ -73,3 +73,59 @@ setup:
7373
- match: {hits.total.value: 1}
7474
- match: {hits.hits.0._id: "3"}
7575
- match: {hits.hits.0.fields.name.0: "rabbit.jpg"}
76+
77+
---
78+
"Vector rescoring has no effect for non-quantized vectors and provides same results as non-rescored knn":
79+
- requires:
80+
reason: 'Quantized vector rescoring is required'
81+
test_runner_features: [capabilities]
82+
capabilities:
83+
- method: GET
84+
path: /_search
85+
capabilities: [knn_quantized_vector_rescore]
86+
- skip:
87+
features: "headers"
88+
89+
# Rescore
90+
- do:
91+
headers:
92+
Content-Type: application/json
93+
search:
94+
rest_total_hits_as_int: true
95+
index: index1
96+
body:
97+
knn:
98+
field: vector
99+
query_vector: [2, 2, 2, 2, 3]
100+
k: 3
101+
num_candidates: 3
102+
rescore_vector:
103+
num_candidates_factor: 1.5
104+
105+
# Get rescoring scores - hit ordering may change depending on how things are distributed
106+
- match: { hits.total: 3 }
107+
- set: { hits.hits.0._score: rescore_score0 }
108+
- set: { hits.hits.1._score: rescore_score1 }
109+
- set: { hits.hits.2._score: rescore_score2 }
110+
111+
# Exact knn via script score
112+
- do:
113+
headers:
114+
Content-Type: application/json
115+
search:
116+
rest_total_hits_as_int: true
117+
index: index1
118+
body:
119+
query:
120+
script_score:
121+
query: {match_all: {} }
122+
script:
123+
source: "1.0 / (1.0 + Math.pow(l2norm(params.query_vector, 'vector'), 2.0))"
124+
params:
125+
query_vector: [2, 2, 2, 2, 3]
126+
127+
# Compare scores as hit IDs may change depending on how things are distributed
128+
- match: { hits.total: 3 }
129+
- match: { hits.hits.0._score: $rescore_score0 }
130+
- match: { hits.hits.1._score: $rescore_score1 }
131+
- match: { hits.hits.2._score: $rescore_score2 }

0 commit comments

Comments
 (0)