kaivalnp commented on code in PR #16506: URL: https://github.com/apache/lucene/pull/16506#discussion_r3846237894
########## lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/dedup/DedupScalarQuantizedVectorsFormat.java: ########## @@ -0,0 +1,136 @@ +/* + * 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.sandbox.codecs.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; +import org.apache.lucene.util.quantization.QuantizedByteVectorValues.ScalarEncoding; + +/** + * A scalar quantized version of {@link DedupFlatVectorsFormat} that stores each distinct vector + * once, in both raw and quantized form. + * + * <p>Quantization is <i>data-blind</i>: input vectors are assumed to be evenly distributed, i.e. + * centered on a zero vector (see {@link DedupQuantizer}). The quantized record of a vector is then + * a pure function of the raw vector and the {@link DedupQuantizer.Flavor} derived from the field's + * similarity function — independent of the other vectors in the segment — so quantized records + * de-duplicate like raw vectors: identical vectors across documents and fields of a group whose + * similarity functions map to the same flavor share one quantized record, resolved through the same + * {@code fieldOrdToGroupOrd} translation map. Records follow the {@link + * org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorsFormat} conventions per flavor, + * and are scored by the stock {@link + * org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorScorer}. Note the accuracy + * tradeoff relative to that format, which centers vectors on a per-field centroid before + * quantizing. + * + * <p>Only {@link org.apache.lucene.index.VectorEncoding#FLOAT32} vectors are quantized; BYTE and + * FLOAT16 vectors are stored raw only, identical to {@link DedupFlatVectorsFormat}. Review Comment: Right, I don't think we have the ability quantize `FLOAT16` vectors today -- we'll need to mirror the logic in the original scalar quantized format when it's added. -- 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]
