| 42 | |
| 43 | template <size_t BATCH_SIZE> |
| 44 | int FlatStreamer<BATCH_SIZE>::init(const IndexMeta &imeta, |
| 45 | const ailego::Params ¶ms) { |
| 46 | meta_ = imeta; |
| 47 | meta_.set_streamer("FlatStreamer", 0U, params); |
| 48 | |
| 49 | // With a turbo quantizer the distances are computed by the quantizer's |
| 50 | // SIMD kernels; the metric cannot describe the quantized layout |
| 51 | // (e.g. Cosine rejects DT_INT8), so skip metric setup entirely. |
| 52 | if (!quantizer_) { |
| 53 | int error_code = InitializeMetric(meta_, &metric_); |
| 54 | if (error_code != 0) { |
| 55 | LOG_ERROR("Failed to initialize index metric %s, error=%d, %s", |
| 56 | meta_.metric_name().c_str(), error_code, |
| 57 | IndexError::What(error_code)); |
| 58 | return error_code; |
| 59 | } |
| 60 | if (metric_->query_metric()) { |
| 61 | metric_ = metric_->query_metric(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // 参数设置 |
| 66 | if (params.get(PARAM_FLAT_COLUMN_MAJOR_ORDER, &column_major_order_)) { |
| 67 | meta_.set_major_order(column_major_order_ ? IndexMeta::MO_COLUMN |
| 68 | : IndexMeta::MO_ROW); |
| 69 | } |
| 70 | // Verify column major order |
| 71 | if (meta_.major_order() != IndexMeta::MO_ROW) { |
| 72 | IndexMeta::DataType ft = meta_.data_type(); |
| 73 | |
| 74 | bool support_column_major = true; |
| 75 | if ((ft != IndexMeta::DT_FP32 && ft != IndexMeta::DT_FP16 && |
| 76 | ft != IndexMeta::DT_INT8 && ft != IndexMeta::DT_INT4 && |
| 77 | ft != IndexMeta::DT_BINARY32 && ft != IndexMeta::DT_BINARY64) || |
| 78 | (meta_.unit_size() != IndexMeta::UnitSizeof(ft))) { |
| 79 | if (meta_.major_order() == IndexMeta::MO_COLUMN) { |
| 80 | LOG_ERROR("Unsupported type %d with unit size %u.", ft, |
| 81 | meta_.unit_size()); |
| 82 | return IndexError_Unsupported; |
| 83 | } else { |
| 84 | support_column_major = false; |
| 85 | } |
| 86 | } |
| 87 | if (meta_.element_size() % IndexMeta::AlignSizeof(ft) != 0) { |
| 88 | if (meta_.major_order() == IndexMeta::MO_COLUMN) { |
| 89 | LOG_ERROR("Unsupported type %d with dimension %u.", ft, |
| 90 | meta_.dimension()); |
| 91 | return IndexError_Unsupported; |
| 92 | } else { |
| 93 | support_column_major = false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if (meta_.major_order() == IndexMeta::MO_UNDEFINED && |
| 98 | support_column_major) { |
| 99 | meta_.set_major_order(IndexMeta::MO_ROW); |
| 100 | } |
| 101 | } |
nothing calls this directly
no test coverage detected