kaivalnp commented on code in PR #15979: URL: https://github.com/apache/lucene/pull/15979#discussion_r3667932152
########## lucene/core/src/java/org/apache/lucene/codecs/lucene106/dedup/DedupFlatVectorsFormat.java: ########## @@ -0,0 +1,133 @@ +/* + * 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 org.apache.lucene.codecs.hnsw.FlatVectorsFormat; +import org.apache.lucene.codecs.hnsw.FlatVectorsReader; +import org.apache.lucene.codecs.hnsw.FlatVectorsWriter; +import org.apache.lucene.index.SegmentReadState; +import org.apache.lucene.index.SegmentWriteState; + +/** + * Flat vector format that stores each distinct vector once. + * + * <p>Vectors that share the same dimension and encoding form a <i>group</i>. Within a group, an + * identical vector is stored a single time regardless of how many documents (across all fields that + * map to that group) reference it; each field then keeps a per-document {@code ordToVecOrd} map + * from its document ordinal to the group ordinal of the shared vector. This is well suited to + * indexes with repeated vectors, e.g. several fields derived from the same embedding, or heavily + * duplicated content. + * + * <h2>.vdd (vector de-dup data) file</h2> Review Comment: Today in code, flat vector formats are [not supposed to](https://github.com/apache/lucene/blob/d18845e6bbfaecf9421579c76fba0d38edde5711/lucene/core/src/java/org/apache/lucene/codecs/hnsw/FlatVectorsReader.java#L50-L54) provide a `search` -- but IMO they should! Strangely, the float variant of the scalar quantized reader [does support exact search](https://github.com/apache/lucene/blob/d18845e6bbfaecf9421579c76fba0d38edde5711/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104ScalarQuantizedVectorsReader.java#L301-L330). That appears to be wasteful too, because it simply iterates over all ordinals and checks whether they pass the filter one-by-one, instead of iterating over filtered docs. Perhaps if the exact search responsibility was passed on to the reader, we could make this^ more efficient + also [simplify the KNN query](https://github.com/apache/lucene/blob/d18845e6bbfaecf9421579c76fba0d38edde5711/lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java#L360) and do cool optimizations like #12820 (there was a similar suggestion in https://github.com/apache/lucene/pull/15011#issuecomment-3166636057). -- 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]
