26
26
import java .util .Arrays ;
27
27
import org .apache .lucene .codecs .BufferingKnnVectorsWriter ;
28
28
import org .apache .lucene .codecs .CodecUtil ;
29
- import org .apache .lucene .codecs .KnnVectorsReader ;
30
29
import org .apache .lucene .codecs .lucene90 .IndexedDISI ;
30
+ import org .apache .lucene .index .ByteVectorValues ;
31
31
import org .apache .lucene .index .DocsWithFieldSet ;
32
32
import org .apache .lucene .index .FieldInfo ;
33
33
import org .apache .lucene .index .FloatVectorValues ;
@@ -115,10 +115,9 @@ public final class Lucene92HnswVectorsWriter extends BufferingKnnVectorsWriter {
115
115
}
116
116
117
117
@ Override
118
- public void writeField (FieldInfo fieldInfo , KnnVectorsReader knnVectorsReader , int maxDoc )
118
+ public void writeField (FieldInfo fieldInfo , FloatVectorValues floatVectorValues , int maxDoc )
119
119
throws IOException {
120
120
long vectorDataOffset = vectorData .alignFilePointer (Float .BYTES );
121
- FloatVectorValues vectors = knnVectorsReader .getFloatVectorValues (fieldInfo .name );
122
121
123
122
IndexOutput tempVectorData =
124
123
segmentWriteState .directory .createTempOutput (
@@ -127,7 +126,7 @@ public void writeField(FieldInfo fieldInfo, KnnVectorsReader knnVectorsReader, i
127
126
boolean success = false ;
128
127
try {
129
128
// write the vector data to a temporary file
130
- DocsWithFieldSet docsWithField = writeVectorData (tempVectorData , vectors );
129
+ DocsWithFieldSet docsWithField = writeVectorData (tempVectorData , floatVectorValues );
131
130
CodecUtil .writeFooter (tempVectorData );
132
131
IOUtils .close (tempVectorData );
133
132
@@ -146,12 +145,11 @@ public void writeField(FieldInfo fieldInfo, KnnVectorsReader knnVectorsReader, i
146
145
// TODO: separate random access vector values from DocIdSetIterator?
147
146
OffHeapFloatVectorValues offHeapVectors =
148
147
new OffHeapFloatVectorValues .DenseOffHeapVectorValues (
149
- vectors .dimension (), docsWithField .cardinality (), vectorDataInput );
148
+ floatVectorValues .dimension (), docsWithField .cardinality (), vectorDataInput );
150
149
OnHeapHnswGraph graph =
151
150
offHeapVectors .size () == 0
152
151
? null
153
- : writeGraph (
154
- offHeapVectors , VectorEncoding .FLOAT32 , fieldInfo .getVectorSimilarityFunction ());
152
+ : writeGraph (offHeapVectors , fieldInfo .getVectorSimilarityFunction ());
155
153
long vectorIndexLength = vectorIndex .getFilePointer () - vectorIndexOffset ;
156
154
writeMeta (
157
155
fieldInfo ,
@@ -175,6 +173,11 @@ public void writeField(FieldInfo fieldInfo, KnnVectorsReader knnVectorsReader, i
175
173
}
176
174
}
177
175
176
+ @ Override
177
+ protected void writeField (FieldInfo fieldInfo , ByteVectorValues byteVectorValues , int maxDoc ) {
178
+ throw new UnsupportedOperationException ("byte vectors not supported in this version" );
179
+ }
180
+
178
181
/**
179
182
* Writes the vector values to the output and returns a set of documents that contains vectors.
180
183
*/
@@ -271,16 +274,14 @@ private void writeMeta(
271
274
}
272
275
273
276
private OnHeapHnswGraph writeGraph (
274
- RandomAccessVectorValues <float []> vectorValues ,
275
- VectorEncoding vectorEncoding ,
276
- VectorSimilarityFunction similarityFunction )
277
+ RandomAccessVectorValues <float []> vectorValues , VectorSimilarityFunction similarityFunction )
277
278
throws IOException {
278
279
279
280
// build graph
280
281
HnswGraphBuilder <float []> hnswGraphBuilder =
281
282
HnswGraphBuilder .create (
282
283
vectorValues ,
283
- vectorEncoding ,
284
+ VectorEncoding . FLOAT32 ,
284
285
similarityFunction ,
285
286
M ,
286
287
beamWidth ,
0 commit comments