jtibshirani commented on a change in pull request #601:
URL: https://github.com/apache/lucene/pull/601#discussion_r784199665



##########
File path: 
lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorsWriter.java
##########
@@ -145,6 +139,64 @@ public void writeField(FieldInfo fieldInfo, 
KnnVectorsReader knnVectorsReader)
       throw new IllegalArgumentException(
           "Indexing an HNSW graph requires a random access vector values, got 
" + vectors);
     }
+
+    long vectorDataLength = vectorData.getFilePointer() - vectorDataOffset;
+    long vectorIndexLength = vectorIndex.getFilePointer() - vectorIndexOffset;
+    writeMeta(
+        fieldInfo,
+        vectorDataOffset,
+        vectorDataLength,
+        vectorIndexOffset,
+        vectorIndexLength,
+        count,
+        docIds);
+    writeGraphOffsets(meta, offsets);
+  }
+
+  @Override
+  public void mergeField(FieldInfo fieldInfo, MergeState mergeState) throws 
IOException {
+    if (mergeState.infoStream.isEnabled("VV")) {
+      mergeState.infoStream.message("VV", "merging " + mergeState.segmentInfo);
+    }
+
+    writeVectorDataPadding();
+    long vectorDataOffset = vectorData.getFilePointer();
+
+    // write the merged vector data to a temporary file
+    VectorValues vectors = MergedVectorValues.mergeVectorValues(fieldInfo, 
mergeState);
+    IndexOutput tempVectorData =
+        segmentWriteState.directory.createTempOutput(
+            vectorData.getName(), "temp", segmentWriteState.context);
+    int[] docIds = writeVectorData(tempVectorData, vectors);
+    tempVectorData.close();
+
+    // copy the temporary file vectors to the actual data file
+    IndexInput vectorDataInput =
+        segmentWriteState.directory.openInput(tempVectorData.getName(), 
segmentWriteState.context);
+    vectorData.copyBytes(vectorDataInput, vectorDataInput.length());
+
+    // build the graph using the temporary vector data
+    Lucene90HnswVectorsReader.OffHeapVectorValues offHeapVectors =
+        new Lucene90HnswVectorsReader.OffHeapVectorValues(
+            vectors.dimension(), docIds, vectorDataInput);
+    // count may be < vectors.size() e,g, if some documents were deleted
+    int count = docIds.length;
+    long[] offsets = new long[count];
+    long vectorIndexOffset = vectorIndex.getFilePointer();
+    writeGraph(
+        vectorIndex,
+        offHeapVectors,
+        fieldInfo.getVectorSimilarityFunction(),
+        vectorIndexOffset,
+        offsets,
+        count,
+        maxConn,
+        beamWidth);
+
+    vectorDataInput.close();
+    segmentWriteState.directory.deleteFile(tempVectorData.getName());

Review comment:
       👍 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to