Types.h 5.8 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
13

G
groot 已提交
14
#include <faiss/Index.h>
15 16

#include <cstdint>
G
groot 已提交
17
#include <map>
C
Cai Yudong 已提交
18
#include <memory>
G
groot 已提交
19 20
#include <set>
#include <string>
21
#include <unordered_map>
S
starlord 已提交
22
#include <utility>
S
starlord 已提交
23
#include <vector>
24

G
groot 已提交
25
#include "cache/DataObj.h"
G
groot 已提交
26
#include "db/Constants.h"
Y
yukun 已提交
27
#include "knowhere/index/vector_index/VecIndex.h"
28
#include "utils/Json.h"
29

J
jinhai 已提交
30
namespace milvus {
31 32
namespace engine {

G
groot 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
extern const char* FIELD_UID;

extern const char* ELEMENT_RAW_DATA;
extern const char* ELEMENT_BLOOM_FILTER;
extern const char* ELEMENT_DELETED_DOCS;
extern const char* ELEMENT_INDEX_COMPRESS;

extern const char* PARAM_UID_AUTOGEN;
extern const char* PARAM_DIMENSION;
extern const char* PARAM_INDEX_TYPE;
extern const char* PARAM_INDEX_METRIC_TYPE;
extern const char* PARAM_INDEX_EXTRA_PARAMS;
extern const char* PARAM_SEGMENT_ROW_COUNT;

extern const char* DEFAULT_STRUCTURED_INDEX;
extern const char* DEFAULT_PARTITON_TAG;

///////////////////////////////////////////////////////////////////////////////////////////////////
G
groot 已提交
51
using idx_t = int64_t;
G
groot 已提交
52
using offset_t = int32_t;
G
groot 已提交
53
using date_t = int32_t;
G
groot 已提交
54

G
groot 已提交
55
using IDNumbers = std::vector<idx_t>;
56

G
groot 已提交
57 58 59 60 61 62
using VectorDistance = faiss::Index::distance_t;
using VectorDistances = std::vector<VectorDistance>;

using ResultIds = std::vector<faiss::Index::idx_t>;
using ResultDistances = std::vector<faiss::Index::distance_t>;

G
groot 已提交
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
enum class DataType {
G
groot 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    NONE = 0,
    BOOL = 1,
    INT8 = 2,
    INT16 = 3,
    INT32 = 4,
    INT64 = 5,

    FLOAT = 10,
    DOUBLE = 11,

    STRING = 20,

    VECTOR_BINARY = 100,
    VECTOR_FLOAT = 101,
};
X
Xu Peng 已提交
80

G
groot 已提交
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
enum class FieldElementType {
G
groot 已提交
83 84 85 86 87 88 89 90 91
    FET_NONE = 0,
    FET_RAW = 1,
    FET_BLOOM_FILTER = 2,
    FET_DELETED_DOCS = 3,
    FET_INDEX = 4,
    FET_COMPRESS_SQ8 = 5,
};

///////////////////////////////////////////////////////////////////////////////////////////////////
G
groot 已提交
92 93 94 95 96 97 98 99 100 101 102 103
class BinaryData : public cache::DataObj {
 public:
    int64_t
    Size() {
        return data_.size();
    }

 public:
    std::vector<uint8_t> data_;
};
using BinaryDataPtr = std::shared_ptr<BinaryData>;

G
groot 已提交
104
///////////////////////////////////////////////////////////////////////////////////////////////////
G
groot 已提交
105 106 107 108
class VaribleData : public cache::DataObj {
 public:
    int64_t
    Size() {
G
groot 已提交
109
        return data_.size() + offset_.size() * sizeof(int64_t);
G
groot 已提交
110 111 112 113 114 115 116 117
    }

