mikemccand commented on code in PR #16403: URL: https://github.com/apache/lucene/pull/16403#discussion_r3615127863
########## 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 Review Comment: Don't we also reuse the HNSW graph if the number of deletions in that segment is "small" (by some measure)? And it also does some incremental work to rebuild connections around those deleted nodes or so? Should we test for this case, in case it's (separately) accidentally lost in the future? ########## lucene/core/src/java/org/apache/lucene/util/hnsw/IncrementalHnswGraphMerger.java: ########## @@ -108,7 +108,7 @@ public IncrementalHnswGraphMerger addReader( if (reader instanceof PerFieldKnnVectorsFormat.FieldsReader candidateReader) { currKnnVectorsReader = candidateReader.getFieldReader(fieldInfo.name); } - if (!(reader instanceof HnswGraphProvider)) { + if (!(currKnnVectorsReader instanceof HnswGraphProvider)) { Review Comment: Phew the best bugs come down to tiny fixes :) Did you confirm the new test case fails without these two lines fixes? ########## 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 { Review Comment: Maybe rename to `TestHnswGraphReuseDuringMerge` or so? -- 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]
