-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Adds maxSim
functions for multi_dense_vector fields
#116993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
elasticsearchmachine
merged 9 commits into
elastic:main
from
benwtrent:feature/add-max-sim
Nov 20, 2024
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cd79489
Add new maxSim functions for multi-vector fields
benwtrent ba0fd5f
iter
benwtrent 75458e0
iter
benwtrent 3d2be40
Adding tests
benwtrent 2c7bca9
Merge remote-tracking branch 'upstream/main' into feature/add-max-sim
benwtrent f5c43fe
fixing maxSim and tests
benwtrent 5e01350
addressig pr comments
benwtrent 87cba85
Merge remote-tracking branch 'upstream/main' into feature/add-max-sim
benwtrent 97b42ee
Merge branch 'main' into feature/add-max-sim
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
206 changes: 206 additions & 0 deletions
206
...src/yamlRestTest/resources/rest-api-spec/test/painless/141_multi_dense_vector_max_sim.yml
This file contains hidden or 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,206 @@ | ||
setup: | ||
- requires: | ||
capabilities: | ||
- method: POST | ||
path: /_search | ||
capabilities: [ multi_dense_vector_script_max_sim ] | ||
test_runner_features: capabilities | ||
reason: "Support for multi dense vector max-sim functions capability required" | ||
- skip: | ||
features: headers | ||
|
||
- do: | ||
indices.create: | ||
index: test-index | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
mappings: | ||
properties: | ||
vector: | ||
type: multi_dense_vector | ||
dims: 5 | ||
byte_vector: | ||
type: multi_dense_vector | ||
dims: 5 | ||
element_type: byte | ||
bit_vector: | ||
type: multi_dense_vector | ||
dims: 40 | ||
element_type: bit | ||
- do: | ||
index: | ||
index: test-index | ||
id: "1" | ||
body: | ||
vector: [[230.0, 300.33, -34.8988, 15.555, -200.0], [-0.5, 100.0, -13, 14.8, -156.0]] | ||
byte_vector: [[8, 5, -15, 1, -7], [-1, 115, -3, 4, -128]] | ||
bit_vector: [[8, 5, -15, 1, -7], [-1, 115, -3, 4, -128]] | ||
|
||
- do: | ||
index: | ||
index: test-index | ||
id: "3" | ||
body: | ||
vector: [[0.5, 111.3, -13.0, 14.8, -156.0]] | ||
byte_vector: [[2, 18, -5, 0, -124]] | ||
bit_vector: [[2, 18, -5, 0, -124]] | ||
|
||
- do: | ||
indices.refresh: {} | ||
--- | ||
"Test max-sim dot product scoring": | ||
- skip: | ||
features: close_to | ||
|
||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "maxSimDotProduct(params.query_vector, 'vector')" | ||
params: | ||
query_vector: [[1, 2, 1, 1, 1]] | ||
mayya-sharipova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- match: {hits.total: 2} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- close_to: {hits.hits.0._score: {value: 656.61615, error: 0.01}} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- close_to: {hits.hits.1._score: {value: 68.90001, error: 0.01}} | ||
|
||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "maxSimDotProduct(params.query_vector, 'byte_vector')" | ||
params: | ||
query_vector: [[1, 2, 1, 1, 0]] | ||
|
||
- match: {hits.total: 2} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- close_to: {hits.hits.0._score: {value: 234, error: 0.01}} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- close_to: {hits.hits.1._score: {value: 33, error: 0.01}} | ||
|
||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "maxSimDotProduct(params.query_vector, 'bit_vector')" | ||
params: | ||
query_vector: [[1, 2, 1, 1, 0]] | ||
|
||
- match: {hits.total: 2} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- close_to: {hits.hits.0._score: {value: 5, error: 0.01}} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- close_to: {hits.hits.1._score: {value: 2, error: 0.01}} | ||
|
||
# doing max-sim dot product with a vector where the stored bit vectors are used as masks | ||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "maxSimDotProduct(params.query_vector, 'bit_vector')" | ||
params: | ||
query_vector: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]] | ||
- match: {hits.total: 2} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- close_to: {hits.hits.0._score: {value: 349, error: 0.01}} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- close_to: {hits.hits.1._score: {value: 125, error: 0.01}} | ||
--- | ||
"Test max-sim inv hamming scoring": | ||
- skip: | ||
features: close_to | ||
|
||
# inv hamming doesn't apply to float vectors | ||
- do: | ||
catch: bad_request | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "maxSimInvHamming(params.query_vector, 'vector')" | ||
params: | ||
query_vector: [[1, 2, 1, 1, 1]] | ||
|
||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "maxSimInvHamming(params.query_vector, 'byte_vector')" | ||
params: | ||
query_vector: [[1, 2, 1, 1, 1]] | ||
|
||
- match: {hits.total: 2} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- close_to: {hits.hits.0._score: {value: 1.125, error: 0.01}} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- close_to: {hits.hits.1._score: {value: 0.675, error: 0.01}} | ||
|
||
- do: | ||
headers: | ||
Content-Type: application/json | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "maxSimInvHamming(params.query_vector, 'bit_vector')" | ||
params: | ||
query_vector: [[1, 2, 1, 1, 1]] | ||
|
||
- match: {hits.total: 2} | ||
|
||
- match: {hits.hits.0._id: "1"} | ||
- close_to: {hits.hits.0._score: {value: 1.125, error: 0.01}} | ||
|
||
- match: {hits.hits.1._id: "3"} | ||
- close_to: {hits.hits.1._score: {value: 0.675, error: 0.01}} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.