-
Notifications
You must be signed in to change notification settings - Fork 25.7k
ESQL - Add byte element support for dense_vector data type #131863
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
Changes from 7 commits
a62c943
9317fcd
4c59ba1
475a285
ecc563f
4a40503
84d3c50
e9afc06
0402ad9
a4aca14
08a3c5c
763fe63
80b48cf
40edca3
8bd7f79
f9447f7
7d2625c
b763bcc
5bcac49
57c45b5
9abc1ea
6977dbe
7675c71
239d350
9385113
67cbb84
14ba3b0
64ca563
ee803a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,26 @@ public static void decodeDenseVector(IndexVersion indexVersion, BytesRef vectorB | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Decodes a BytesRef into the provided array of bytes | ||
| * @param vectorBR - dense vector encoded in BytesRef | ||
| * @param vector - array of bytes where the decoded vector should be stored | ||
| */ | ||
| public static void decodeDenseVector(IndexVersion indexVersion, BytesRef vectorBR, byte[] vector) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed a specific method for decoding dense vector of byte values - this is an adaptation of the existing float[] method (expand up to see it) |
||
| if (vectorBR == null) { | ||
| throw new IllegalArgumentException(DenseVectorScriptDocValues.MISSING_VECTOR_FIELD_MESSAGE); | ||
| } | ||
| if (indexVersion.onOrAfter(LITTLE_ENDIAN_FLOAT_STORED_INDEX_VERSION)) { | ||
| ByteBuffer fb = ByteBuffer.wrap(vectorBR.bytes, vectorBR.offset, vectorBR.length).order(ByteOrder.LITTLE_ENDIAN); | ||
| fb.get(vector); | ||
| } else { | ||
| ByteBuffer byteBuffer = ByteBuffer.wrap(vectorBR.bytes, vectorBR.offset, vectorBR.length); | ||
| for (int dim = 0; dim < vector.length; dim++) { | ||
| vector[dim] = byteBuffer.get(dim * vectorBR.offset); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static float[] getMultiMagnitudes(BytesRef magnitudes) { | ||
| assert magnitudes.length % Float.BYTES == 0; | ||
| float[] multiMagnitudes = new float[magnitudes.length / Float.BYTES]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| id:l, vector:dense_vector | ||
| 0, [1.0, 2.0, 3.0] | ||
| 1, [4.0, 5.0, 6.0] | ||
| 2, [9.0, 8.0, 7.0] | ||
| 3, [0.054, 0.032, 0.012] | ||
| id:l, float_vector:dense_vector, byte_vector:dense_vector | ||
carlosdelest marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 0, [1.0, 2.0, 3.0], [10, 20, 30] | ||
| 1, [4.0, 5.0, 6.0], [40, 50, 60] | ||
| 2, [9.0, 8.0, 7.0], [90, 80, 70] | ||
| 3, [0.054, 0.032, 0.012], [100, 110, 120] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A copy of the float vector tests, using the specific byte field |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| retrieveByteVectorData | ||
| required_capability: dense_vector_field_type_byte_elements | ||
|
|
||
| FROM dense_vector | ||
| | KEEP id, byte_vector | ||
| | SORT id | ||
| ; | ||
|
|
||
| id:l | byte_vector:dense_vector | ||
| 0 | [10, 20, 30] | ||
| 1 | [40, 50, 60] | ||
| 2 | [90, 80, 70] | ||
| 3 | [100, 110, 120] | ||
| ; | ||
|
|
||
| denseByteVectorWithEval | ||
| required_capability: dense_vector_field_type_byte_elements | ||
|
|
||
| FROM dense_vector | ||
| | EVAL v = byte_vector | ||
| | KEEP id, v | ||
| | SORT id | ||
| ; | ||
|
|
||
| id:l | v:dense_vector | ||
| 0 | [10, 20, 30] | ||
| 1 | [40, 50, 60] | ||
| 2 | [90, 80, 70] | ||
| 3 | [100, 110, 120] | ||
| ; | ||
|
|
||
| denseByteVectorWithRenameAndDrop | ||
| required_capability: dense_vector_field_type_byte_elements | ||
|
|
||
| FROM dense_vector | ||
| | EVAL v = byte_vector | ||
| | RENAME v AS new_vector | ||
| | DROP float_vector, byte_vector | ||
| | SORT id | ||
| ; | ||
|
|
||
| id:l | new_vector:dense_vector | ||
| 0 | [10, 20, 30] | ||
| 1 | [40, 50, 60] | ||
| 2 | [90, 80, 70] | ||
| 3 | [100, 110, 120] | ||
| ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added abstract classes to deal with common code between float and byte vector reading