vec_impl.h 3.5 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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
//
//   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.

X
MS-154  
xj.lin 已提交
18 19 20

#pragma once

X
xiaojun.lin 已提交
21
#include "knowhere/index/vector_index/VectorIndex.h"
X
MS-154  
xj.lin 已提交
22 23 24 25 26

#include "vec_index.h"


namespace zilliz {
X
xj.lin 已提交
27
namespace milvus {
X
MS-154  
xj.lin 已提交
28 29 30 31
namespace engine {

class VecIndexImpl : public VecIndex {
 public:
X
xj.lin 已提交
32 33
    explicit VecIndexImpl(std::shared_ptr<zilliz::knowhere::VectorIndex> index, const IndexType &type)
        : index_(std::move(index)), type(type) {};
S
starlord 已提交
34
    ErrorCode BuildAll(const long &nb,
X
xj.lin 已提交
35 36 37 38 39
                                   const float *xb,
                                   const long *ids,
                                   const Config &cfg,
                                   const long &nt,
                                   const float *xt) override;
40 41
    VecIndexPtr CopyToGpu(const int64_t &device_id, const Config &cfg) override;
    VecIndexPtr CopyToCpu(const Config &cfg) override;
X
xj.lin 已提交
42
    IndexType GetType() override;
X
xj.lin 已提交
43 44
    int64_t Dimension() override;
    int64_t Count() override;
S
starlord 已提交
45
    ErrorCode Add(const long &nb, const float *xb, const long *ids, const Config &cfg) override;
X
MS-154  
xj.lin 已提交
46
    zilliz::knowhere::BinarySet Serialize() override;
S
starlord 已提交
47
    ErrorCode Load(const zilliz::knowhere::BinarySet &index_binary) override;
48 49
    VecIndexPtr Clone() override;
    int64_t GetDeviceId() override;
S
starlord 已提交
50
    ErrorCode Search(const long &nq, const float *xq, float *dist, long *ids, const Config &cfg) override;
X
MS-154  
xj.lin 已提交
51

X
xj.lin 已提交
52
 protected:
X
xj.lin 已提交
53
    int64_t dim = 0;
X
xj.lin 已提交
54
    IndexType type = IndexType::INVALID;
X
MS-154  
xj.lin 已提交
55 56 57
    std::shared_ptr<zilliz::knowhere::VectorIndex> index_ = nullptr;
};

X
xj.lin 已提交
58 59
class IVFMixIndex : public VecIndexImpl {
 public:
X
xj.lin 已提交
60 61 62
    explicit IVFMixIndex(std::shared_ptr<zilliz::knowhere::VectorIndex> index, const IndexType &type)
        : VecIndexImpl(std::move(index), type) {};

S
starlord 已提交
63
    ErrorCode BuildAll(const long &nb,
X
xj.lin 已提交
64 65 66 67 68
                                   const float *xb,
                                   const long *ids,
                                   const Config &cfg,
                                   const long &nt,
                                   const float *xt) override;
S
starlord 已提交
69
    ErrorCode Load(const zilliz::knowhere::BinarySet &index_binary) override;
X
xj.lin 已提交
70 71
};

X
xj.lin 已提交
72 73
class BFIndex : public VecIndexImpl {
 public:
X
xj.lin 已提交
74 75
    explicit BFIndex(std::shared_ptr<zilliz::knowhere::VectorIndex> index) : VecIndexImpl(std::move(index),
                                                                                          IndexType::FAISS_IDMAP) {};
S
starlord 已提交
76
    ErrorCode Build(const Config& cfg);
X
xj.lin 已提交
77
    float *GetRawVectors();
S
starlord 已提交
78
    ErrorCode BuildAll(const long &nb,
X
xj.lin 已提交
79 80 81 82 83
                                   const float *xb,
                                   const long *ids,
                                   const Config &cfg,
                                   const long &nt,
                                   const float *xt) override;
X
xj.lin 已提交
84
    int64_t *GetRawIds();
X
xj.lin 已提交
85 86
};

X
MS-154  
xj.lin 已提交
87 88 89
}
}
}