-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fielddata and scripting support for byte-sized vectors (#91184)
This change adds support fielddata and subsequently scripting for byte vectors. This is a follow up to #90774 and completes the initial work for #89784.
- Loading branch information
Showing
29 changed files
with
3,202 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 91184 | ||
summary: Add fielddata and scripting support for byte-sized vectors | ||
area: Vector Search | ||
type: feature | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...ss/src/yamlRestTest/resources/rest-api-spec/test/painless/145_dense_vector_byte_basic.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
setup: | ||
- skip: | ||
version: " - 8.5.99" | ||
reason: "support for byte vectors added in 8.6" | ||
features: headers | ||
|
||
- do: | ||
indices.create: | ||
index: test-index | ||
body: | ||
settings: | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
vector: | ||
type: dense_vector | ||
element_type: byte | ||
dims: 5 | ||
indexed_vector: | ||
type: dense_vector | ||
element_type: byte | ||
dims: 5 | ||
index: true | ||
similarity: cosine | ||
|
||
- do: | ||
index: | ||
index: test-index | ||
id: "1" | ||
body: | ||
vector: [8, 5, -15, 1, -7] | ||
indexed_vector: [8, 5, -15, 1, -7] | ||
|
||
- do: | ||
index: | ||
index: test-index | ||
id: "2" | ||
body: | ||
vector: [-1, 115, -3, 4, -128] | ||
indexed_vector: [-1, 115, -3, 4, -128] | ||
|
||
- do: | ||
index: | ||
index: test-index | ||
id: "3" | ||
body: | ||
vector: [2, 18, -5, 0, -124] | ||
indexed_vector: [2, 18, -5, 0, -124] | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"Dot Product": | ||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "dotProduct(params.query_vector, 'vector')" | ||
params: | ||
query_vector: [0, 111, -13, 14, -124] | ||
|
||
- match: {hits.total: 3} | ||
|
||
- match: {hits.hits.0._id: "2"} | ||
- match: {hits.hits.0._score: 28732.0} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- match: {hits.hits.1._score: 17439.0} | ||
|
||
- match: {hits.hits.2._id: "1"} | ||
- match: {hits.hits.2._score: 1632.0} | ||
|
||
--- | ||
"Cosine Similarity": | ||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "cosineSimilarity(params.query_vector, 'vector')" | ||
params: | ||
query_vector: [0, 111, -13, 14, -124] | ||
|
||
- match: {hits.total: 3} | ||
|
||
- match: {hits.hits.0._id: "2"} | ||
- gte: {hits.hits.0._score: 0.995} | ||
- lte: {hits.hits.0._score: 0.998} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- gte: {hits.hits.1._score: 0.829} | ||
- lte: {hits.hits.1._score: 0.832} | ||
|
||
- match: {hits.hits.2._id: "1"} | ||
- gte: {hits.hits.2._score: 0.509} | ||
- lte: {hits.hits.2._score: 0.512} | ||
|
||
--- | ||
"Cosine similarity with indexed vector": | ||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "cosineSimilarity(params.query_vector, 'indexed_vector')" | ||
params: | ||
query_vector: [0, 111, -13, 14, -124] | ||
|
||
- match: {hits.total: 3} | ||
|
||
- match: {hits.hits.0._id: "2"} | ||
- gte: {hits.hits.0._score: 0.995} | ||
- lte: {hits.hits.0._score: 0.998} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- gte: {hits.hits.1._score: 0.829} | ||
- lte: {hits.hits.1._score: 0.832} | ||
|
||
- match: {hits.hits.2._id: "1"} | ||
- gte: {hits.hits.2._score: 0.509} | ||
- lte: {hits.hits.2._score: 0.512} |
99 changes: 99 additions & 0 deletions
99
...ess/src/yamlRestTest/resources/rest-api-spec/test/painless/155_dense_vector_byte_l1l2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
setup: | ||
- skip: | ||
version: " - 8.5.99" | ||
reason: "support for byte vectors added in 8.6" | ||
features: headers | ||
|
||
- do: | ||
indices.create: | ||
index: test-index | ||
body: | ||
settings: | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
my_dense_vector: | ||
type: dense_vector | ||
element_type: byte | ||
dims: 5 | ||
|
||
- do: | ||
index: | ||
index: test-index | ||
id: "1" | ||
body: | ||
my_dense_vector: [8, 5, -15, 1, -7] | ||
|
||
- do: | ||
index: | ||
index: test-index | ||
id: "2" | ||
body: | ||
my_dense_vector: [-1, 115, -3, 4, -128] | ||
|
||
- do: | ||
index: | ||
index: test-index | ||
id: "3" | ||
body: | ||
my_dense_vector: [2, 18, -5, 0, -124] | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"L1 norm": | ||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "l1norm(params.query_vector, 'my_dense_vector')" | ||
params: | ||
query_vector: [0, 111, -13, 14, -124] | ||
|
||
- match: {hits.total: 3} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- match: {hits.hits.0._score: 246.0} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- match: {hits.hits.1._score: 117.0} | ||
|
||
- match: {hits.hits.2._id: "2"} | ||
- gte: {hits.hits.2._score: 29.0} | ||
|
||
--- | ||
"L2 norm": | ||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "l2norm(params.query_vector, 'my_dense_vector')" | ||
params: | ||
query_vector: [0, 111, -13, 14, -124] | ||
|
||
- match: {hits.total: 3} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- gte: {hits.hits.0._score: 158.624} | ||
- lte: {hits.hits.0._score: 158.627} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- gte: {hits.hits.1._score: 94.407} | ||
- lte: {hits.hits.1._score: 94.41} | ||
|
||
- match: {hits.hits.2._id: "2"} | ||
- gte: {hits.hits.2._score: 15.263} | ||
- lte: {hits.hits.2._score: 15.266} |
Oops, something went wrong.