DB.h 5.9 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

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

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

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

class Env;

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

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

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

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

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

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

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

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

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

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

61
    virtual Status
62
    HasNativeCollection(const std::string& collection_id, bool& has_or_not_) = 0;
63

S
starlord 已提交
64
    virtual Status
65
    AllCollections(std::vector<meta::CollectionSchema>& table_schema_array) = 0;
G
groot 已提交
66

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

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

S
starlord 已提交
73
    virtual Status
74
    PreloadCollection(const std::string& collection_id) = 0;
G
groot 已提交
75

S
starlord 已提交
76
    virtual Status
77
    UpdateCollectionFlag(const std::string& collection_id, int64_t flag) = 0;
S
starlord 已提交
78 79

    virtual Status
J
Jin Hai 已提交
80
    CreatePartition(const std::string& collection_id, const std::string& partition_name,
G
groot 已提交
81 82 83 84
                    const std::string& partition_tag) = 0;

    virtual Status
    DropPartition(const std::string& partition_name) = 0;
S
starlord 已提交
85 86

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

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

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

    virtual Status
J
Jin Hai 已提交
96
    DeleteVector(const std::string& collection_id, IDNumber vector_id) = 0;
97 98

    virtual Status
J
Jin Hai 已提交
99
    DeleteVectors(const std::string& collection_id, IDNumbers vector_ids) = 0;
100 101

    virtual Status
J
Jin Hai 已提交
102
    Flush(const std::string& collection_id) = 0;
103 104 105 106 107

    virtual Status
    Flush() = 0;

    virtual Status
G
groot 已提交
108
    Compact(const std::string& collection_id, double threshold = 0.0) = 0;
109 110

    virtual Status
111 112
    GetVectorsByID(const std::string& collection_id, const IDNumbers& id_array,
                   std::vector<engine::VectorsData>& vectors) = 0;
113 114

    virtual Status
J
Jin Hai 已提交
115
    GetVectorIDs(const std::string& collection_id, const std::string& segment_id, IDNumbers& vector_ids) = 0;
116 117 118 119 120

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

    virtual Status
121 122 123
    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 已提交
124 125

    virtual Status
J
Jin Hai 已提交
126
    Query(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
127 128
          const std::vector<std::string>& partition_tags, uint64_t k, const milvus::json& extra_params,
          const VectorsData& vectors, ResultIds& result_ids, ResultDistances& result_distances) = 0;
G
groot 已提交
129 130

    virtual Status
131 132 133
    QueryByFileID(const std::shared_ptr<server::Context>& context, const std::vector<std::string>& file_ids, uint64_t k,
                  const milvus::json& extra_params, const VectorsData& vectors, ResultIds& result_ids,
                  ResultDistances& result_distances) = 0;
S
starlord 已提交
134 135 136 137 138

    virtual Status
    Size(uint64_t& result) = 0;

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

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

S
starlord 已提交
145
    virtual Status
J
Jin Hai 已提交
146
    DropIndex(const std::string& collection_id) = 0;
S
starlord 已提交
147 148 149

    virtual Status
    DropAll() = 0;
150 151 152 153 154 155 156 157

    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
158 159
    InsertEntities(const std::string& collection_id, const std::string& partition_tag,
                   const std::vector<std::string>& field_names, Entity& entity,
160 161 162 163 164 165 166 167
                   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,
                const std::vector<std::string>& partition_tags, context::HybridSearchContextPtr hybrid_search_context,
                query::GeneralQueryPtr general_query,
                std::unordered_map<std::string, engine::meta::hybrid::DataType>& attr_type, uint64_t& nq,
                engine::ResultIds& result_ids, engine::ResultDistances& result_distances) = 0;
S
starlord 已提交
168
};  // DB
X
Xu Peng 已提交
169

S
starlord 已提交
170 171
using DBPtr = std::shared_ptr<DB>;

S
starlord 已提交
172 173
}  // namespace engine
}  // namespace milvus