ExecutionEngine.h 3.3 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
2
//
3 4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
J
jinhai 已提交
5
//
6 7 8 9 10
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
J
jinhai 已提交
11

X
Xu Peng 已提交
12 13
#pragma once

X
Xu Peng 已提交
14
#include <memory>
S
starlord 已提交
15
#include <string>
S
starlord 已提交
16
#include <vector>
X
Xu Peng 已提交
17

18
#include "utils/Json.h"
T
Tinkerrr 已提交
19 20
#include "utils/Status.h"

J
jinhai 已提交
21
namespace milvus {
X
Xu Peng 已提交
22 23
namespace engine {

Z
zirui.chen 已提交
24
// TODO(linxj): replace with VecIndex::IndexType
G
groot 已提交
25
enum class EngineType {
G
groot 已提交
26
    INVALID = 0,
G
groot 已提交
27 28
    FAISS_IDMAP = 1,
    FAISS_IVFFLAT,
S
starlord 已提交
29
    FAISS_IVFSQ8,
X
xj.lin 已提交
30
    NSG_MIX,
W
wxyu 已提交
31
    FAISS_IVFSQ8H,
Z
zirui.chen 已提交
32
    FAISS_PQ,
33 34
    SPTAG_KDT,
    SPTAG_BKT,
G
groot 已提交
35 36
    FAISS_BIN_IDMAP,
    FAISS_BIN_IVFFLAT,
T
Tinkerrr 已提交
37 38
    HNSW,
    MAX_VALUE = HNSW,
G
groot 已提交
39 40
};

41
enum class MetricType {
G
groot 已提交
42 43 44 45 46 47
    L2 = 1,        // Euclidean Distance
    IP = 2,        // Cosine Similarity
    HAMMING = 3,   // Hamming Distance
    JACCARD = 4,   // Jaccard Distance
    TANIMOTO = 5,  // Tanimoto Distance
    MAX_VALUE = TANIMOTO,
48 49
};

50
class ExecutionEngine {
S
starlord 已提交
51
 public:
S
starlord 已提交
52 53
    virtual Status
    AddWithIds(int64_t n, const float* xdata, const int64_t* xids) = 0;
54

G
groot 已提交
55 56 57
    virtual Status
    AddWithIds(int64_t n, const uint8_t* xdata, const int64_t* xids) = 0;

S
starlord 已提交
58 59
    virtual size_t
    Count() const = 0;
60

S
starlord 已提交
61 62
    virtual size_t
    Size() const = 0;
63

S
starlord 已提交
64 65
    virtual size_t
    Dimension() const = 0;
G
groot 已提交
66

S
starlord 已提交
67 68
    virtual size_t
    PhysicalSize() const = 0;
69

S
starlord 已提交
70 71
    virtual Status
    Serialize() = 0;
72

S
starlord 已提交
73 74
    virtual Status
    Load(bool to_cache = true) = 0;
75

S
starlord 已提交
76
    virtual Status
W
wxyu 已提交
77
    CopyToGpu(uint64_t device_id, bool hybrid) = 0;
78

Y
Yu Kun 已提交
79 80 81
    virtual Status
    CopyToIndexFileToGpu(uint64_t device_id) = 0;

S
starlord 已提交
82 83
    virtual Status
    CopyToCpu() = 0;
84

85 86
    //    virtual std::shared_ptr<ExecutionEngine>
    //    Clone() = 0;
W
wxyu 已提交
87

88 89 90 91 92 93
    //    virtual Status
    //    Merge(const std::string& location) = 0;

    virtual Status
    GetVectorByID(const int64_t& id, float* vector, bool hybrid) = 0;

S
starlord 已提交
94
    virtual Status
95
    GetVectorByID(const int64_t& id, uint8_t* vector, bool hybrid) = 0;
96

S
starlord 已提交
97
    virtual Status
98 99
    Search(int64_t n, const float* data, int64_t k, const milvus::json& extra_params, float* distances, int64_t* labels,
           bool hybrid) = 0;
100

G
groot 已提交
101
    virtual Status
102 103
    Search(int64_t n, const uint8_t* data, int64_t k, const milvus::json& extra_params, float* distances,
           int64_t* labels, bool hybrid) = 0;
G
groot 已提交
104

105
    virtual Status
106 107
    Search(int64_t n, const std::vector<int64_t>& ids, int64_t k, const milvus::json& extra_params, float* distances,
           int64_t* labels, bool hybrid) = 0;
108

S
starlord 已提交
109 110
    virtual std::shared_ptr<ExecutionEngine>
    BuildIndex(const std::string& location, EngineType engine_type) = 0;
111

S
starlord 已提交
112 113
    virtual Status
    Cache() = 0;
Y
yu yunfeng 已提交
114

S
starlord 已提交
115 116
    virtual Status
    GpuCache(uint64_t gpu_id) = 0;
Y
Yu Kun 已提交
117

S
starlord 已提交
118 119
    virtual Status
    Init() = 0;
S
starlord 已提交
120

S
starlord 已提交
121 122
    virtual EngineType
    IndexEngineType() const = 0;
S
starlord 已提交
123

S
starlord 已提交
124 125
    virtual MetricType
    IndexMetricType() const = 0;
126

S
starlord 已提交
127 128
    virtual std::string
    GetLocation() const = 0;
129 130
};

G
groot 已提交
131 132
using ExecutionEnginePtr = std::shared_ptr<ExecutionEngine>;

S
starlord 已提交
133 134
}  // namespace engine
}  // namespace milvus