|
18 | 18 | #include "VecSim/memory/vecsim_base.h" |
19 | 19 | #include "VecSim/spaces/spaces.h" |
20 | 20 | #include "VecSim/memory/memory_utils.h" |
| 21 | +#include "VecSim/types/sq8.h" |
21 | 22 |
|
22 | 23 | class PreprocessorInterface : public VecsimBaseObject { |
23 | 24 | public: |
@@ -216,10 +217,8 @@ class CosinePreprocessor : public PreprocessorInterface { |
216 | 217 | template <typename DataType, VecSimMetric Metric> |
217 | 218 | class QuantPreprocessor : public PreprocessorInterface { |
218 | 219 | using OUTPUT_TYPE = uint8_t; |
| 220 | + using sq8 = vecsim_types::sq8; |
219 | 221 |
|
220 | | - // For L2: store sum + sum_of_squares (2 extra values) |
221 | | - // For IP/Cosine: store only sum (1 extra value) |
222 | | - static constexpr size_t extra_storage_values_count = (Metric == VecSimMetric_L2) ? 2 : 1; |
223 | 222 | static_assert(Metric == VecSimMetric_L2 || Metric == VecSimMetric_IP || |
224 | 223 | Metric == VecSimMetric_Cosine, |
225 | 224 | "QuantPreprocessor only supports L2, IP and Cosine metrics"); |
@@ -294,13 +293,13 @@ class QuantPreprocessor : public PreprocessorInterface { |
294 | 293 | DataType *metadata = reinterpret_cast<DataType *>(quantized + this->dim); |
295 | 294 |
|
296 | 295 | // Store min_val, delta, in the metadata |
297 | | - metadata[0] = min_val; |
298 | | - metadata[1] = delta; |
| 296 | + metadata[sq8::MIN_VAL] = min_val; |
| 297 | + metadata[sq8::DELTA] = delta; |
299 | 298 |
|
300 | 299 | // Store sum (for all metrics) and sum_squares (for L2 only) |
301 | | - metadata[2] = sum; |
| 300 | + metadata[sq8::SUM] = sum; |
302 | 301 | if constexpr (Metric == VecSimMetric_L2) { |
303 | | - metadata[3] = sum_squares; |
| 302 | + metadata[sq8::SUM_SQUARES] = sum_squares; |
304 | 303 | } |
305 | 304 | } |
306 | 305 |
|
@@ -352,7 +351,7 @@ class QuantPreprocessor : public PreprocessorInterface { |
352 | 351 | QuantPreprocessor(std::shared_ptr<VecSimAllocator> allocator, size_t dim) |
353 | 352 | : PreprocessorInterface(allocator), dim(dim), |
354 | 353 | storage_bytes_count(dim * sizeof(OUTPUT_TYPE) + |
355 | | - (2 + extra_storage_values_count) * sizeof(DataType)), |
| 354 | + (vecsim_types::sq8::metadata_count<Metric>()) * sizeof(DataType)), |
356 | 355 | query_bytes_count((dim + 1) * sizeof(DataType)) { |
357 | 356 | static_assert(std::is_floating_point_v<DataType>, |
358 | 357 | "QuantPreprocessor only supports floating-point types"); |
|
0 commit comments