 public:
    std::vector<uint8_t> data_;
    std::vector<int64_t> offset_;
};
using VaribleDataPtr = std::shared_ptr<VaribleData>;

G
groot 已提交
118
///////////////////////////////////////////////////////////////////////////////////////////////////
G
groot 已提交
119
using FIELD_TYPE_MAP = std::unordered_map<std::string, DataType>;
Y
yukun 已提交
120
using FIELD_WIDTH_MAP = std::unordered_map<std::string, int64_t>;
G
groot 已提交
121 122
using FIXEDX_FIELD_MAP = std::unordered_map<std::string, BinaryDataPtr>;
using VARIABLE_FIELD_MAP = std::unordered_map<std::string, VaribleDataPtr>;
Y
yukun 已提交
123 124 125
using VECTOR_INDEX_MAP = std::unordered_map<std::string, knowhere::VecIndexPtr>;
using STRUCTURED_INDEX_MAP = std::unordered_map<std::string, knowhere::IndexPtr>;

G
groot 已提交
126
///////////////////////////////////////////////////////////////////////////////////////////////////
Y
yukun 已提交
127 128 129 130 131 132 133
struct DataChunk {
    int64_t count_ = 0;
    FIXEDX_FIELD_MAP fixed_fields_;
    VARIABLE_FIELD_MAP variable_fields_;
};
using DataChunkPtr = std::shared_ptr<DataChunk>;

G
groot 已提交
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
struct CollectionIndex {
136
    std::string index_name_;
G
groot 已提交
137
    std::string index_type_;
G
groot 已提交
138
    std::string metric_name_;
G
groot 已提交
139
    milvus::json extra_params_ = {{"nlist", 2048}};
140
};
141

G
groot 已提交
142
///////////////////////////////////////////////////////////////////////////////////////////////////
G
groot 已提交
143 144 145 146 147 148 149
struct VectorsData {
    uint64_t vector_count_ = 0;
    std::vector<float> float_data_;
    std::vector<uint8_t> binary_data_;
    IDNumbers id_array_;
};

G
groot 已提交
150
///////////////////////////////////////////////////////////////////////////////////////////////////
Y
yukun 已提交
151 152
struct AttrsData {
    uint64_t attr_count_ = 0;
G
groot 已提交
153
    std::unordered_map<std::string, engine::DataType> attr_type_;
Y
yukun 已提交
154 155 156 157
    std::unordered_map<std::string, std::vector<uint8_t>> attr_data_;
    IDNumbers id_array_;
};

G
groot 已提交
158
///////////////////////////////////////////////////////////////////////////////////////////////////
Y
yukun 已提交
159 160 161 162
struct QueryResult {
    uint64_t row_num_;
    engine::ResultIds result_ids_;
    engine::ResultDistances result_distances_;
Y
yukun 已提交
163
    engine::DataChunkPtr data_chunk_;
Y
yukun 已提交
164
};
C
Cai Yudong 已提交
165
using QueryResultPtr = std::shared_ptr<QueryResult>;
Y
yukun 已提交
166

G
groot 已提交
167 168 169 170
///////////////////////////////////////////////////////////////////////////////////////////////////
struct DBMetaOptions {
    std::string path_;
    std::string backend_uri_;
171
};
G
groot 已提交
172

G
groot 已提交
173 174 175
///////////////////////////////////////////////////////////////////////////////////////////////////
struct DBOptions {
    typedef enum { SINGLE = 0, CLUSTER_READONLY, CLUSTER_WRITABLE } MODE;
C
Cai Yudong 已提交
176

G
groot 已提交
177 178
    DBMetaOptions meta_;
    int mode_ = MODE::SINGLE;
C
Cai Yudong 已提交
179

G
groot 已提交
180
    size_t insert_buffer_size_ = 4 * GB;
G
groot 已提交
181

G
groot 已提交
182
    int64_t auto_flush_interval_ = 1;
G
groot 已提交
183

G
groot 已提交
184 185 186
    bool metric_enable_ = false;

    // wal relative configurations
G
groot 已提交
187
    bool wal_enable_ = false;
188
    std::string wal_path_;
G
groot 已提交
189 190 191 192

    // transcript configurations
    bool transcript_enable_ = false;
    std::string replay_script_path_;  // for replay
193
};
C
Cai Yudong 已提交
194

S
starlord 已提交
195 196
}  // namespace engine
}  // namespace milvus