IVectorQuantizer<T>
Interfaces · AiDotNet.RetrievalAugmentedGeneration.VectorSearch.Quantization
Common interface for vector quantizers used to compress dense embeddings for memory- and latency-efficient similarity search.
Known implementations: BinaryQuantizer<T>, ProductQuantizer<T>, ScalarQuantizer<T>
For Beginners
A raw embedding stores every dimension as a full floating-point number (4 or 8 bytes each). Quantization replaces those numbers with much smaller codes (for example a single byte, or even a single bit, per dimension) plus a small “dictionary” that lets you approximately reconstruct the original values. You lose a little precision but save a lot of memory.
How It Works
Quantization trades a small amount of accuracy for large reductions in memory footprint (and often faster distance computation). This is how libraries such as FAISS, Qdrant and pgvector serve billions of vectors on commodity hardware.
Properties
| Property | Summary |
|---|---|
bool IsTrained { get; } |
Gets a value indicating whether the quantizer has been trained and is ready to encode. |
int CodeLength { get; } |
Gets the number of bytes produced by Encode for a single vector, or 0 if untrained. |
int Dimension { get; } |
Gets the dimensionality of the vectors this quantizer was trained on, or 0 if untrained. |
Methods
| Method | Summary |
|---|---|
Vector<T> Decode(byte[] code) |
Approximately reconstructs a vector from its compact byte representation. |
byte[] Encode(Vector<T> vector) |
Encodes a vector into its compact byte representation. |
void Train(IEnumerable<Vector<T>> vectors) |
Trains the quantizer (learns any required statistics or codebooks) from a set of vectors. |