Skip to content
Open
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion src/quantization/int8_quantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ INT8Quantizer<metric>::DecodeBatchImpl(const uint8_t* codes, DataType* data, uin
template <MetricType metric>
float
INT8Quantizer<metric>::ComputeImpl(const uint8_t* codes1, const uint8_t* codes2) {
static_assert(metric == MetricType::METRIC_TYPE_IP ||
metric == MetricType::METRIC_TYPE_COSINE ||
metric == MetricType::METRIC_TYPE_L2SQR,
"Unsupported metric type for INT8Quantizer");
if constexpr (metric == MetricType::METRIC_TYPE_IP) {
Comment on lines +109 to 113
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says the code was changed to else if constexpr (metric == MetricType::METRIC_TYPE_L2SQR), but the diff shows the L2SQR path is now handled via a plain else. Either update the PR description to match the implementation, or change the code to use else if constexpr as described.

Copilot uses AI. Check for mistakes.
return 1.0F - INT8ComputeIP(reinterpret_cast<const int8_t*>(codes1),
reinterpret_cast<const int8_t*>(codes2),
Expand All @@ -122,7 +126,7 @@ INT8Quantizer<metric>::ComputeImpl(const uint8_t* codes1, const uint8_t* codes2)
this->dim_);
similarity /= mold1[0] * mold2[0];
return 1.0F - std::max(-1.0F, std::min(1.0F, similarity));
} else if (metric == MetricType::METRIC_TYPE_L2SQR) {
} else {
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a bare else makes it less explicit that this branch is specifically for METRIC_TYPE_L2SQR (the reader has to infer it from the static_assert plus earlier branches). Consider making this branch an explicit else if constexpr (metric == MetricType::METRIC_TYPE_L2SQR) for self-documentation, while keeping the static_assert for compile-time enforcement.

Suggested change
} else {
} else if constexpr (metric == MetricType::METRIC_TYPE_L2SQR) {

Copilot uses AI. Check for mistakes.
return INT8ComputeL2Sqr(reinterpret_cast<const int8_t*>(codes1),
reinterpret_cast<const int8_t*>(codes2),
this->dim_);
Expand Down
Loading