Coverage Report

Created: 2026-03-15 08:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/index/ann/ann_index.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "storage/index/ann/ann_index.h"
19
20
#include "common/metrics/doris_metrics.h"
21
#include "exprs/function/array/function_array_distance.h"
22
23
namespace doris::segment_v2 {
24
25
7
std::string metric_to_string(AnnIndexMetric metric) {
26
7
    switch (metric) {
27
4
    case AnnIndexMetric::L2:
28
4
        return L2Distance::name;
29
1
    case AnnIndexMetric::IP:
30
1
        return InnerProduct::name;
31
2
    default:
32
2
        return "UNKNOWN";
33
7
    }
34
7
}
35
36
54
AnnIndexMetric string_to_metric(const std::string& metric) {
37
54
    if (metric == L2Distance::name) {
38
50
        return AnnIndexMetric::L2;
39
50
    } else if (metric == InnerProduct::name) {
40
4
        return AnnIndexMetric::IP;
41
4
    } else {
42
0
        return AnnIndexMetric::UNKNOWN;
43
0
    }
44
54
}
45
46
0
std::string ann_index_type_to_string(AnnIndexType type) {
47
0
    switch (type) {
48
0
    case AnnIndexType::UNKNOWN:
49
0
        return "unknown";
50
0
    case AnnIndexType::HNSW:
51
0
        return "hnsw";
52
0
    case AnnIndexType::IVF:
53
0
        return "ivf";
54
0
    default:
55
0
        return "unknown";
56
0
    }
57
0
}
58
59
46
AnnIndexType string_to_ann_index_type(const std::string& type) {
60
46
    if (type == "hnsw") {
61
42
        return AnnIndexType::HNSW;
62
42
    } else if (type == "ivf") {
63
4
        return AnnIndexType::IVF;
64
4
    } else {
65
0
        return AnnIndexType::UNKNOWN;
66
0
    }
67
46
}
68
69
141
VectorIndex::VectorIndex() {
70
141
    DorisMetrics::instance()->ann_index_in_memory_cnt->increment(1);
71
141
}
72
73
141
VectorIndex::~VectorIndex() {
74
141
    DorisMetrics::instance()->ann_index_in_memory_cnt->increment(-1);
75
141
}
76
77
} // namespace doris::segment_v2