1111
1212import org .apache .lucene .codecs .KnnVectorsReader ;
1313import org .apache .lucene .codecs .KnnVectorsWriter ;
14+ import org .apache .lucene .codecs .hnsw .FlatVectorScorerUtil ;
1415import org .apache .lucene .codecs .hnsw .FlatVectorsFormat ;
16+ import org .apache .lucene .codecs .lucene104 .Lucene104ScalarQuantizedVectorScorer ;
1517import org .apache .lucene .codecs .lucene104 .Lucene104ScalarQuantizedVectorsFormat ;
18+ import org .apache .lucene .codecs .lucene104 .Lucene104ScalarQuantizedVectorsReader ;
19+ import org .apache .lucene .codecs .lucene104 .Lucene104ScalarQuantizedVectorsWriter ;
1620import org .apache .lucene .codecs .lucene99 .Lucene99HnswVectorsReader ;
1721import org .apache .lucene .codecs .lucene99 .Lucene99HnswVectorsWriter ;
1822import org .apache .lucene .index .SegmentReadState ;
@@ -26,16 +30,17 @@ public class ES93HnswScalarQuantizedVectorsFormat extends AbstractHnswVectorsFor
2630
2731 static final String NAME = "ES93HnswScalarQuantizedVectorsFormat" ;
2832
29- /** The format for storing, reading, merging vectors on disk */
30- private final FlatVectorsFormat flatVectorsFormat ;
33+ static final Lucene104ScalarQuantizedVectorScorer flatVectorScorer = new Lucene104ScalarQuantizedVectorScorer (
34+ FlatVectorScorerUtil .getLucene99FlatVectorsScorer ()
35+ );
36+
37+ private final Lucene104ScalarQuantizedVectorsFormat .ScalarEncoding encoding ;
38+ private final FlatVectorsFormat rawVectorFormat ;
3139
3240 public ES93HnswScalarQuantizedVectorsFormat () {
3341 super (NAME );
34- this .flatVectorsFormat = new ES93ScalarQuantizedFlatVectorsFormat (
35- Lucene104ScalarQuantizedVectorsFormat .ScalarEncoding .SEVEN_BIT ,
36- ES93GenericFlatVectorsFormat .ElementType .STANDARD ,
37- false
38- );
42+ this .encoding = Lucene104ScalarQuantizedVectorsFormat .ScalarEncoding .SEVEN_BIT ;
43+ this .rawVectorFormat = new ES93GenericFlatVectorsFormat (ES93GenericFlatVectorsFormat .ElementType .STANDARD , false );
3944 }
4045
4146 public ES93HnswScalarQuantizedVectorsFormat (
@@ -46,7 +51,8 @@ public ES93HnswScalarQuantizedVectorsFormat(
4651 boolean useDirectIO
4752 ) {
4853 super (NAME , maxConn , beamWidth );
49- this .flatVectorsFormat = new ES93ScalarQuantizedFlatVectorsFormat (encoding , elementType , useDirectIO );
54+ this .encoding = encoding ;
55+ this .rawVectorFormat = new ES93GenericFlatVectorsFormat (elementType , useDirectIO );
5056 }
5157
5258 public ES93HnswScalarQuantizedVectorsFormat (
@@ -59,12 +65,13 @@ public ES93HnswScalarQuantizedVectorsFormat(
5965 ExecutorService mergeExec
6066 ) {
6167 super (NAME , maxConn , beamWidth , numMergeWorkers , mergeExec );
62- this .flatVectorsFormat = new ES93ScalarQuantizedFlatVectorsFormat (encoding , elementType , useDirectIO );
68+ this .encoding = encoding ;
69+ this .rawVectorFormat = new ES93GenericFlatVectorsFormat (elementType , useDirectIO );
6370 }
6471
6572 @ Override
6673 protected FlatVectorsFormat flatVectorsFormat () {
67- return flatVectorsFormat ;
74+ return rawVectorFormat ;
6875 }
6976
7077 @ Override
@@ -73,7 +80,8 @@ public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException
7380 state ,
7481 maxConn ,
7582 beamWidth ,
76- flatVectorsFormat .fieldsWriter (state ),
83+ new Lucene104ScalarQuantizedVectorsWriter (state , encoding , rawVectorFormat .fieldsWriter (state ), flatVectorScorer ) {
84+ },
7785 numMergeWorkers ,
7886 mergeExec ,
7987 0
@@ -82,6 +90,9 @@ public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException
8290
8391 @ Override
8492 public KnnVectorsReader fieldsReader (SegmentReadState state ) throws IOException {
85- return new Lucene99HnswVectorsReader (state , flatVectorsFormat .fieldsReader (state ));
93+ return new Lucene99HnswVectorsReader (
94+ state ,
95+ new Lucene104ScalarQuantizedVectorsReader (state , rawVectorFormat .fieldsReader (state ), flatVectorScorer )
96+ );
8697 }
8798}
0 commit comments