jeho-rpls commented on code in PR #16403:
URL: https://github.com/apache/lucene/pull/16403#discussion_r3604840582


##########
lucene/core/src/test/org/apache/lucene/index/TestHnswGraphReuse.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.KnnFloatVectorField;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.lucene.tests.util.TestUtil;
+import org.apache.lucene.util.InfoStream;
+
+/**
+ * Tests that merging deletion-free segments under the default codec reuses 
their existing HNSW
+ * graphs instead of rebuilding the merged graph from scratch. The default 
codec wires vector
+ * readers through {@code PerFieldKnnVectorsFormat.FieldsReader}, the wrapper 
that {@code
+ * IncrementalHnswGraphMerger#addReader} must unwrap for reuse to trigger.
+ *
+ * <p>The assertion keys on the InfoStream message of {@code 
MergingHnswGraphBuilder}, used by the
+ * single threaded merger that the default format selects ({@code 
numMergeWorkers} is 1).
+ */
+public class TestHnswGraphReuse extends LuceneTestCase {
+
+  private static final int DIM = 8;
+  private static final int SEGMENTS = 2;
+
+  /**
+   * Above the tiny-segment cutoff of {@code 
Lucene99HnswVectorsWriter#shouldCreateGraph} (about 650

Review Comment:
   Thanks for the review and the pointer to #15419.
   I think both approaches have pros and cons: an explicit threshold like 
#15419, and the literal default codec this test uses.
   
   The explicit form is simpler and immune to default retuning, but default 
codec pins `new Lucene99HnswVectorsFormat()`, so an explicit threshold means a 
hand-built format that no longer follows the default codec.
   
   Using the default codec here was deliberate.
   This is the only test in the tree that asserts reuse actually triggers 
(`TestHnswMergeAbort` only checks for the `"build graph"` prefix, which the 
full rebuild also emits), and the regression shipped in the default 
configuration unnoticed.
   
   The dependence you point out is the cost, but a default change there fails 
loudly, and the javadoc on the segment size documents the cutoff it needs to 
clear.



-- 
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