VecImpl.h 3.2 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"
22
#include "VecIndex.h"
X
MS-154  
xj.lin 已提交
23 24 25


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

class VecIndexImpl : public VecIndex {
 public:
X
xj.lin 已提交
31 32
    explicit VecIndexImpl(std::shared_ptr<zilliz::knowhere::VectorIndex> index, const IndexType &type)
        : index_(std::move(index)), type(type) {};
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

    Status
    BuildAll(const long &nb,
             const float *xb,
             const long *ids,
             const Config &cfg,
             const long &nt,
             const float *xt) override;

    VecIndexPtr
    CopyToGpu(const int64_t &device_id, const Config &cfg) override;

    VecIndexPtr
    CopyToCpu(const Config &cfg) override;

    IndexType
    GetType() override;

    int64_t
    Dimension() override;

    int64_t
    Count() override;

    Status
    Add(const long &nb, const float *xb, const long *ids, const Config &cfg) override;

    zilliz::knowhere::BinarySet
    Serialize() override;

    Status
    Load(const zilliz::knowhere::BinarySet &index_binary) override;

    VecIndexPtr
    Clone() override;

    int64_t
    GetDeviceId() override;

    Status
    Search(const long &nq, const float *xq, float *dist, long *ids, const Config &cfg) override;
X
MS-154  
xj.lin 已提交
74

X
xj.lin 已提交
75
 protected:
X
xj.lin 已提交
76
    int64_t dim = 0;
77

X
xj.lin 已提交
78
    IndexType type = IndexType::INVALID;
79

X
MS-154  
xj.lin 已提交
80 81 82
    std::shared_ptr<zilliz::knowhere::VectorIndex> index_ = nullptr;
};

X
xj.lin 已提交
83 84
class IVFMixIndex : public VecIndexImpl {
 public:
X
xj.lin 已提交
85 86 87
    explicit IVFMixIndex(std::shared_ptr<zilliz::knowhere::VectorIndex> index, const IndexType &type)
        : VecIndexImpl(std::move(index), type) {};

88 89 90 91 92 93 94 95 96 97
    Status
    BuildAll(const long &nb,
             const float *xb,
             const long *ids,
             const Config &cfg,
             const long &nt,
             const float *xt) override;

    Status
    Load(const zilliz::knowhere::BinarySet &index_binary) override;
X
xj.lin 已提交
98 99
};

X
xj.lin 已提交
100 101
class BFIndex : public VecIndexImpl {
 public:
X
xj.lin 已提交
102 103
    explicit BFIndex(std::shared_ptr<zilliz::knowhere::VectorIndex> index) : VecIndexImpl(std::move(index),
                                                                                          IndexType::FAISS_IDMAP) {};
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

    ErrorCode
    Build(const Config &cfg);

    float *
    GetRawVectors();

    Status
    BuildAll(const long &nb,
             const float *xb,
             const long *ids,
             const Config &cfg,
             const long &nt,
             const float *xt) override;

    int64_t *
    GetRawIds();
X
xj.lin 已提交
121 122
};

X
MS-154  
xj.lin 已提交
123 124 125
}
}
}