Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
59eea4c
refactor: add extra meta size
richyreachy Mar 24, 2026
517ce50
feat: turbo distances
richyreachy Mar 24, 2026
51cc10e
refactor: fix int4 ip
richyreachy Mar 25, 2026
12395f6
refactor: add avx2 int4 l2
richyreachy Mar 25, 2026
1ed3209
refactor: add dist funcs
richyreachy Mar 26, 2026
c6f37d2
refactor: add ut for march
richyreachy Mar 26, 2026
573d585
feat: add turbo ut
richyreachy Mar 27, 2026
fdc0f35
feat: add int8/int4 avx2 sse
richyreachy Mar 27, 2026
7be94e0
feat: add dist
richyreachy Mar 30, 2026
4d21dd8
feat: add dist func
richyreachy Mar 31, 2026
42dd299
feat: add scalar dist funcs
richyreachy Mar 31, 2026
04d86ff
feat: add scalar dist funcs
richyreachy Mar 31, 2026
1958a82
feat: add ut
richyreachy Mar 31, 2026
92340b9
feat: add dist funcs
richyreachy Mar 31, 2026
b748222
feat: add dist funcs
richyreachy Mar 31, 2026
4f885b9
feat: add dist funcs
richyreachy Mar 31, 2026
cf017bc
feat: add dist funcs
richyreachy Mar 31, 2026
faa7e64
feat: add fp16 funcs
richyreachy Mar 31, 2026
c073035
feat: add dist funcs
richyreachy Mar 31, 2026
b6baa89
feat: update ut
richyreachy Apr 1, 2026
83b172c
feat: add dist ut
richyreachy Apr 2, 2026
f9fe8ae
feat: add dist funcs
richyreachy Apr 2, 2026
2b23284
feat: add dist funcs
richyreachy Apr 2, 2026
950c7fd
feat: add cosine and euclidean dist func
richyreachy Apr 2, 2026
5a3bec9
feat: merge main
richyreachy Apr 8, 2026
000a199
refactor: change makefile
richyreachy Apr 9, 2026
27ec0f0
refactor: change makefile
richyreachy Apr 9, 2026
08d995e
fix: fix single dist
richyreachy Apr 10, 2026
b4f4bdc
fix: fix single dist
richyreachy Apr 10, 2026
97455f6
fix: avx512fp16 dist func
richyreachy Apr 13, 2026
1f2b66f
feat: support arm
richyreachy Apr 13, 2026
50fc6d7
feat: add armv8
richyreachy Apr 13, 2026
b0bfa89
feat: add armv8
richyreachy Apr 13, 2026
ebd51ef
feat: add armv8
richyreachy Apr 13, 2026
fe8d72a
fix: armv8
richyreachy Apr 13, 2026
f29d6dd
fix: fix typo
richyreachy Apr 13, 2026
53ffc8e
fix: fix dist
richyreachy Apr 13, 2026
85f8cc6
Merge branch 'main' into refactor/turbo
richyreachy Apr 13, 2026
3e45b87
fix: fix dist
richyreachy Apr 13, 2026
e26610a
fix: vnni inner product
richyreachy Apr 13, 2026
b433e6b
fix: fix batch ut
richyreachy Apr 14, 2026
36c4f4c
feat: add batch ut
richyreachy Apr 14, 2026
895cd78
feat: add batch dist
richyreachy Apr 14, 2026
41efb29
fix: fix batch dist
richyreachy Apr 15, 2026
1d02de3
feat: add quantizer
richyreachy Apr 16, 2026
8686780
feat: add quantizer
richyreachy Apr 16, 2026
7aa0b62
refactor: add quantizer definition
richyreachy Apr 17, 2026
5568416
feat: add record int8 quantizer
richyreachy Apr 17, 2026
37e15ad
feat: add record quantizer
richyreachy Apr 20, 2026
2eb881a
feat: add quantizer
richyreachy Apr 20, 2026
eb91962
feat: add quantizer
richyreachy Apr 20, 2026
7725683
feat: add quantizer
richyreachy Apr 20, 2026
711199e
feat: add int8 quantizer
richyreachy Apr 21, 2026
ad174ba
feat: int8 quantizer
richyreachy Apr 21, 2026
75991a5
feat: int8 quantizer
richyreachy Apr 21, 2026
c5e8236
feat: int8 quantizer
richyreachy Apr 21, 2026
0cd3001
feat: add int4 quantizer
richyreachy Apr 21, 2026
9162016
feat: add int4 quantizer
richyreachy Apr 21, 2026
9839711
feat: add quantizer uts
richyreachy Apr 22, 2026
8ddab15
feat: add quantizer uts
richyreachy Apr 22, 2026
d27026a
feat: add quantizer uts
richyreachy Apr 22, 2026
096eca3
feat: add serialize and deserialize
richyreachy Apr 22, 2026
e71ae68
fix: move distances
richyreachy Apr 22, 2026
daf86d9
fix: update makefile
richyreachy Apr 22, 2026
9a9a6d6
feat: add extra meta size
richyreachy Apr 22, 2026
824ba83
feat: add extra meta size
richyreachy Apr 22, 2026
e1d9314
fix: fix ut
richyreachy Apr 22, 2026
c8b92b5
refactor: meta size
richyreachy Apr 23, 2026
d30c5af
refactor: meta size
richyreachy Apr 23, 2026
717b447
fix: fix uts
richyreachy Apr 24, 2026
aec4665
feat: fix ut bugs
richyreachy Apr 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/core/framework/index_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,18 @@ std::vector<std::string> IndexFactory::AllRefiners(void) {
return ailego::Factory<IndexRefiner>::Classes();
}

