[BugFix] Fix IOContext, Scorer, and max dimension for Lucene SQ 1 bit #3203
[BugFix] Fix IOContext, Scorer, and max dimension for Lucene SQ 1 bit #3203naveentatikonda wants to merge 5 commits intoopensearch-project:3.6from
Conversation
5a0e53f to
a6aa0cb
Compare
...pensearch/knn/index/codec/KNN1040Codec/PrefetchingLucene104ScalarQuantizedVectorsFormat.java
Outdated
Show resolved
Hide resolved
.../org/opensearch/knn/index/codec/scorer/PrefetchableLucene104ScalarQuantizedVectorScorer.java
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.6 #3203 +/- ##
============================================
- Coverage 83.18% 83.16% -0.03%
- Complexity 4215 4234 +19
============================================
Files 453 456 +3
Lines 15455 15507 +52
Branches 1972 1974 +2
============================================
+ Hits 12857 12897 +40
- Misses 1805 1814 +9
- Partials 793 796 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
.../org/opensearch/knn/index/codec/scorer/PrefetchableLucene104ScalarQuantizedVectorScorer.java
Outdated
Show resolved
Hide resolved
...opensearch/knn/index/codec/scorer/PrefetchableLucene104ScalarQuantizedVectorScorerTests.java
Outdated
Show resolved
Hide resolved
...pensearch/knn/index/codec/KNN1040Codec/PrefetchingLucene104ScalarQuantizedVectorsFormat.java
Outdated
Show resolved
Hide resolved
a6aa0cb to
7c38f8a
Compare
7c38f8a to
0bad74a
Compare
11d6dea to
1c4ab75
Compare
0bad74a to
f210f85
Compare
856a970 to
72d68c4
Compare
...ava/org/opensearch/knn/index/codec/KNN1040Codec/Faiss1040PrefetchSupportKnnVectorReader.java
Outdated
Show resolved
Hide resolved
...ava/org/opensearch/knn/index/codec/KNN1040Codec/Faiss1040PrefetchSupportKnnVectorReader.java
Outdated
Show resolved
Hide resolved
...in/java/org/opensearch/knn/index/codec/KNN1040Codec/KNN1040ScalarQuantizedVectorsFormat.java
Show resolved
Hide resolved
...in/java/org/opensearch/knn/index/codec/KNN1040Codec/KNN1040ScalarQuantizedVectorsFormat.java
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNN1040Codec/ScalarQuantizedFloatVectorValues.java
Show resolved
Hide resolved
52448ab to
3daeb46
Compare
3daeb46 to
87eb1f3
Compare
|
This is the test that is failing Thanks @jack-hung-lgtm for adding this IT which helped to catch a bug in cosine similarity space type with Bulk SIMD. Will keep this PR on hold until the issue is resolved. This logic was missed in our Bulk SIMD implementation of cosine similarity. We are working on resolving the issue. Thanks! |
3a8748b to
fef69bc
Compare
fef69bc to
ef7fc5e
Compare
Signed-off-by: Naveen Tatikonda <navtat@amazon.com> Address Review Comments Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
Signed-off-by: Naveen Tatikonda <navtat@amazon.com> Address Review Comments Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
ef7fc5e to
324030b
Compare
| // For cosine similarity, Lucene's OptimizedScalarQuantizer asserts the query is a unit vector. | ||
| // FAISS already normalizes the query, so we only normalize if it isn't already. But, we need to | ||
| // normalize the query vector when using Lucene engine. | ||
| KNN1040ScalarQuantizedUtils.normalizeIfNeeded(targetCopy, similarityFunction); |
There was a problem hiding this comment.
If we end up choosing normalizing query vector within flat vector scorer, then can we avoid checking whether it's an unit vector?
We can just normalize targetCopy, as it's idempotent.
Normalize(Normalize(Normalize(vector))) == Normalize(vector)
There was a problem hiding this comment.
Also curious, why we are not normalizing query vector in QueryBuilder side likewise we're doing for other cosine index type?
src/main/java/org/opensearch/knn/index/codec/KNN1040Codec/KNN1040ScalarQuantizedUtils.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
| * <p>This is used by both the Lucene SQ flat path ({@link KNN1040ScalarQuantizedVectorsFormat}) | ||
| * and the Lucene SQ HNSW path ({@link KNN1040HnswScalarQuantizedVectorsFormat}). | ||
| */ | ||
| final class KNN1040ReadAdviceOverridingDirectory extends FilterDirectory { |
There was a problem hiding this comment.
This is not needed because in OpenSearch version > 3.1 and less than equal to 3.6 readAdvise is not honored
There was a problem hiding this comment.
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Directory wrapper that enforces {@link DataAccessHint#SEQUENTIAL} for {@code .veb} files |
There was a problem hiding this comment.
NIT : .veb -> .veq
Description
This PR includes the following bug fixes for Lucene SQ 1 bit (both HNSW and Flat):
.veqfile to useSEQUENTIALinstead ofRANDOM16000instead of1024Changes
Add
KNN1040ScalarQuantizedVectorsFormatandKNN1040HnswScalarQuantizedVectorsFormatto use custom bulk SIMD scorer for theFLATandHNSWindex typeWire
KNN1040ScalarQuantizedVectorsFormatandKNN1040HnswScalarQuantizedVectorsFormatintoKNN1040PerFieldKnnVectorsFormatfor the FLAT resolverAdd unit tests for the new
KNN1040ScalarQuantizedVectorsFormatandKNN1040HnswScalarQuantizedVectorsFormatand codec resolverRename
Faiss104ScalarQuantizedVectorScorer.java => KNN1040ScalarQuantizedVectorScorer.javaandFaiss1040ScalarQuantizedUtils.java => KNN1040ScalarQuantizedUtils.javaAdd
KNN1040ReadAdviceOverridingDirectorythat wraps the segment directory and overridesIOContextto useDataAccessHint.SEQUENTIALfor.veq(quantized vector data) files. Lucene's default reader opens these withDataAccessHint.RANDOM, which disables OS read-ahead prefetching. Since quantized vector data is read sequentially during search, switching to sequential access improves I/O throughput. Raw vector data (.vec) retains random access for rescoring.Override
fieldsReaderinKNN1040ScalarQuantizedVectorsFormatto wrapstate.directorywithKNN1040ReadAdviceOverridingDirectorybefore passing it toLucene104ScalarQuantizedVectorsReader. The HNSW path (KNN1040HnswScalarQuantizedVectorsFormat) inherits this behavior via delegation.Add unit tests for
KNN1040ReadAdviceOverridingDirectory,KNN1040ScalarQuantizedVectorsFormatTests, andKNN1040HnswScalarQuantizedVectorsFormatTeststo verify.veqfiles are opened withSEQUENTIALhintRelated Issues
#3178
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.