vec_impl.h 3.0 KB
Newer Older
X
MS-154  
xj.lin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "knowhere/index/vector_index/vector_index.h"

#include "vec_index.h"


namespace zilliz {
X
xj.lin 已提交
15
namespace milvus {
X
MS-154  
xj.lin 已提交
16 17 18 19
namespace engine {

class VecIndexImpl : public VecIndex {
 public:
X
xj.lin 已提交
20 21
    explicit VecIndexImpl(std::shared_ptr<zilliz::knowhere::VectorIndex> index, const IndexType &type)
        : index_(std::move(index)), type(type) {};
X
xj.lin 已提交
22 23 24 25 26 27
    server::KnowhereError BuildAll(const long &nb,
                                   const float *xb,
                                   const long *ids,
                                   const Config &cfg,
                                   const long &nt,
                                   const float *xt) override;
28 29
    VecIndexPtr CopyToGpu(const int64_t &device_id, const Config &cfg) override;
    VecIndexPtr CopyToCpu(const Config &cfg) override;
X
xj.lin 已提交
30
    IndexType GetType() override;
X
xj.lin 已提交
31 32
    int64_t Dimension() override;
    int64_t Count() override;
X
xj.lin 已提交
33
    server::KnowhereError Add(const long &nb, const float *xb, const long *ids, const Config &cfg) override;
X
MS-154  
xj.lin 已提交
34
    zilliz::knowhere::BinarySet Serialize() override;
X
xj.lin 已提交
35 36
    server::KnowhereError Load(const zilliz::knowhere::BinarySet &index_binary) override;
    server::KnowhereError Search(const long &nq, const float *xq, float *dist, long *ids, const Config &cfg) override;
X
MS-154  
xj.lin 已提交
37

X
xj.lin 已提交
38
 protected:
X
xj.lin 已提交
39
    int64_t dim = 0;
X
xj.lin 已提交
40
    IndexType type = IndexType::INVALID;
X
MS-154  
xj.lin 已提交
41 42 43
    std::shared_ptr<zilliz::knowhere::VectorIndex> index_ = nullptr;
};

X
xj.lin 已提交
44 45
class IVFMixIndex : public VecIndexImpl {
 public:
X
xj.lin 已提交
46 47 48
    explicit IVFMixIndex(std::shared_ptr<zilliz::knowhere::VectorIndex> index, const IndexType &type)
        : VecIndexImpl(std::move(index), type) {};

X
xj.lin 已提交
49 50 51 52 53 54 55
    server::KnowhereError BuildAll(const long &nb,
                                   const float *xb,
                                   const long *ids,
                                   const Config &cfg,
                                   const long &nt,
                                   const float *xt) override;
    server::KnowhereError Load(const zilliz::knowhere::BinarySet &index_binary) override;
X
xj.lin 已提交
56 57
};

X
xj.lin 已提交
58 59
class BFIndex : public VecIndexImpl {
 public:
X
xj.lin 已提交
60 61
    explicit BFIndex(std::shared_ptr<zilliz::knowhere::VectorIndex> index) : VecIndexImpl(std::move(index),
                                                                                          IndexType::FAISS_IDMAP) {};
X
xj.lin 已提交
62
    server::KnowhereError Build(const Config& cfg);
X
xj.lin 已提交
63
    float *GetRawVectors();
X
xj.lin 已提交
64 65 66 67 68 69
    server::KnowhereError BuildAll(const long &nb,
                                   const float *xb,
                                   const long *ids,
                                   const Config &cfg,
                                   const long &nt,
                                   const float *xt) override;
X
xj.lin 已提交
70
    int64_t *GetRawIds();
X
xj.lin 已提交
71 72
};

X
MS-154  
xj.lin 已提交
73 74 75
}
}
}