|
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,8 +262,18 @@ class InvertedIndex : public BaseInvertedIndex<DType> { |
261 | 262 | } |
262 | 263 | } |
263 | 264 | add_row_to_index(raw_row, i); |
| 265 | +#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT) |
| 266 | + knowhere_sparse_dataset_nnz_len.Observe(count); |
| 267 | +#endif |
264 | 268 | } |
265 | 269 |
|
| 270 | +#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT) |
| 271 | + for (size_t i = 0; i < dim_map_.size(); ++i) { |
| 272 | + knowhere_sparse_inverted_index_posting_list_len.Observe(inverted_index_ids_[i].size()); |
| 273 | + } |
| 274 | + knowhere_sparse_inverted_index_size.Increment((double)size() / 1024.0 / 1024.0); |
| 275 | +#endif |
| 276 | + |
266 | 277 | n_rows_internal_ = rows; |
267 | 278 |
|
268 | 279 | return Status::success; |
@@ -438,6 +449,9 @@ class InvertedIndex : public BaseInvertedIndex<DType> { |
438 | 449 | } |
439 | 450 |
|
440 | 451 | auto q_vec = parse_query(query, approx_params.drop_ratio_search); |
| 452 | +#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT) |
| 453 | + knowhere_sparse_query_nnz_len.Observe(q_vec.size()); |
| 454 | +#endif |
441 | 455 | if (q_vec.empty()) { |
442 | 456 | return; |
443 | 457 | } |
@@ -921,7 +935,18 @@ class InvertedIndex : public BaseInvertedIndex<DType> { |
921 | 935 | } |
922 | 936 | inverted_index_ids_[dim_it->second].emplace_back(vec_id); |
923 | 937 | inverted_index_vals_[dim_it->second].emplace_back(get_quant_val(val)); |
924 | | - if constexpr (algo == InvertedIndexAlgo::DAAT_WAND || algo == InvertedIndexAlgo::DAAT_MAXSCORE) { |
| 938 | + } |
| 939 | + // update max_score_in_dim_ |
| 940 | + if constexpr (algo == InvertedIndexAlgo::DAAT_WAND || algo == InvertedIndexAlgo::DAAT_MAXSCORE) { |
| 941 | + for (size_t j = 0; j < row.size(); ++j) { |
| 942 | + auto [dim, val] = row[j]; |
| 943 | + if (val == 0) { |
| 944 | + continue; |
| 945 | + } |
| 946 | + auto dim_it = dim_map_.find(dim); |
| 947 | + if (dim_it == dim_map_.cend()) { |
| 948 | + throw std::runtime_error("unexpected vector dimension in InvertedIndex"); |
| 949 | + } |
925 | 950 | auto score = static_cast<float>(val); |
926 | 951 | if (metric_type_ == SparseMetricType::METRIC_BM25) { |
927 | 952 | score = bm25_params_->max_score_computer(val, row_sum); |
|
0 commit comments