|
30 | 30 | #include "knowhere/comp/index_param.h" |
31 | 31 | #include "knowhere/expected.h" |
32 | 32 | #include "knowhere/log.h" |
| 33 | +#include "knowhere/prometheus_client.h" |
33 | 34 | #include "knowhere/sparse_utils.h" |
34 | 35 | #include "knowhere/utils.h" |
35 | 36 |
|
@@ -261,10 +262,17 @@ class InvertedIndex : public BaseInvertedIndex<DType> { |
261 | 262 | } |
262 | 263 | } |
263 | 264 | add_row_to_index(raw_row, i); |
| 265 | + knowhere_sparse_dataset_nnz_len.Observe(count); |
| 266 | + } |
| 267 | + |
| 268 | + for (size_t i = 0; i < dim_map_.size(); ++i) { |
| 269 | + knowhere_sparse_inverted_index_posting_list_len.Observe(inverted_index_ids_[i].size()); |
264 | 270 | } |
265 | 271 |
|
266 | 272 | n_rows_internal_ = rows; |
267 | 273 |
|
| 274 | + knowhere_sparse_inverted_index_size.Increment((double)size() / 1024.0 / 1024.0); |
| 275 | + |
268 | 276 | return Status::success; |
269 | 277 | } |
270 | 278 |
|
@@ -438,6 +446,7 @@ class InvertedIndex : public BaseInvertedIndex<DType> { |
438 | 446 | } |
439 | 447 |
|
440 | 448 | auto q_vec = parse_query(query, approx_params.drop_ratio_search); |
| 449 | + knowhere_sparse_query_nnz_len.Observe(q_vec.size()); |
441 | 450 | if (q_vec.empty()) { |
442 | 451 | return; |
443 | 452 | } |
@@ -921,7 +930,18 @@ class InvertedIndex : public BaseInvertedIndex<DType> { |
921 | 930 | } |
922 | 931 | inverted_index_ids_[dim_it->second].emplace_back(vec_id); |
923 | 932 | inverted_index_vals_[dim_it->second].emplace_back(get_quant_val(val)); |
924 | | - if constexpr (algo == InvertedIndexAlgo::DAAT_WAND || algo == InvertedIndexAlgo::DAAT_MAXSCORE) { |
| 933 | + } |
| 934 | + // update max_score_in_dim_ |
| 935 | + if constexpr (algo == InvertedIndexAlgo::DAAT_WAND || algo == InvertedIndexAlgo::DAAT_MAXSCORE) { |
| 936 | + for (size_t j = 0; j < row.size(); ++j) { |
| 937 | + auto [dim, val] = row[j]; |
| 938 | + if (val == 0) { |
| 939 | + continue; |
| 940 | + } |
| 941 | + auto dim_it = dim_map_.find(dim); |
| 942 | + if (dim_it == dim_map_.cend()) { |
| 943 | + throw std::runtime_error("unexpected vector dimension in InvertedIndex"); |
| 944 | + } |
925 | 945 | auto score = static_cast<float>(val); |
926 | 946 | if (metric_type_ == SparseMetricType::METRIC_BM25) { |
927 | 947 | score = bm25_params_->max_score_computer(val, row_sum); |
|
0 commit comments