Package io.github.jbellis.jvector.pq
Class LocallyAdaptiveVectorQuantization
java.lang.Object
io.github.jbellis.jvector.pq.LocallyAdaptiveVectorQuantization
- All Implemented Interfaces:
VectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
public class LocallyAdaptiveVectorQuantization
extends Object
implements VectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
Implements Locally-Adaptive Vector Quantization (LVQ) as described in
"Similarity search in the blink of an eye with compressed indices" (https://arxiv.org/abs/2304.04759).
In particular, single-level LVQ-8 is used. To encode, a vector is first de-meaned by subtracting the global mean.
Then, each component is quantized using a byte, where 0 = min and 255 = max. The bias and scale are stored for each
component to allow for dequantization. Vectors are packed using Turbo LVQ as described in
"Locally-Adaptive Quantization for Streaming Vector Search" (https://arxiv.org/pdf/2402.02044.pdf).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A Turbo LVQ vector that has been packed into a byte sequence.static class
A LVQ-quantized vector. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
the size of a compressed vectorint
the size of the serialized compressor itself (NOT the size of compressed vectors)createCompressedVectors
(Object[] compressedVectors) encode
(VectorFloat<?> v) encodeAll
(RandomAccessVectorValues ravv, ForkJoinPool simdExecutor) boolean
scoreFunctionFrom
(VectorFloat<?> query, VectorSimilarityFunction similarityFunction, LVQPackedVectors packedVectors) void
write
(DataOutput out, int version) Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.jbellis.jvector.pq.VectorCompressor
encodeAll, encodeAll, write
-
Field Details
-
globalMean
-
-
Constructor Details
-
LocallyAdaptiveVectorQuantization
-
-
Method Details
-
compute
-
encodeAll
public LocallyAdaptiveVectorQuantization.QuantizedVector[] encodeAll(RandomAccessVectorValues ravv, ForkJoinPool simdExecutor) - Specified by:
encodeAll
in interfaceVectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
-
encode
- Specified by:
encode
in interfaceVectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
-
write
- Specified by:
write
in interfaceVectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
- Parameters:
out
- DataOutput to write toversion
- serialization version. Versions 2 and 3 are supported- Throws:
IOException
-
compressedVectorSize
public int compressedVectorSize()Description copied from interface:VectorCompressor
the size of a compressed vector- Specified by:
compressedVectorSize
in interfaceVectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
-
compressorSize
public int compressorSize()Description copied from interface:VectorCompressor
the size of the serialized compressor itself (NOT the size of compressed vectors)- Specified by:
compressorSize
in interfaceVectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
-
scoreFunctionFrom
public ScoreFunction.Reranker scoreFunctionFrom(VectorFloat<?> query, VectorSimilarityFunction similarityFunction, LVQPackedVectors packedVectors) -
createCompressedVectors
- Specified by:
createCompressedVectors
in interfaceVectorCompressor<LocallyAdaptiveVectorQuantization.QuantizedVector>
- Parameters:
compressedVectors
- must match the type T for this VectorCompressor, but it is declared as Object because we want callers to be able to use this without committing to a specific type T.
-
load
- Throws:
IOException
-
equals
-