Struct faiss::ScalarQuantizer
-
struct ScalarQuantizer : public faiss::Quantizer
The uniform quantizer has a range [vmin, vmax]. The range can be the same for all dimensions (uniform) or specific per dimension (default).
Public Types
-
enum QuantizerType
Values:
-
enumerator QT_8bit
8 bits per component
-
enumerator QT_4bit
4 bits per component
-
enumerator QT_8bit_uniform
same, shared range for all dimensions
-
enumerator QT_4bit_uniform
-
enumerator QT_fp16
-
enumerator QT_8bit_direct
fast indexing of uint8s
-
enumerator QT_6bit
6 bits per component
-
enumerator QT_bf16
-
enumerator QT_8bit_direct_signed
fast indexing of signed int8s ranging from [-128 to 127]
-
enumerator QT_8bit
-
enum RangeStat
The uniform encoder can estimate the range of representable values of the unform encoder using different statistics. Here rs = rangestat_arg
Values:
-
enumerator RS_minmax
[min - rs*(max-min), max + rs*(max-min)]
-
enumerator RS_meanstd
[mean - std * rs, mean + std * rs]
-
enumerator RS_quantiles
[Q(rs), Q(1-rs)]
-
enumerator RS_optim
alternate optimization of reconstruction error
-
enumerator RS_minmax
Public Functions
-
ScalarQuantizer(size_t d, QuantizerType qtype)
-
ScalarQuantizer()
-
void set_derived_sizes()
updates internal values based on qtype and d
-
virtual void train(size_t n, const float *x) override
Train the quantizer
- Parameters:
x – training vectors, size n * d
-
virtual void compute_codes(const float *x, uint8_t *codes, size_t n) const override
Encode a set of vectors
- Parameters:
x – vectors to encode, size n * d
codes – output codes, size n * code_size
-
virtual void decode(const uint8_t *code, float *x, size_t n) const override
Decode a set of vectors
- Parameters:
codes – codes to decode, size n * code_size
x – output vectors, size n * d
-
SQuantizer *select_quantizer() const
-
SQDistanceComputer *get_distance_computer(MetricType metric = METRIC_L2) const
-
InvertedListScanner *select_InvertedListScanner(MetricType mt, const Index *quantizer, bool store_pairs, const IDSelector *sel, bool by_residual = false) const
Public Members
-
QuantizerType qtype = QT_8bit
-
float rangestat_arg = 0
-
size_t bits = 0
bits per scalar code
-
std::vector<float> trained
trained values (including the range)
-
size_t d
size of the input vectors
-
size_t code_size
bytes per indexed vector
-
struct SQDistanceComputer : public faiss::FlatCodesDistanceComputer
Public Functions
-
inline SQDistanceComputer()
-
virtual float query_to_code(const uint8_t *code) const = 0
-
inline virtual float distance_to_code(const uint8_t *code) final
compute distance of current query to an encoded vector
-
inline virtual float operator()(idx_t i) override
compute distance of vector i to current query
-
virtual void set_query(const float *x) = 0
called before computing distances. Pointer x should remain valid while operator () is called
-
inline virtual void distances_batch_4(const idx_t idx0, const idx_t idx1, const idx_t idx2, const idx_t idx3, float &dis0, float &dis1, float &dis2, float &dis3)
compute distances of current query to 4 stored vectors. certain DistanceComputer implementations may benefit heavily from this.
Public Members
-
const float *q
-
const uint8_t *codes
-
size_t code_size
-
inline SQDistanceComputer()
-
struct SQuantizer
Public Functions
-
virtual void encode_vector(const float *x, uint8_t *code) const = 0
-
virtual void decode_vector(const uint8_t *code, float *x) const = 0
-
inline virtual ~SQuantizer()
-
virtual void encode_vector(const float *x, uint8_t *code) const = 0
-
enum QuantizerType