Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/145343.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
area: Vector Search
issues: []
pr: 145343
summary: Only use `MemorySegment` scorers when slices can be obtained from the `IndexInput`
type: bug
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public final class IndexInputUtils {

private IndexInputUtils() {}

/**
* Returns {@code true} if {@code MemorySegment} slices can be obtained from the specified {@link IndexInput}.
*/
public static boolean canUseSegmentSlices(IndexInput input) {
return input instanceof MemorySegmentAccessInput || input instanceof DirectAccessInput;
}

/**
* Obtains a memory segment for the next {@code length} bytes of the
* index input, passes it to {@code action}, and returns the result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.simdvec.ES93BinaryQuantizedVectorScorer;
import org.elasticsearch.simdvec.ESNextOSQVectorsScorer;
import org.elasticsearch.simdvec.MemorySegmentAccessInputAccess;
import org.elasticsearch.simdvec.internal.IndexInputUtils;
import org.elasticsearch.simdvec.internal.MemorySegmentES92Int7VectorsScorer;

import java.io.IOException;
Expand Down Expand Up @@ -50,7 +51,9 @@ public ESNextOSQVectorsScorer newESNextOSQVectorsScorer(
&& ((queryBits == 4 && (indexBits == 1 || indexBits == 2 || indexBits == 4)) || (queryBits == 7 && indexBits == 7))) {
IndexInput unwrappedInput = FilterIndexInput.unwrapOnlyTest(input);
unwrappedInput = MemorySegmentAccessInputAccess.unwrap(unwrappedInput);
return new MemorySegmentESNextOSQVectorsScorer(unwrappedInput, queryBits, indexBits, dimension, dataLength, bulkSize);
if (IndexInputUtils.canUseSegmentSlices(unwrappedInput)) {
return new MemorySegmentESNextOSQVectorsScorer(unwrappedInput, queryBits, indexBits, dimension, dataLength, bulkSize);
}
}
return new ESNextOSQVectorsScorer(input, queryBits, indexBits, dimension, dataLength, bulkSize);
}
Expand All @@ -60,7 +63,9 @@ public ES91OSQVectorsScorer newES91OSQVectorsScorer(IndexInput input, int dimens
if (PanamaESVectorUtilSupport.HAS_FAST_INTEGER_VECTORS) {
IndexInput unwrappedInput = FilterIndexInput.unwrapOnlyTest(input);
unwrappedInput = MemorySegmentAccessInputAccess.unwrap(unwrappedInput);
return new MemorySegmentES91OSQVectorsScorer(unwrappedInput, dimension, bulkSize);
if (IndexInputUtils.canUseSegmentSlices(unwrappedInput)) {
return new MemorySegmentES91OSQVectorsScorer(unwrappedInput, dimension, bulkSize);
}
}
return new OnHeapES91OSQVectorsScorer(input, dimension, bulkSize);
}
Expand All @@ -69,7 +74,11 @@ public ES91OSQVectorsScorer newES91OSQVectorsScorer(IndexInput input, int dimens
public ES92Int7VectorsScorer newES92Int7VectorsScorer(IndexInput input, int dimension, int bulkSize) {
IndexInput unwrappedInput = FilterIndexInput.unwrapOnlyTest(input);
unwrappedInput = MemorySegmentAccessInputAccess.unwrap(unwrappedInput);
return new MemorySegmentES92Int7VectorsScorer(unwrappedInput, dimension, bulkSize);

if (IndexInputUtils.canUseSegmentSlices(unwrappedInput)) {
return new MemorySegmentES92Int7VectorsScorer(unwrappedInput, dimension, bulkSize);
}
return new ES92Int7VectorsScorer(input, dimension, bulkSize);
}

@Override
Expand All @@ -78,7 +87,9 @@ public ES93BinaryQuantizedVectorScorer newES93BinaryQuantizedVectorScorer(IndexI
if (NATIVE_SUPPORTED) {
IndexInput unwrappedInput = FilterIndexInput.unwrapOnlyTest(input);
unwrappedInput = MemorySegmentAccessInputAccess.unwrap(unwrappedInput);
return new NativeBinaryQuantizedVectorScorer(unwrappedInput, dimensions, vectorLengthInBytes);
if (IndexInputUtils.canUseSegmentSlices(unwrappedInput)) {
return new NativeBinaryQuantizedVectorScorer(unwrappedInput, dimensions, vectorLengthInBytes);
}
}
return new DefaultES93BinaryQuantizedVectorScorer(input, dimensions, vectorLengthInBytes);
}
Expand Down
Loading