|
22 | 22 | import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier; |
23 | 23 | import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer; |
24 | 24 | import org.apache.lucene.util.quantization.QuantizedByteVectorValues; |
| 25 | +import org.apache.lucene.util.quantization.ScalarQuantizedVectorSimilarity; |
25 | 26 | import org.apache.lucene.util.quantization.ScalarQuantizer; |
26 | 27 |
|
27 | 28 | import java.io.IOException; |
|
47 | 48 | import static org.hamcrest.Matchers.equalTo; |
48 | 49 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
49 | 50 |
|
50 | | -// @com.carrotsearch.randomizedtesting.annotations.Repeat(iterations = 100) |
51 | | -public class VectorScorerFactoryTests extends AbstractVectorTestCase { |
| 51 | +public class Int7SQVectorScorerFactoryTests extends AbstractVectorTestCase { |
52 | 52 |
|
53 | 53 | // bounds of the range of values that can be seen by int7 scalar quantized vectors |
54 | 54 | static final byte MIN_INT7_VALUE = 0; |
@@ -107,7 +107,7 @@ void testSimpleImpl(long maxChunkSize) throws IOException { |
107 | 107 | scorer.setScoringOrdinal(0); |
108 | 108 | assertThat(scorer.score(1), equalTo(expected)); |
109 | 109 |
|
110 | | - if (Runtime.version().feature() >= 22) { |
| 110 | + if (supportsHeapSegments()) { |
111 | 111 | var qScorer = factory.getInt7SQVectorScorer(VectorSimilarityType.of(sim), values, query1).get(); |
112 | 112 | assertThat(qScorer.score(1), equalTo(expected)); |
113 | 113 | } |
@@ -229,11 +229,11 @@ void testRandomSupplier(long maxChunkSize, Function<Integer, byte[]> byteArraySu |
229 | 229 | } |
230 | 230 |
|
231 | 231 | public void testRandomScorer() throws IOException { |
232 | | - testRandomScorerImpl(MMapDirectory.DEFAULT_MAX_CHUNK_SIZE, VectorScorerFactoryTests.FLOAT_ARRAY_RANDOM_FUNC); |
| 232 | + testRandomScorerImpl(MMapDirectory.DEFAULT_MAX_CHUNK_SIZE, Int7SQVectorScorerFactoryTests.FLOAT_ARRAY_RANDOM_FUNC); |
233 | 233 | } |
234 | 234 |
|
235 | 235 | public void testRandomScorerMax() throws IOException { |
236 | | - testRandomScorerImpl(MMapDirectory.DEFAULT_MAX_CHUNK_SIZE, VectorScorerFactoryTests.FLOAT_ARRAY_MAX_FUNC); |
| 236 | + testRandomScorerImpl(MMapDirectory.DEFAULT_MAX_CHUNK_SIZE, Int7SQVectorScorerFactoryTests.FLOAT_ARRAY_MAX_FUNC); |
237 | 237 | } |
238 | 238 |
|
239 | 239 | public void testRandomScorerChunkSizeSmall() throws IOException { |
@@ -461,6 +461,19 @@ QuantizedByteVectorValues vectorValues(int dims, int size, IndexInput in, Vector |
461 | 461 | return new OffHeapQuantizedByteVectorValues.DenseOffHeapVectorValues(dims, size, sq, false, sim, null, slice); |
462 | 462 | } |
463 | 463 |
|
| 464 | + /** Computes the score using the Lucene implementation. */ |
| 465 | + public static float luceneScore( |
| 466 | + VectorSimilarityType similarityFunc, |
| 467 | + byte[] a, |
| 468 | + byte[] b, |
| 469 | + float correction, |
| 470 | + float aOffsetValue, |
| 471 | + float bOffsetValue |
| 472 | + ) { |
| 473 | + var scorer = ScalarQuantizedVectorSimilarity.fromVectorSimilarity(VectorSimilarityType.of(similarityFunc), correction, (byte) 7); |
| 474 | + return scorer.score(a, aOffsetValue, b, bOffsetValue); |
| 475 | + } |
| 476 | + |
464 | 477 | RandomVectorScorerSupplier luceneScoreSupplier(QuantizedByteVectorValues values, VectorSimilarityFunction sim) throws IOException { |
465 | 478 | return new Lucene99ScalarQuantizedVectorScorer(null).getRandomVectorScorerSupplier(sim, values); |
466 | 479 | } |
|
0 commit comments