benwtrent commented on code in PR #14792: URL: https://github.com/apache/lucene/pull/14792#discussion_r2167546639
########## lucene/core/src/java/org/apache/lucene/codecs/lucene95/OffHeapFloatVectorValues.java: ########## @@ -270,7 +270,8 @@ public DocIdSetIterator iterator() { } } - private static class EmptyOffHeapVectorValues extends OffHeapFloatVectorValues { Review Comment: if switching to `size() == 0` for float vector existence, I think this change is unnecessary. ########## lucene/core/src/java/org/apache/lucene/codecs/lucene99/OffHeapQuantizedFloatVectorValues.java: ########## @@ -0,0 +1,365 @@ +/* + * 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.lucene99; + +import java.io.IOException; +import java.nio.ByteBuffer; +import org.apache.lucene.codecs.hnsw.FlatVectorsScorer; +import org.apache.lucene.codecs.lucene90.IndexedDISI; +import org.apache.lucene.codecs.lucene95.HasIndexSlice; +import org.apache.lucene.codecs.lucene95.OrdToDocDISIReaderConfiguration; +import org.apache.lucene.index.FloatVectorValues; +import org.apache.lucene.index.VectorSimilarityFunction; +import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.search.VectorScorer; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.util.Bits; +import org.apache.lucene.util.hnsw.RandomVectorScorer; +import org.apache.lucene.util.packed.DirectMonotonicReader; +import org.apache.lucene.util.quantization.ScalarQuantizer; + +/** Read the vector values from the index input. This supports both iterated and random access. */ +public abstract class OffHeapQuantizedFloatVectorValues extends FloatVectorValues Review Comment: If this is gonna be public, it should likely have a `internal` annotation to make folks aware that its interface can break whenever we want. ########## lucene/core/src/java/org/apache/lucene/codecs/lucene99/OffHeapQuantizedFloatVectorValues.java: ########## @@ -0,0 +1,365 @@ +/* + * 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.lucene99; + +import java.io.IOException; +import java.nio.ByteBuffer; +import org.apache.lucene.codecs.hnsw.FlatVectorsScorer; +import org.apache.lucene.codecs.lucene90.IndexedDISI; +import org.apache.lucene.codecs.lucene95.HasIndexSlice; +import org.apache.lucene.codecs.lucene95.OrdToDocDISIReaderConfiguration; +import org.apache.lucene.index.FloatVectorValues; +import org.apache.lucene.index.VectorSimilarityFunction; +import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.search.VectorScorer; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.util.Bits; +import org.apache.lucene.util.hnsw.RandomVectorScorer; +import org.apache.lucene.util.packed.DirectMonotonicReader; +import org.apache.lucene.util.quantization.ScalarQuantizer; + +/** Read the vector values from the index input. This supports both iterated and random access. */ +public abstract class OffHeapQuantizedFloatVectorValues extends FloatVectorValues + implements HasIndexSlice { + + protected final int dimension; + protected final int size; + protected final int numBytes; + protected final ScalarQuantizer scalarQuantizer; + protected final VectorSimilarityFunction similarityFunction; + protected final FlatVectorsScorer vectorsScorer; + protected final boolean compress; + + protected final IndexInput slice; + protected final float[] floatValue; + protected final byte[] binaryValue; + protected final ByteBuffer byteBuffer; + protected final int byteSize; + protected int curOrd = -1; + protected final float[] scoreCorrectionConstant = new float[1]; + + OffHeapQuantizedFloatVectorValues( + int dimension, + int size, + ScalarQuantizer scalarQuantizer, + VectorSimilarityFunction similarityFunction, + FlatVectorsScorer vectorsScorer, + boolean compress, + IndexInput slice) { + this.dimension = dimension; + this.size = size; + this.slice = slice; + this.scalarQuantizer = scalarQuantizer; + this.compress = compress; + if (scalarQuantizer.getBits() <= 4 && compress) { + this.numBytes = (dimension + 1) >> 1; + } else { + this.numBytes = dimension; + } + this.byteSize = this.numBytes + Float.BYTES; + byteBuffer = ByteBuffer.allocate(dimension); + binaryValue = byteBuffer.array(); + floatValue = new float[dimension]; + this.similarityFunction = similarityFunction; + this.vectorsScorer = vectorsScorer; + } + + public ScalarQuantizer getScalarQuantizer() { + return scalarQuantizer; + } Review Comment: this isn't strictly necessary ########## lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99ScalarQuantizedVectorsReader.java: ########## @@ -189,6 +190,21 @@ private FieldEntry getFieldEntry(String field) { public FloatVectorValues getFloatVectorValues(String field) throws IOException { final FieldEntry fieldEntry = getFieldEntry(field); final FloatVectorValues rawVectorValues = rawVectorsReader.getFloatVectorValues(field); + if (rawVectorValues instanceof OffHeapFloatVectorValues.EmptyOffHeapVectorValues Review Comment: I agree with @msokolov here. Checking size simplifies things. -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org