DB.h 7.0 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
#pragma once
X
Xu Peng 已提交
13

14
#include <map>
Z
Zhiru Zhu 已提交
15 16
#include <memory>
#include <string>
17
#include <unordered_map>
Z
Zhiru Zhu 已提交
18 19
#include <vector>

X
Xu Peng 已提交
20
#include "Options.h"
X
Xu Peng 已提交
21
#include "Types.h"
22
#include "context/HybridSearchContext.h"
S
starlord 已提交
23
#include "meta/Meta.h"
24
#include "query/GeneralQuery.h"
Z
Zhiru Zhu 已提交
25
#include "server/context/Context.h"
S
starlord 已提交
26
#include "utils/Status.h"
X
Xu Peng 已提交
27

J
jinhai 已提交
28
namespace milvus {
X
Xu Peng 已提交
29
namespace engine {
X
Xu Peng 已提交
30 31 32 33

class Env;

class DB {
S
starlord 已提交
34
 public:
S
starlord 已提交
35
    DB() = default;
36

S
starlord 已提交
37
    DB(const DB&) = delete;
38

S
starlord 已提交
39 40
    DB&
    operator=(const DB&) = delete;
S
starlord 已提交
41 42

    virtual ~DB() = default;
X
Xu Peng 已提交
43

S
starlord 已提交
44 45
    virtual Status
    Start() = 0;
46

S
starlord 已提交
47 48 49 50
    virtual Status
    Stop() = 0;

    virtual Status
51
    CreateCollection(meta::CollectionSchema& table_schema_) = 0;
G
groot 已提交
52

S
starlord 已提交
53
    virtual Status
54
    DropCollection(const std::string& collection_id) = 0;
G
groot 已提交
55

S
starlord 已提交
56
    virtual Status
57
    DescribeCollection(meta::CollectionSchema& table_schema_) = 0;
G
groot 已提交
58

S
starlord 已提交
59
    virtual Status
G
groot 已提交
60
    HasCollection(const std::string& collection_id, bool& has_or_not) = 0;
G
groot 已提交
61

62
    virtual Status
G
groot 已提交
63
    HasNativeCollection(const std::string& collection_id, bool& has_or_not) = 0;
64

S
starlord 已提交
65
    virtual Status
66
    AllCollections(std::vector<std::string>& names) = 0;
G
groot 已提交
67

68
    virtual Status
69
    GetCollectionInfo(const std::string& collection_id, std::string& collection_info) = 0;
70

S
starlord 已提交
71
    virtual Status
72
    GetCollectionRowCount(const std::string& collection_id, uint64_t& row_count) = 0;
G
groot 已提交
73

S
starlord 已提交
74
    virtual Status
G
groot 已提交
75 76
    PreloadCollection(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
                      bool force = false) = 0;
G
groot 已提交
77

78 79 80
    virtual Status
    ReLoadSegmentsDeletedDocs(const std::string& collection_id, const std::vector<int64_t>& segment_ids) = 0;

S
starlord 已提交
81
    virtual Status
82
    UpdateCollectionFlag(const std::string& collection_id, int64_t flag) = 0;
S
starlord 已提交
83 84

    virtual Status
J
Jin Hai 已提交
85
    CreatePartition(const std::string& collection_id, const std::string& partition_name,
G
groot 已提交
86 87
                    const std::string& partition_tag) = 0;

G
groot 已提交
88 89 90
    virtual Status
    HasPartition(const std::string& collection_id, const std::string& tag, bool& has_or_not) = 0;

G
groot 已提交
91 92
    virtual Status
    DropPartition(const std::string& partition_name) = 0;
S
starlord 已提交
93 94

    virtual Status
J
Jin Hai 已提交
95
    DropPartitionByTag(const std::string& collection_id, const std::string& partition_tag) = 0;
S
starlord 已提交
96 97

    virtual Status
J
Jin Hai 已提交
98
    ShowPartitions(const std::string& collection_id, std::vector<meta::CollectionSchema>& partition_schema_array) = 0;
S
starlord 已提交
99 100

    virtual Status
J
Jin Hai 已提交
101
    InsertVectors(const std::string& collection_id, const std::string& partition_tag, VectorsData& vectors) = 0;
G
groot 已提交
102

103 104 105
    virtual Status
    DeleteEntities(const std::string& collection_id, IDNumbers entity_ids) = 0;

106
    virtual Status
J
Jin Hai 已提交
107
    Flush(const std::string& collection_id) = 0;
108 109 110 111 112

    virtual Status
    Flush() = 0;

