Skip to content

Commit 6ce2652

Browse files
authored
Merge branch 'main' into unmute-testSecurityNativeRealm
2 parents 0b53f44 + 48f38e5 commit 6ce2652

File tree

31 files changed

+288
-80
lines changed

31 files changed

+288
-80
lines changed

distribution/docker/src/docker/dockerfiles/cloud_ess_fips/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Extract Elasticsearch artifact
2626
################################################################################
2727
28-
FROM docker.elastic.co/wolfi/chainguard-base-fips:latest@sha256:cbdc968f357706186e2b83ea1fea92382f5d51842e867a662541b67c28f4e809 AS builder
28+
FROM docker.elastic.co/wolfi/chainguard-base-fips:latest@sha256:7b18967a1329291d113228149b97382406f039171c6537b1afa4067701a6ba9e AS builder
2929
3030
# Install required packages to extract the Elasticsearch distribution
3131
RUN <%= retry.loop(package_manager, "export DEBIAN_FRONTEND=noninteractive && ${package_manager} update && ${package_manager} update && ${package_manager} add --no-cache curl") %>
@@ -104,7 +104,7 @@ WORKDIR /usr/share/elasticsearch/config
104104
# Add entrypoint
105105
################################################################################
106106

107-
FROM docker.elastic.co/wolfi/chainguard-base-fips:latest@sha256:cbdc968f357706186e2b83ea1fea92382f5d51842e867a662541b67c28f4e809
107+
FROM docker.elastic.co/wolfi/chainguard-base-fips:latest@sha256:7b18967a1329291d113228149b97382406f039171c6537b1afa4067701a6ba9e
108108

