kaivalnp commented on code in PR #15979: URL: https://github.com/apache/lucene/pull/15979#discussion_r3668223099
########## lucene/core/src/java/org/apache/lucene/codecs/lucene106/dedup/DedupGroup.java: ########## @@ -0,0 +1,105 @@ +/* + * 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.codecs.lucene106.dedup; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.lucene.internal.hppc.LongIntHashMap; +import org.apache.lucene.internal.hppc.ObjectCursor; +import org.apache.lucene.util.Accountable; + +/** + * Interns vectors so that each distinct value is stored once. {@link #addUnique} returns the group + * ordinal for a vector, adding it (via {@link #copy}) only if not already present. Callers with the + * same {@code (dimension, encoding)} share a group, so an identical vector across fields is stored + * a single time. + * + * <p>Not thread-safe; a group is confined to the writer that created it. + * + * @lucene.experimental + */ +abstract sealed class DedupGroup<T> implements Accountable + permits DedupFlushContext.ByteGroup, + DedupFlushContext.FloatGroup, + DedupFlushContext.Float16Group, + DedupMergeContext.DedupMergeGroup { + + /** + * Map for vector hash -> group ord. Only a hint and not the ground truth due to possibility of + * hash collisions, where a full equality check must be performed. + */ + private final LongIntHashMap hashToOrdHint; + + private final List<T> vectors; + + private final ObjectCursor<T> current; // reuse from addUnique + + DedupGroup() { + this.hashToOrdHint = new LongIntHashMap(); + this.vectors = new ArrayList<>(); + this.current = new ObjectCursor<>(); + } + + abstract long hash(T vector) throws IOException; Review Comment: We don't have a test case right now -- are you suggesting a `@Monster` test, or an offline run? I'm guessing the HNSW graph construction will still be the bottleneck here, but I haven't tried this^ -- 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]