std::shared_ptr<turbo::Quantizer> IndexFactory::CreateQuantizer(
const std::string &name) {
return ailego::Factory<zvec::turbo::Quantizer>::MakeShared(name.c_str());
}

bool IndexFactory::HasQuantizer(const std::string &name) {
return ailego::Factory<turbo::Quantizer>::Has(name.c_str());
}

std::vector<std::string> IndexFactory::AllQuantizers(void) {
return ailego::Factory<turbo::Quantizer>::Classes();
}

} // namespace core
} // namespace zvec
4 changes: 3 additions & 1 deletion src/core/framework/index_meta.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ struct IndexMetaFormatHeader {
uint32_t space_id;
uint32_t attachment_offset;
uint32_t attachment_size;
uint8_t reserved_[4092];
uint32_t extra_meta_size;
uint8_t reserved_[4088];
};

static_assert(sizeof(IndexMetaFormatHeader) % 32 == 0,
Expand All @@ -47,6 +48,7 @@ void IndexMeta::serialize(std::string *out) const {
format.dimension = dimension_;
format.unit_size = unit_size_;
format.space_id = space_id_;
format.extra_meta_size = extra_meta_size_;

if (!metric_name_.empty()) {
ailego::Params item;
Expand Down
21 changes: 11 additions & 10 deletions src/core/metric/quantized_integer_metric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,23 @@ class QuantizedIntegerMetric : public IndexMetric {
if (meta_.data_type() == IndexMeta::DataType::DT_INT8) {
auto turbo_ret = turbo::get_distance_func(
turbo::MetricType::kSquaredEuclidean, turbo::DataType::kInt8,
turbo::QuantizeType::kDefault);
static_cast<turbo::QuantizeType>(quantize_type_));
if (turbo_ret && m == 1 && n == 1) {
return turbo_ret;
}
return DistanceMatrixCompute<SquaredEuclidean, int8_t>(m, n);
}
if (meta_.data_type() == IndexMeta::DataType::DT_INT4) {

return DistanceMatrixCompute<SquaredEuclidean, uint8_t>(m, n);
}
break;

case MetricType::kInnerProduct:
if (meta_.data_type() == IndexMeta::DataType::DT_INT8) {
return DistanceMatrixCompute<MinusInnerProduct, int8_t>(m, n);
}
if (meta_.data_type() == IndexMeta::DataType::DT_INT4) {
auto turbo_ret = turbo::get_distance_func(
turbo::MetricType::kInnerProduct, turbo::DataType::kInt8,
static_cast<turbo::QuantizeType>(quantize_type_));
if (turbo_ret && m == 1 && n == 1) {
return turbo_ret;
}
return DistanceMatrixCompute<MinusInnerProduct, uint8_t>(m, n);
}
break;
Expand All @@ -139,7 +140,7 @@ class QuantizedIntegerMetric : public IndexMetric {
if (meta_.data_type() == IndexMeta::DataType::DT_INT8) {
auto turbo_ret = turbo::get_distance_func(
turbo::MetricType::kCosine, turbo::DataType::kInt8,
turbo::QuantizeType::kDefault);
static_cast<turbo::QuantizeType>(quantize_type_));
if (turbo_ret) {
return turbo_ret;
}
Expand All @@ -160,7 +161,7 @@ class QuantizedIntegerMetric : public IndexMetric {
if (meta_.data_type() == IndexMeta::DataType::DT_INT8) {
auto turbo_ret = turbo::get_batch_distance_func(
turbo::MetricType::kSquaredEuclidean, turbo::DataType::kInt8,
turbo::QuantizeType::kDefault);
static_cast<turbo::QuantizeType>(quantize_type_));
if (turbo_ret) {
return turbo_ret;
}
Expand Down Expand Up @@ -215,7 +216,7 @@ class QuantizedIntegerMetric : public IndexMetric {
if (meta_.data_type() == IndexMeta::DataType::DT_INT8) {
auto turbo_ret = turbo::get_batch_distance_func(
turbo::MetricType::kCosine, turbo::DataType::kInt8,
turbo::QuantizeType::kDefault);
static_cast<turbo::QuantizeType>(quantize_type_));
if (turbo_ret) {
return turbo_ret;
}
Expand Down
19 changes: 19 additions & 0 deletions src/include/zvec/core/framework/index_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <turbo/quantizer/quantizer.h>
#include <zvec/ailego/pattern/factory.h>
#include <zvec/core/framework/index_builder.h>
#include <zvec/core/framework/index_cluster.h>
Expand Down Expand Up @@ -167,6 +168,16 @@ struct IndexFactory {

//! Retrieve all refiner classes
static std::vector<std::string> AllRefiners(void);

//! Create a quantizer by name
static std::shared_ptr<zvec::turbo::Quantizer> CreateQuantizer(
const std::string &name);

//! Test if the quantizer exists
static bool HasQuantizer(const std::string &name);

//! Retrieve all quantizer classes
static std::vector<std::string> AllQuantizers(void);
};

//! Register Index Metric
Expand Down Expand Up @@ -283,5 +294,13 @@ struct IndexFactory {
#define INDEX_FACTORY_REGISTER_REFINER(__IMPL__, ...) \
INDEX_FACTORY_REGISTER_REFINER_ALIAS(__IMPL__, __IMPL__, ##__VA_ARGS__)

//! Register Quantizer
#define INDEX_FACTORY_REGISTER_QUANTIZER_ALIAS(__NAME__, __IMPL__, ...) \
AILEGO_FACTORY_REGISTER(__NAME__, turbo::Quantizer, __IMPL__, ##__VA_ARGS__)

//! Register Quantizer
#define INDEX_FACTORY_REGISTER_QUANTIZER(__IMPL__, ...) \
INDEX_FACTORY_REGISTER_QUANTIZER_ALIAS(__IMPL__, __IMPL__, ##__VA_ARGS__)

} // namespace core
} // namespace zvec
40 changes: 38 additions & 2 deletions src/include/zvec/core/framework/index_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class IndexMeta {
DT_BINARY64 = 8,
};


/*! Major Orders
*/
enum MajorOrder {
Expand Down Expand Up @@ -451,6 +452,11 @@ class IndexMeta {
this->set_meta(data_type, UnitSizeof(data_type), dim);
}

//! Set extra meta size
void set_extra_meta_size(uint32_t size) {
extra_meta_size_ = size;
}

//! Set information of metric
template <typename TName, typename TParams>
void set_metric(TName &&name, uint32_t rev, TParams &&params) {
Expand Down Expand Up @@ -586,6 +592,7 @@ class IndexMeta {
uint32_t dimension_{0};
uint32_t unit_size_{0};
uint32_t element_size_{0};
uint32_t extra_meta_size_{0};
uint64_t space_id_{0};
uint32_t metric_revision_{0};
uint32_t converter_revision_{0};
Expand Down Expand Up @@ -632,6 +639,19 @@ class IndexQueryMeta {
unit_size_(unit),
element_size_(IndexMeta::ElementSizeof(data_type, unit, dim)) {}

//! Constructor
IndexQueryMeta(IndexMeta::MetaType meta_type, IndexMeta::DataType data_type,
uint32_t unit, uint32_t dim, uint32_t quantize_type,
uint32_t extra_meta_size)
: meta_type_(meta_type),
data_type_(data_type),
dimension_(dim),
unit_size_(unit),
quantize_type_(quantize_type),
extra_meta_size_(extra_meta_size),
element_size_(IndexMeta::ElementSizeof(data_type, unit, dim) +
extra_meta_size_) {}

//! Constructor
IndexQueryMeta(IndexMeta::DataType data_type, uint32_t dim)
: IndexQueryMeta{IndexMeta::MetaType::MT_DENSE, data_type,
Expand Down Expand Up @@ -676,7 +696,8 @@ class IndexQueryMeta {
//! Set dimension of feature
void set_dimension(uint32_t dim) {
dimension_ = dim;
element_size_ = IndexMeta::ElementSizeof(data_type_, unit_size_, dim);
element_size_ = IndexMeta::ElementSizeof(data_type_, unit_size_, dim) +
extra_meta_size_;
}

//! Set meta type
Expand All @@ -694,19 +715,34 @@ class IndexQueryMeta {
data_type_ = data_type;
dimension_ = dim;
unit_size_ = unit;
element_size_ = IndexMeta::ElementSizeof(data_type, unit, dim);
element_size_ =
IndexMeta::ElementSizeof(data_type, unit, dim) + extra_meta_size_;
}

//! Set meta information of feature
void set_meta(IndexMeta::DataType data_type, uint32_t dim) {
this->set_meta(data_type, IndexMeta::UnitSizeof(data_type), dim);
}

//! Set meta information of feature with quantize type and extra meta size
void set_meta(IndexMeta::DataType data_type, uint32_t dim,
uint32_t quantize_type, uint32_t extra_meta_size) {
data_type_ = data_type;
dimension_ = dim;
unit_size_ = IndexMeta::UnitSizeof(data_type);
quantize_type_ = quantize_type;
extra_meta_size_ = extra_meta_size;
element_size_ =
IndexMeta::ElementSizeof(data_type, unit_size_, dim) + extra_meta_size_;
}

private:
IndexMeta::MetaType meta_type_{IndexMeta::MetaType::MT_DENSE};
IndexMeta::DataType data_type_{IndexMeta::DataType::DT_UNDEFINED};
uint32_t dimension_{0};
uint32_t unit_size_{0};
uint32_t quantize_type_{0};
uint32_t extra_meta_size_{0};
uint32_t element_size_{0};
};

Expand Down
3 changes: 3 additions & 0 deletions src/include/zvec/core/framework/index_metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ struct IndexMetric : public IndexModule {
virtual DistanceBatchQueryPreprocessFunc get_query_preprocess_func() const {
return nullptr;
}

protected:
int quantize_type_{0};
};

} // namespace core
Expand Down
37 changes: 30 additions & 7 deletions src/include/zvec/turbo/turbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,51 @@ using QueryPreprocessFunc =
enum class MetricType {
kSquaredEuclidean,
kCosine,
kInnerProduct,
kMipsSquaredEuclidean,
kUnknown,
};

enum class DataType {
kInt4,
kInt8,
kFp16,
kFp32,
kUnknown,
};

enum class QuantizeType {
kDefault,
kRecordInt8,
kRecordInt4,
kInt8,
kInt4,
kFp16,
kPQ,
kRabit
};

enum class CpuArchType {
kAuto,
kScalar,
kSSE,
kAVX,
kAVX2,
kAVX512,
kAVX512VNNI,
kAVX512FP16
};

DistanceFunc get_distance_func(MetricType metric_type, DataType data_type,
QuantizeType quantize_type);
QuantizeType quantize_type,
CpuArchType cpu_arch_type = CpuArchType::kAuto);

BatchDistanceFunc get_batch_distance_func(MetricType metric_type,
DataType data_type,
QuantizeType quantize_type);
BatchDistanceFunc get_batch_distance_func(
MetricType metric_type, DataType data_type, QuantizeType quantize_type,
CpuArchType cpu_arch_type = CpuArchType::kAuto);

QueryPreprocessFunc get_query_preprocess_func(MetricType metric_type,
DataType data_type,
QuantizeType quantize_type);
QueryPreprocessFunc get_query_preprocess_func(
MetricType metric_type, DataType data_type, QuantizeType quantize_type,
CpuArchType cpu_arch_type = CpuArchType::kAuto);

} // namespace zvec::turbo
Loading