Skip to content

Commit 51eeaaf

Browse files
committed
Added sparse vector query test
1 parent 05080f9 commit 51eeaaf

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

x-pack/plugin/rank-rrf/src/yamlRestTest/resources/rest-api-spec/test/linear/20_linear_retriever_simplified.yml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ setup:
5656
type: text
5757
timestamp:
5858
type: date
59-
vector:
59+
dense_vector:
6060
type: dense_vector
6161
dims: 1
6262
index: true
6363
similarity: l2_norm
6464
index_options:
6565
type: flat
66+
sparse_vector:
67+
type: sparse_vector
6668

6769
- do:
6870
bulk:
@@ -77,7 +79,10 @@ setup:
7779
"text_1": "foo match 1",
7880
"text_2": "x match 2",
7981
"timestamp": "2000-03-30",
80-
"vector": [1]
82+
"dense_vector": [1],
83+
"sparse_vector": {
84+
"foo": 1.0
85+
}
8186
}
8287
{"index": {"_id": "2"}}
8388
{
@@ -87,7 +92,10 @@ setup:
8792
"text_1": "bar match 3",
8893
"text_2": "y match 4",
8994
"timestamp": "2010-02-08",
90-
"vector": [2]
95+
"dense_vector": [2],
96+
"sparse_vector": {
97+
"bar": 1.0
98+
}
9199
}
92100
{"index": {"_id": "3"}}
93101
{
@@ -97,7 +105,10 @@ setup:
97105
"text_1": "baz match 5",
98106
"text_2": "z match 6",
99107
"timestamp": "2024-08-08",
100-
"vector": [3]
108+
"dense_vector": [3],
109+
"sparse_vector": {
110+
"baz": 1.0
111+
}
101112
}
102113
103114
---
@@ -167,7 +178,7 @@ setup:
167178
---
168179
"Semantic match per-field boosting using the simplified format":
169180
# The mock inference services generate synthetic vectors that don't accurately represent similarity to non-identical
170-
# input, so it's hard to create a test produces intuitive results. Instead, we rely on the fact that the inference
181+
# input, so it's hard to create a test that produces intuitive results. Instead, we rely on the fact that the inference
171182
# services generate consistent vectors (i.e. same input -> same output) to demonstrate that per-field boosting on
172183
# a semantic_text field can change the result order.
173184
- do:
@@ -255,20 +266,38 @@ setup:
255266
- close_to: { hits.hits.0._score: { value: 1.0, error: 0.0001 } }
256267

257268
---
258-
"Cannot query raw vector fields":
269+
"Can query sparse vector fields":
270+
- do:
271+
search:
272+
index: test-index
273+
body:
274+
retriever:
275+
linear:
276+
fields: [ "sparse_vector" ]
277+
query: "foo"
278+
normalizer: "minmax"
279+
280+
# Lexical-only match, so max score is 1
281+
- match: { hits.total.value: 1 }
282+
- length: { hits.hits: 1 }
283+
- match: { hits.hits.0._id: "1" }
284+
- close_to: { hits.hits.0._score: { value: 1.0, error: 0.0001 } }
285+
286+
---
287+
"Cannot query dense vector fields":
259288
- do:
260289
catch: bad_request
261290
search:
262291
index: test-index
263292
body:
264293
retriever:
265294
linear:
266-
fields: [ "vector" ]
295+
fields: [ "dense_vector" ]
267296
query: "foo"
268297
normalizer: "minmax"
269298

270299
- contains: { error.root_cause.0.reason: "[linear] search failed - retrievers '[standard]' returned errors" }
271-
- contains: { error.root_cause.0.suppressed.0.failed_shards.0.reason.reason: "Field [vector] of type [dense_vector] does not support match queries" }
300+
- contains: { error.root_cause.0.suppressed.0.failed_shards.0.reason.reason: "Field [dense_vector] of type [dense_vector] does not support match queries" }
272301

273302
---
274303
"Filters are propagated":

0 commit comments

Comments
 (0)