You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/DefaultESVectorUtilSupport.java
+44-5Lines changed: 44 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -204,19 +204,58 @@ static float ipFloatBitImpl(float[] q, byte[] d, int start) {
204
204
returnacc0 + acc1 + acc2 + acc3;
205
205
}
206
206
207
+
/**
208
+
* Returns the inner product (aka dot product) between the query vector {@code q}, and the data vector {@code d}.
209
+
* <p>
210
+
* The query vector should be {@link #B_QUERY}-bit quantized and striped, so that the first {@code n} bits
211
+
* of the array are the initial bits of each of the {@code n} vector dimensions; the next {@code n}
212
+
* bits are the second bits of each of the {@code n} vector dimensions, and so on
213
+
* (this algorithm is only valid for vectors with dimensions a multiple of 8).
214
+
* The striping is usually done by {@code BQSpaceUtils.transposeHalfByte}.
215
+
* <p>
216
+
* The data vector should be single-bit quantized.
217
+
*
218
+
* <h4>Dot products with bit quantization</h4>
219
+
*
220
+
* The dot product of any vector with a bit vector is a simple selector - each query vector dimension is multiplied
221
+
* by the 0 or 1 in the corresponding data vector dimension; the result is that each dimension value
222
+
* is either kept or ignored, with the dimensions that are kept then summed together.
223
+
*
224
+
* <h4>The algorithm</h4>
225
+
*
226
+
* The transposition already applied to the query vector ensures there's a 1-to-1 correspondence
227
+
* between the data vector bits and query vector bits (see {@code BQSpaceUtils.transposeHalfByte)};
228
+
* this means we can use a bitwise {@code &} to keep only the bits of the vector elements we want to sum.
229
+
* Essentially, the data vector is used as a selector for each of the striped bits of each vector dimension
230
+
* as stored, concatenated together, in {@code q}.
231
+
* <p>
232
+
* The final dot product result can be obtained by observing that the sum of each stripe of {@code n} bits
233
+
* can be computed using the bit count of that stripe. Similar to
0 commit comments