benwtrent commented on code in PR #13197: URL: https://github.com/apache/lucene/pull/13197#discussion_r1535715050
########## lucene/core/src/java/org/apache/lucene/codecs/lucene99/OffHeapQuantizedHalfByteVectorValues.java: ########## @@ -0,0 +1,299 @@ +/* + * 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.lucene90.IndexedDISI; +import org.apache.lucene.codecs.lucene95.OrdToDocDISIReaderConfiguration; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.util.Bits; +import org.apache.lucene.util.packed.DirectMonotonicReader; +import org.apache.lucene.util.quantization.QuantizedByteVectorValues; +import org.apache.lucene.util.quantization.RandomAccessQuantizedByteVectorValues; + +/** + * Read the quantized vector values and their score correction values from the index input. This + * supports both iterated and random access. + */ +abstract class OffHeapQuantizedHalfByteVectorValues extends QuantizedByteVectorValues + implements RandomAccessQuantizedByteVectorValues { + + protected final int dimension; + protected final int size; + protected final IndexInput slice; + protected final byte[] binaryValue; + protected final int byteSize, numBytes; + protected final ByteBuffer byteBuffer; + protected int lastOrd = -1; + protected final float[] scoreCorrectionConstant = new float[1]; + + public static void decompressBytes(byte[] compressed, int numBytes) { + if (numBytes << 1 != compressed.length) { + throw new IllegalArgumentException( + "numBytes: " + numBytes + " does not match compressed length: " + compressed.length); + } + for (int i = 0; i < numBytes; ++i) { + compressed[numBytes + i] = (byte) (compressed[i] & 0x0F); + compressed[i] = (byte) ((compressed[i] & 0xFF) >> 4); + } Review Comment: @jpountz its pretty fast. This combined with the panama optimized int4 vector comparison keeps runtime faster than float32. However, doing this and only the int8 vector comparison makes us about the same speed or slightly slower than float32. I am going to run a bunch more benchmarks once I get this all refactored and show all the numbers. -- 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