From 4c65c8affa0c670dd0db040a12509ce3df514530 Mon Sep 17 00:00:00 2001 From: carlosdelest Date: Thu, 5 Dec 2024 21:55:48 +0100 Subject: [PATCH] Fix sneaky bug on iterator --- .../mapper/vectors/VectorSimilarityFloatValueSource.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java b/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java index 540533a1b2b7d..04b2a906d6dad 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java @@ -50,18 +50,14 @@ public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws final KnnVectorValues.DocIndexIterator iterator = vectorValues.iterator(); return new DoubleValues() { - private int docId = -1; - @Override public double doubleValue() throws IOException { vectorOpsCount++; - return vectorSimilarityFunction.compare(target, vectorValues.vectorValue(docId)); + return vectorSimilarityFunction.compare(target, vectorValues.vectorValue(iterator.index())); } @Override public boolean advanceExact(int doc) throws IOException { - assert doc > iterator.docID(); - docId = doc; return doc >= iterator.docID() && iterator.docID() != DocIdSetIterator.NO_MORE_DOCS && iterator.advance(doc) == doc; } };