-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Adding support for hex-encoded byte vectors on knn-search #105393
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
pmpailis
merged 24 commits into
elastic:main
from
pmpailis:feature/support_for_hex_encoded_byte_vectors
Mar 13, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
135d8d0
adding parsing for hex-encoded byte vectors
pmpailis 0e4d7e6
Update docs/changelog/105393.yaml
pmpailis 3833517
addressing PR comments - removing duplicated code and opting for swit…
pmpailis 638a737
changing visibility of parseQueryVector method
pmpailis 4d05b3f
iter
pmpailis 325a900
addressing PR comments - adding VectorData DTO
pmpailis 9933da3
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
pmpailis 5cec209
adding VectorData as a record
pmpailis 2436b03
addressing PR comments - simplifying toXContent for VectorData
pmpailis fc405a0
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
elasticmachine 2c34682
addressing PR comments - removing mocks, updating bwc tests, and supp…
pmpailis db4ba3d
Merge remote-tracking branch 'origin/main' into feature/support_for_h…
pmpailis e2d0b1d
minor iter
pmpailis 089b212
Merge remote-tracking branch 'origin/main' into feature/support_for_h…
pmpailis d0355ca
minor iter
pmpailis 9c3840e
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
pmpailis 71591fe
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
elasticmachine 98cee5e
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
elasticmachine d3a2838
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
pmpailis 80d3538
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
elasticmachine c5282d9
Merge remote-tracking branch 'origin/main' into feature/support_for_h…
pmpailis ce0b82e
Merge remote-tracking branch 'origin/main' into feature/support_for_h…
pmpailis fffd8c3
Merge branch 'main' into feature/support_for_hex_encoded_byte_vectors
pmpailis 727d747
fixing compilation error
pmpailis 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 105393 | ||
summary: Adding support for hex-encoded byte vectors on knn-search | ||
area: Vector Search | ||
type: feature | ||
issues: [] |
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
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
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
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
163 changes: 163 additions & 0 deletions
163
...t/resources/rest-api-spec/test/search.vectors/170_knn_search_hex_encoded_byte_vectors.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,163 @@ | ||
setup: | ||
- skip: | ||
version: ' - 8.13.99' | ||
reason: 'hex encoding for byte vectors was added in 8.14' | ||
|
||
- do: | ||
indices.create: | ||
index: knn_hex_vector_index | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
mappings: | ||
dynamic: false | ||
properties: | ||
my_vector_byte: | ||
type: dense_vector | ||
dims: 3 | ||
index : true | ||
similarity : l2_norm | ||
element_type: byte | ||
my_vector_float: | ||
type: dense_vector | ||
dims: 3 | ||
index: true | ||
element_type: float | ||
similarity : l2_norm | ||
|
||
# [-128, 127, 10] - is encoded as '807f0a' | ||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "1" | ||
body: | ||
my_vector_byte: "807f0a" | ||
|
||
|
||
# [0, 1, 0] - is encoded as '000100' | ||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "2" | ||
body: | ||
my_vector_byte: "000100" | ||
|
||
# [64, -10, -30] - is encoded as '40f6e2' | ||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "3" | ||
body: | ||
my_vector_byte: "40f6e2" | ||
|
||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "4" | ||
body: | ||
my_vector_float: [10.5, -10, 1024] | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"Fail to index hex-encoded vector on float field": | ||
|
||
# [-128, 127, 10] - is encoded as '807f0a' | ||
- do: | ||
catch: /Failed to parse object./ | ||
index: | ||
index: knn_hex_vector_index | ||
id: "5" | ||
body: | ||
my_vector_float: "807f0a" | ||
|
||
--- | ||
"Knn search with hex string for float field" : | ||
# [64, 10, -30] - is encoded as '400ae2' | ||
# this will be properly decoded but only because: | ||
# (i) the provided input is compatible as the values are within [Byte.MIN_VALUE, Byte.MAX_VALUE] range | ||
# (ii) we do not differentiate between byte and float fields when initially parsing a query even for hex | ||
# (iii) we support expansion from byte to float | ||
|
||
- do: | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
knn: | ||
field: my_vector_float | ||
query_vector: "400ae2" | ||
num_candidates: 100 | ||
k: 10 | ||
|
||
- match: { hits.total.value: 1 } | ||
- match: { hits.hits.0._id: "4" } | ||
|
||
--- | ||
"Knn search with hex string for byte field" : | ||
# [64, 10, -30] - is encoded as '400ae2' | ||
- do: | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
knn: | ||
field: my_vector_byte | ||
query_vector: "400ae2" | ||
num_candidates: 100 | ||
k: 10 | ||
|
||
- match: { hits.total.value: 3 } | ||
- match: { hits.hits.0._id: "3" } | ||
- match: { hits.hits.1._id: "2" } | ||
- match: { hits.hits.2._id: "1" } | ||
|
||
--- | ||
"Knn search with hex string for byte field - dimensions mismatch" : | ||
# [64, 10, -30, 10] - is encoded as '400ae20a' | ||
- do: | ||
catch: /the query vector has a different dimension \[4\] than the index vectors \[3\]/ | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
knn: | ||
field: my_vector_byte | ||
query_vector: "400ae20a" | ||
num_candidates: 100 | ||
k: 10 | ||
|
||
|
||
--- | ||
"Knn search with hex string for byte field - cannot decode string" : | ||
# '40af20a' is garbage :) | ||
- do: | ||
catch: /failed to parse field \[query_vector\]/ | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
knn: | ||
field: my_vector_byte | ||
query_vector: "40af20a" | ||
num_candidates: 100 | ||
k: 10 | ||
|
||
--- | ||
"Knn search with standard byte vector matching against hex-encoded indexed docs" : | ||
- do: | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
knn: | ||
field: my_vector_byte | ||
query_vector: [64, 10, -30] | ||
num_candidates: 100 | ||
k: 10 | ||
|
||
- match: { hits.total.value: 3 } | ||
- match: { hits.hits.0._id: "3" } | ||
- match: { hits.hits.1._id: "2" } | ||
- match: { hits.hits.2._id: "1" } |
162 changes: 162 additions & 0 deletions
162
...st/resources/rest-api-spec/test/search.vectors/175_knn_query_hex_encoded_byte_vectors.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,162 @@ | ||
setup: | ||
- skip: | ||
version: ' - 8.13.99' | ||
reason: 'hex encoding for byte vectors was added in 8.14' | ||
|
||
- do: | ||
indices.create: | ||
index: knn_hex_vector_index | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
mappings: | ||
dynamic: false | ||
properties: | ||
my_vector_byte: | ||
type: dense_vector | ||
dims: 3 | ||
index : true | ||
similarity : l2_norm | ||
element_type: byte | ||
my_vector_float: | ||
type: dense_vector | ||
dims: 3 | ||
index: true | ||
element_type: float | ||
similarity : l2_norm | ||
|
||
# [-128, 127, 10] - is encoded as '807f0a' | ||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "1" | ||
body: | ||
my_vector_byte: "807f0a" | ||
|
||
|
||
# [0, 1, 0] - is encoded as '000100' | ||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "2" | ||
body: | ||
my_vector_byte: "000100" | ||
|
||
# [64, -10, -30] - is encoded as '40f6e2' | ||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "3" | ||
body: | ||
my_vector_byte: "40f6e2" | ||
|
||
- do: | ||
index: | ||
index: knn_hex_vector_index | ||
id: "4" | ||
body: | ||
my_vector_float: [10.5, -10, 1024] | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"Fail to index hex-encoded vector on float field": | ||
|
||
# [-128, 127, 10] - is encoded as '807f0a' | ||
- do: | ||
catch: /Failed to parse object./ | ||
index: | ||
index: knn_hex_vector_index | ||
id: "5" | ||
body: | ||
my_vector_float: "807f0a" | ||
|
||
--- | ||
"Knn query with hex string for float field" : | ||
# [64, 10, -30] - is encoded as '400ae2' | ||
# this will be properly decoded but only because: | ||
# (i) the provided input is compatible as the values are within [Byte.MIN_VALUE, Byte.MAX_VALUE] range | ||
# (ii) we do not differentiate between byte and float fields when initially parsing a query even for hex | ||
# (iii) we support expansion from byte to float | ||
|
||
- do: | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
query: | ||
knn: | ||
field: my_vector_float | ||
query_vector: "400ae2" | ||
num_candidates: 100 | ||
|
||
- match: { hits.total.value: 1 } | ||
- match: { hits.hits.0._id: "4" } | ||
|
||
--- | ||
"Knn query with hex string for byte field" : | ||
# [64, 10, -30] - is encoded as '400ae2' | ||
- do: | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
query: | ||
knn: | ||
field: my_vector_byte | ||
query_vector: "400ae2" | ||
num_candidates: 100 | ||
|
||
- match: { hits.total.value: 3 } | ||
- match: { hits.hits.0._id: "3" } | ||
- match: { hits.hits.1._id: "2" } | ||
- match: { hits.hits.2._id: "1" } | ||
|
||
--- | ||
"Knn query with hex string for byte field - dimensions mismatch" : | ||
# [64, 10, -30, 10] - is encoded as '400ae20a' | ||
- do: | ||
catch: /the query vector has a different dimension \[4\] than the index vectors \[3\]/ | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
query: | ||
knn: | ||
field: my_vector_byte | ||
query_vector: "400ae20a" | ||
num_candidates: 100 | ||
|
||
--- | ||
"Knn query with hex string for byte field - cannot decode string" : | ||
# '40af20a' is garbage :) | ||
- do: | ||
catch: /failed to parse field \[query_vector\]/ | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
query: | ||
knn: | ||
field: my_vector_byte | ||
query_vector: "40af20a" | ||
num_candidates: 100 | ||
|
||
--- | ||
"Knn query with standard byte vector matching against hex-encoded indexed docs" : | ||
- do: | ||
search: | ||
index: knn_hex_vector_index | ||
body: | ||
size: 3 | ||
query: | ||
knn: | ||
field: my_vector_byte | ||
query_vector: [64, 10, -30] | ||
num_candidates: 100 | ||
|
||
- match: { hits.total.value: 3 } | ||
- match: { hits.hits.0._id: "3" } | ||
- match: { hits.hits.1._id: "2" } | ||
- match: { hits.hits.2._id: "1" } |
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.