kaivalnp commented on code in PR #15979: URL: https://github.com/apache/lucene/pull/15979#discussion_r3592540595
########## lucene/core/src/java/org/apache/lucene/codecs/dedup/DedupFlatVectorsWriter.java: ########## @@ -0,0 +1,1024 @@ +/* + * 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.dedup; + +import static org.apache.lucene.codecs.dedup.DedupFlatVectorsFormat.DIRECT_MONOTONIC_BLOCK_SHIFT; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.lucene.codecs.CodecUtil; +import org.apache.lucene.codecs.KnnVectorsWriter; +import org.apache.lucene.codecs.hnsw.FlatFieldVectorsWriter; +import org.apache.lucene.codecs.hnsw.FlatVectorsScorer; +import org.apache.lucene.codecs.hnsw.FlatVectorsWriter; +import org.apache.lucene.codecs.lucene95.OrdToDocDISIReaderConfiguration; +import org.apache.lucene.index.ByteVectorValues; +import org.apache.lucene.index.DocIDMerger; +import org.apache.lucene.index.DocsWithFieldSet; +import org.apache.lucene.index.FieldInfo; +import org.apache.lucene.index.FloatVectorValues; +import org.apache.lucene.index.IndexFileNames; +import org.apache.lucene.index.KnnVectorValues; +import org.apache.lucene.index.MergeState; +import org.apache.lucene.index.SegmentWriteState; +import org.apache.lucene.index.Sorter; +import org.apache.lucene.index.VectorEncoding; +import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.util.ArrayUtil; +import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.RamUsageEstimator; +import org.apache.lucene.util.packed.DirectWriter; + +/** + * Writes a {@link DedupFlatVectorsFormat} segment. + * + * <p><b>Indexing (flush)</b>: per-field calls accumulate vectors in heap, with a per-pool dedup + * hash table ({@link FlushPool}). {@code flush()} writes contiguous unique-vector bytes per pool, + * then per-field {@code docOrd → vecOrd} maps. + * + * <p><b>Merge</b>: per-field calls iterate source segments via {@link DocIDMerger}. A per-pool + * {@link MergePool} hash table maps the 64-bit hash of each candidate vector to a {@code + * (KnnVectorValues, srcOrd)} pair so that hash-collisions can be byte-verified by re-reading the + * source via mmap. No temp files are written; pool data is materialised into {@code .dvc} at {@link + * #finish()} time by re-reading each unique vector from its source segment (sources stay open until + * merge ends). + * + * <p>When a source reader is itself a {@link DedupFlatVectorsReader}, the merge takes a fast path + * (Level A): each source vec-ord is interned <em>once</em> per (mergedPool, sourceReader) pair and + * cached in a sparse {@code srcVecOrd → mergedVecOrd} array, so the per-doc loop becomes two int Review Comment: Makes sense, I'll add some! -- 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]