109109
RUN <%= retry.loop(package_manager,
110110
"export DEBIAN_FRONTEND=noninteractive && \n" +

distribution/docker/src/docker/dockerfiles/wolfi/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Extract Elasticsearch artifact
2626
################################################################################
2727
28-
FROM docker.elastic.co/wolfi/chainguard-base:latest@sha256:b85d54c9019ff80e88aab7d357ede3341d1442ce190173eed42ae5a116753e4e AS builder
28+
FROM docker.elastic.co/wolfi/chainguard-base:latest@sha256:46fd486e4716d592aa1ad7dad15bb3e6d0aa5b08b2070e9daec9f6b8c8c990a6 AS builder
2929
3030
# Install required packages to extract the Elasticsearch distribution
3131
RUN <%= retry.loop(package_manager, "export DEBIAN_FRONTEND=noninteractive && ${package_manager} update && ${package_manager} update && ${package_manager} add --no-cache curl") %>
@@ -80,7 +80,7 @@ RUN sed -i -e 's/ES_DISTRIBUTION_TYPE=tar/ES_DISTRIBUTION_TYPE=docker/' bin/elas
8080
# Add entrypoint
8181
################################################################################
8282

83-
FROM docker.elastic.co/wolfi/chainguard-base:latest@sha256:b85d54c9019ff80e88aab7d357ede3341d1442ce190173eed42ae5a116753e4e
83+
FROM docker.elastic.co/wolfi/chainguard-base:latest@sha256:46fd486e4716d592aa1ad7dad15bb3e6d0aa5b08b2070e9daec9f6b8c8c990a6
8484

8585
RUN <%= retry.loop(package_manager,
8686
"export DEBIAN_FRONTEND=noninteractive && \n" +

docs/changelog/136988.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 136988
2+
summary: Enable score function in release builds
3+
area: ES|QL
4+
type: feature
5+
issues: []

docs/reference/query-languages/esql/_snippets/functions/layout/score.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/functions-operators/search-functions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ for information on the limitations of full text search.
5353
:::{include} ../_snippets/functions/layout/qstr.md
5454
:::
5555

56+
:::{include} ../_snippets/functions/layout/score.md
57+
:::
58+
5659
% TERM is currently a hidden feature
5760
% To make it visible again, uncomment this and the line in
5861
lists/search-functions.md

docs/reference/query-languages/esql/kibana/definition/functions/score.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/simdvec/src/main/java/org/elasticsearch/simdvec/ESNextOSQVectorsScorer.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public class ESNextOSQVectorsScorer {
4848

4949
/** Sole constructor, called by sub-classes. */
5050
public ESNextOSQVectorsScorer(IndexInput in, byte queryBits, byte indexBits, int dimensions, int dataLength) {
51-
if (queryBits != 4 || indexBits != 1) {
52-
throw new IllegalArgumentException("Only asymmetric 4-bit query and 1-bit index supported");
51+
if (queryBits != 4 || (indexBits != 1 && indexBits != 2)) {
52+
throw new IllegalArgumentException("Only asymmetric 4-bit query and 1 or 2-bit index supported");
5353
}
5454
this.in = in;
5555
this.queryBits = queryBits;
@@ -65,15 +65,27 @@ public ESNextOSQVectorsScorer(IndexInput in, byte queryBits, byte indexBits, int
6565
public long quantizeScore(byte[] q) throws IOException {
6666
if (indexBits == 1) {
6767
if (queryBits == 4) {
68-
return quantized4BitScore(q);
68+
return quantized4BitScore(q, length);
6969
}
7070
throw new IllegalArgumentException("Only asymmetric 4-bit query supported");
7171
}
72+
if (indexBits == 2) {
73+
if (queryBits == 4) {
74+
return quantized4BitScore2BitIndex(q);
75+
}
76+
}
7277
throw new IllegalArgumentException("Only 1-bit index supported");
78+
}
7379

80+
private long quantized4BitScore2BitIndex(byte[] q) throws IOException {
81+
assert q.length == length * 2;
82+
assert length % 2 == 0 : "length must be even for 2-bit index length: " + length + " dimensions: " + dimensions;
83+
int lower = (int) quantized4BitScore(q, length / 2);
84+
int upper = (int) quantized4BitScore(q, length / 2);
85+
return lower + ((long) upper << 1);
7486
}
7587

76-
private long quantized4BitScore(byte[] q) throws IOException {
88+
private long quantized4BitScore(byte[] q, int length) throws IOException {
7789
assert q.length == length * 4;
7890
final int size = length;
7991
long subRet0 = 0;
@@ -120,6 +132,15 @@ public void quantizeScoreBulk(byte[] q, int count, float[] scores) throws IOExce
120132
}
121133
throw new IllegalArgumentException("Only asymmetric 4-bit query supported");
122134
}
135+
if (indexBits == 2) {
136+
if (queryBits == 4) {
137+
for (int i = 0; i < count; i++) {
138+
scores[i] = quantizeScore(q);
139+
}
140+
return;
141+
}
142+
throw new IllegalArgumentException("Only asymmetric 4-bit query supported");
143+
}
123144
}
124145

125146
/**
@@ -140,9 +161,9 @@ public float score(
140161
) {
141162
float ax = lowerInterval;
142163
// Here we assume `lx` is simply bit vectors, so the scaling isn't necessary
143-
float lx = (upperInterval - ax) * BIT_SCALES[indexBits];
164+
float lx = (upperInterval - ax) * BIT_SCALES[indexBits - 1];
144165
float ay = queryLowerInterval;
145-
float ly = (queryUpperInterval - ay) * BIT_SCALES[queryBits];
166+
float ly = (queryUpperInterval - ay) * BIT_SCALES[queryBits - 1];
146167
float y1 = queryComponentSum;
147168
float score = ax * ay * dimensions + ay * lx * (float) targetComponentSum + ax * ly * y1 + lx * ly * qcDist;
148169
// For euclidean, we need to invert the score and apply the additional correction, which is

libs/simdvec/src/main/java/org/elasticsearch/simdvec/ESVectorUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ public static void packAsBinary(int[] vector, byte[] packed) {
393393
IMPL.packAsBinary(vector, packed);
394394
}
395395

396+
public static void packDibit(int[] vector, byte[] packed) {
397+
if (packed.length * Byte.SIZE / 2 < vector.length) {
398+
throw new IllegalArgumentException("packed array is too small: " + packed.length * Byte.SIZE / 2 + " < " + vector.length);
399+
}
400+
IMPL.packDibit(vector, packed);
401+
}
402+
396403
/**
397404
* The idea here is to organize the query vector bits such that the first bit
398405
* of every dimension is in the first set dimensions bits, or (dimensions/8) bytes. The second,

libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/DefaultESVectorUtilSupport.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,58 @@ public void soarDistanceBulk(
321321
distances[3] = soarDistance(v1, c3, originalResidual, soarLambda, rnorm);
322322
}
323323

324+
@Override
325+
public void packDibit(int[] vector, byte[] packed) {
326+
packDibitImpl(vector, packed);
327+
}
328+
324329
@Override
325330
public void packAsBinary(int[] vector, byte[] packed) {
326331
packAsBinaryImpl(vector, packed);
327332
}
328333

334+
/**
335+
* Packs two bit vector (values 0-3) into a byte array with lower bits first.
336+
* The striding is similar to transposeHalfByte
337+
*
338+
* @param vector the input vector with values 0-3
339+
* @param packed the output packed byte array
340+
*/
341+
public static void packDibitImpl(int[] vector, byte[] packed) {
342+
int limit = vector.length - 7;
343+
int i = 0;
344+
int index = 0;
345+
for (; i < limit; i += 8, index++) {
346+
assert vector[i] >= 0 && vector[i] <= 3;
347+
assert vector[i + 1] >= 0 && vector[i + 1] <= 3;
348+
assert vector[i + 2] >= 0 && vector[i + 2] <= 3;
349+
assert vector[i + 3] >= 0 && vector[i + 3] <= 3;
350+
assert vector[i + 4] >= 0 && vector[i + 4] <= 3;
351+
assert vector[i + 5] >= 0 && vector[i + 5] <= 3;
352+
assert vector[i + 6] >= 0 && vector[i + 6] <= 3;
353+
assert vector[i + 7] >= 0 && vector[i + 7] <= 3;
354+
int lowerByte = (vector[i] & 1) << 7 | (vector[i + 1] & 1) << 6 | (vector[i + 2] & 1) << 5 | (vector[i + 3] & 1) << 4
355+
| (vector[i + 4] & 1) << 3 | (vector[i + 5] & 1) << 2 | (vector[i + 6] & 1) << 1 | (vector[i + 7] & 1);
356+
int upperByte = ((vector[i] >> 1) & 1) << 7 | ((vector[i + 1] >> 1) & 1) << 6 | ((vector[i + 2] >> 1) & 1) << 5 | ((vector[i
357+
+ 3] >> 1) & 1) << 4 | ((vector[i + 4] >> 1) & 1) << 3 | ((vector[i + 5] >> 1) & 1) << 2 | ((vector[i + 6] >> 1) & 1) << 1
358+
| ((vector[i + 7] >> 1) & 1);
359+
packed[index] = (byte) lowerByte;
360+
packed[index + packed.length / 2] = (byte) upperByte;
361+
}
362+
if (i == vector.length) {
363+
return;
364+
}
365+
int lowerByte = 0;
366+
int upperByte = 0;
367+
for (int j = 7; i < vector.length; j--, i++) {
368+
assert vector[i] >= 0 && vector[i] <= 3;
369+
lowerByte |= (vector[i] & 1) << j;
370+
upperByte |= ((vector[i] >> 1) & 1) << j;
371+
}
372+
packed[index] = (byte) lowerByte;
373+
packed[index + packed.length / 2] = (byte) upperByte;
374+
}
375+
329376
public static void packAsBinaryImpl(int[] vector, byte[] packed) {
330377
int limit = vector.length - 7;
331378
int i = 0;

libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/ESVectorUtilSupport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ void soarDistanceBulk(
6666

6767
void packAsBinary(int[] vector, byte[] packed);
6868

69+
void packDibit(int[] vector, byte[] packed);
70+
6971
void transposeHalfByte(int[] q, byte[] quantQueryByte);
7072

7173
int indexOf(byte[] bytes, int offset, int length, byte marker);

0 commit comments

Comments
 (0)