    virtual Status
G
groot 已提交
113 114
    Compact(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
            double threshold = 0.0) = 0;
115 116

    virtual Status
G
groot 已提交
117
    GetVectorsByID(const engine::meta::CollectionSchema& collection, const IDNumbers& id_array,
118
                   std::vector<engine::VectorsData>& vectors) = 0;
119

Y
yukun 已提交
120 121
    virtual Status
    GetEntitiesByID(const std::string& collection_id, const IDNumbers& id_array,
F
fishpenguin 已提交
122 123
                    const std::vector<std::string>& field_names, std::vector<engine::VectorsData>& vectors,
                    std::vector<engine::AttrsData>& attrs) = 0;
Y
yukun 已提交
124

125
    virtual Status
J
Jin Hai 已提交
126
    GetVectorIDs(const std::string& collection_id, const std::string& segment_id, IDNumbers& vector_ids) = 0;
127 128 129 130 131

    //    virtual Status
    //    Merge(const std::set<std::string>& table_ids) = 0;

    virtual Status
132 133 134
    QueryByIDs(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
               const std::vector<std::string>& partition_tags, uint64_t k, const milvus::json& extra_params,
               const IDNumbers& id_array, ResultIds& result_ids, ResultDistances& result_distances) = 0;
G
groot 已提交
135 136

    virtual Status
J
Jin Hai 已提交
137
    Query(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
138
          const std::vector<std::string>& partition_tags, uint64_t k, const milvus::json& extra_params,
Y
yukun 已提交
139
          VectorsData& vectors, ResultIds& result_ids, ResultDistances& result_distances) = 0;
G
groot 已提交
140 141

    virtual Status
142
    QueryByFileID(const std::shared_ptr<server::Context>& context, const std::vector<std::string>& file_ids, uint64_t k,
Y
yukun 已提交
143
                  const milvus::json& extra_params, VectorsData& vectors, ResultIds& result_ids,
144
                  ResultDistances& result_distances) = 0;
S
starlord 已提交
145 146 147 148 149

    virtual Status
    Size(uint64_t& result) = 0;

    virtual Status
G
groot 已提交
150 151
    CreateIndex(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
                const CollectionIndex& index) = 0;
G
groot 已提交
152

S
starlord 已提交
153
    virtual Status
154
    DescribeIndex(const std::string& collection_id, CollectionIndex& index) = 0;
G
groot 已提交
155

S
starlord 已提交
156
    virtual Status
J
Jin Hai 已提交
157
    DropIndex(const std::string& collection_id) = 0;
S
starlord 已提交
158 159 160

    virtual Status
    DropAll() = 0;
161 162 163 164 165 166 167 168

    virtual Status
    CreateHybridCollection(meta::CollectionSchema& collection_schema, meta::hybrid::FieldsSchema& fields_schema) = 0;

    virtual Status
    DescribeHybridCollection(meta::CollectionSchema& collection_schema, meta::hybrid::FieldsSchema& fields_schema) = 0;

    virtual Status
169 170
    InsertEntities(const std::string& collection_id, const std::string& partition_tag,
                   const std::vector<std::string>& field_names, Entity& entity,
171 172 173 174
                   std::unordered_map<std::string, meta::hybrid::DataType>& field_types) = 0;

    virtual Status
    HybridQuery(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
Y
yukun 已提交
175 176
                const std::vector<std::string>& partition_tags, query::GeneralQueryPtr general_query,
                query::QueryPtr query_ptr, std::vector<std::string>& field_name,
Y
yukun 已提交
177 178
                std::unordered_map<std::string, engine::meta::hybrid::DataType>& attr_type,
                engine::QueryResult& result) = 0;
Y
yukun 已提交
179 180 181 182 183 184 185 186 187
    virtual Status
    FlushAttrsIndex(const std::string& collection_id) = 0;

    virtual Status
    CreateStructuredIndex(const std::string& collection_id, const std::vector<std::string>& field_names,
                          const std::unordered_map<std::string, meta::hybrid::DataType>& attr_types,
                          const std::unordered_map<std::string, std::vector<uint8_t>>& attr_data,
                          std::unordered_map<std::string, int64_t>& attr_size,
                          std::unordered_map<std::string, knowhere::IndexPtr>& attr_indexes) = 0;
S
starlord 已提交
188
};  // DB
X
Xu Peng 已提交
189

S
starlord 已提交
190 191
using DBPtr = std::shared_ptr<DB>;

S
starlord 已提交
192 193
}  // namespace engine
}  // namespace milvus