Skip to content

Commit 2df6101

Browse files
committed
clean up
1 parent 771708e commit 2df6101

File tree

1 file changed

+14
-53
lines changed

1 file changed

+14
-53
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/DefaultIVFVectorsReader.java

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ CentroidIterator getCentroidIterator(FieldInfo fieldInfo, int numCentroids, Inde
8686
return getCentroidIteratorNoParent(fieldInfo, centroids, numCentroids, scorer, quantized, queryParams, globalCentroidDp);
8787
}
8888

89-
private CentroidIterator getCentroidIteratorNoParent(
89+
private static CentroidIterator getCentroidIteratorNoParent(
9090
FieldInfo fieldInfo,
9191
IndexInput centroids,
9292
int numCentroids,
@@ -96,15 +96,13 @@ private CentroidIterator getCentroidIteratorNoParent(
9696
float globalCentroidDp
9797
) throws IOException {
9898
final NeighborQueue neighborQueue = new NeighborQueue(numCentroids, true);
99-
int4QuantizedScoreBulk(
99+
score(
100100
neighborQueue,
101-
centroids,
102101
numCentroids,
103102
0,
104103
scorer,
105104
quantizeQuery,
106105
queryParams,
107-
new float[3], // targetCorrections
108106
globalCentroidDp,
109107
fieldInfo.getVectorSimilarityFunction(),
110108
new float[ES91Int4VectorsScorer.BULK_SIZE]
@@ -125,7 +123,7 @@ public long nextPostingListOffset() throws IOException {
125123
};
126124
}
127125

128-
private CentroidIterator getCentroidIteratorWithParents(
126+
private static CentroidIterator getCentroidIteratorWithParents(
129127
FieldInfo fieldInfo,
130128
IndexInput centroids,
131129
int numParents,
@@ -138,16 +136,13 @@ private CentroidIterator getCentroidIteratorWithParents(
138136
final int maxChildrenSize = centroids.readVInt();
139137
final NeighborQueue parentsQueue = new NeighborQueue(numParents, true);
140138
final float[] scores = new float[ES91Int4VectorsScorer.BULK_SIZE];
141-
final float[] centroidCorrectiveValues = new float[3];
142-
int4QuantizedScoreBulk(
139+
score(
143140
parentsQueue,
144-
centroids,
145141
numParents,
146142
0,
147143
scorer,
148144
quantizeQuery,
149145
queryParams,
150-
centroidCorrectiveValues, // targetCorrections
151146
globalCentroidDp,
152147
fieldInfo.getVectorSimilarityFunction(),
153148
scores
@@ -170,7 +165,6 @@ private CentroidIterator getCentroidIteratorWithParents(
170165
scorer,
171166
quantizeQuery,
172167
queryParams,
173-
centroidCorrectiveValues,
174168
globalCentroidDp,
175169
scores
176170
);
@@ -214,7 +208,6 @@ private void updateQueue() throws IOException {
214208
scorer,
215209
quantizeQuery,
216210
queryParams,
217-
centroidCorrectiveValues,
218211
globalCentroidDp,
219212
scores
220213
);
@@ -225,7 +218,7 @@ private void updateQueue() throws IOException {
225218
};
226219
}
227220

228-
private void populateOneChildrenGroup(
221+
private static void populateOneChildrenGroup(
229222
NeighborQueue neighborQueue,
230223
IndexInput centroids,
231224
long parentOffset,
@@ -235,38 +228,33 @@ private void populateOneChildrenGroup(
235228
ES91Int4VectorsScorer scorer,
236229
byte[] quantizeQuery,
237230
OptimizedScalarQuantizer.QuantizationResult queryParams,
238-
float[] targetCorrections,
239231
float globalCentroidDp,
240232
float[] scores
241233
) throws IOException {
242234
centroids.seek(parentOffset);
243235
int childrenOrdinal = centroids.readInt();
244236
int numChildren = centroids.readInt();
245237
centroids.seek(childrenOffset + centroidQuantizeSize * childrenOrdinal);
246-
int4QuantizedScoreBulk(
238+
score(
247239
neighborQueue,
248-
centroids,
249240
numChildren,
250241
childrenOrdinal,
251242
scorer,
252243
quantizeQuery,
253244
queryParams,
254-
targetCorrections,
255245
globalCentroidDp,
256246
fieldInfo.getVectorSimilarityFunction(),
257247
scores
258248
);
259249
}
260250

261-
private void int4QuantizedScoreBulk(
251+
private static void score(
262252
NeighborQueue neighborQueue,
263-
IndexInput centroids,
264253
int size,
265254
int scoresOffset,
266255
ES91Int4VectorsScorer scorer,
267256
byte[] quantizeQuery,
268257
OptimizedScalarQuantizer.QuantizationResult queryCorrections,
269-
float[] targetCorrections,
270258
float centroidDp,
271259
VectorSimilarityFunction similarityFunction,
272260
float[] scores
@@ -290,46 +278,19 @@ private void int4QuantizedScoreBulk(
290278
}
291279

292280
for (; i < size; i++) {
293-
float score = int4QuantizedScore(
294-
centroids,
295-
scorer,
281+
float score = scorer.score(
296282
quantizeQuery,
297-
queryCorrections,
298-
targetCorrections,
299-
centroidDp,
300-
similarityFunction
283+
queryCorrections.lowerInterval(),
284+
queryCorrections.upperInterval(),
285+
queryCorrections.quantizedComponentSum(),
286+
queryCorrections.additionalCorrection(),
287+
similarityFunction,
288+
centroidDp
301289
);
302290
neighborQueue.add(scoresOffset + i, score);
303291
}
304292
}
305293

306-
private float int4QuantizedScore(
307-
IndexInput centroids,
308-
ES91Int4VectorsScorer scorer,
309-
byte[] quantizeQuery,
310-
OptimizedScalarQuantizer.QuantizationResult queryCorrections,
311-
float[] targetCorrections,
312-
float centroidDp,
313-
VectorSimilarityFunction similarityFunction
314-
) throws IOException {
315-
float qcDist = scorer.int4DotProduct(quantizeQuery);
316-
centroids.readFloats(targetCorrections, 0, 3);
317-
final int targetComponentSum = Short.toUnsignedInt(centroids.readShort());
318-
return scorer.applyCorrections(
319-
queryCorrections.lowerInterval(),
320-
queryCorrections.upperInterval(),
321-
queryCorrections.quantizedComponentSum(),
322-
queryCorrections.additionalCorrection(),
323-
similarityFunction,
324-
centroidDp,
325-
targetCorrections[0],
326-
targetCorrections[1],
327-
targetComponentSum,
328-
targetCorrections[2],
329-
qcDist
330-
);
331-
}
332-
333294
@Override
334295
PostingVisitor getPostingVisitor(FieldInfo fieldInfo, IndexInput indexInput, float[] target, IntPredicate needsScoring)
335296
throws IOException {

0 commit comments

Comments
 (0)