vec_impl.h 2.6 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
MS-154  
xj.lin 已提交
22 23 24 25 26 27
    void BuildAll(const long &nb,
                  const float *xb,
                  const long *ids,
                  const Config &cfg,
                  const long &nt,
                  const float *xt) override;
X
xj.lin 已提交
28
    IndexType GetType() override;
X
xj.lin 已提交
29 30
    int64_t Dimension() override;
    int64_t Count() override;
X
MS-154  
xj.lin 已提交
31 32 33 34 35
    void Add(const long &nb, const float *xb, const long *ids, const Config &cfg) override;
    zilliz::knowhere::BinarySet Serialize() override;
    void Load(const zilliz::knowhere::BinarySet &index_binary) override;
    void Search(const long &nq, const float *xq, float *dist, long *ids, const Config &cfg) override;

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

X
xj.lin 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54
class IVFMixIndex : public VecIndexImpl {
 public:
    explicit IVFMixIndex(std::shared_ptr<zilliz::knowhere::VectorIndex> index) : VecIndexImpl(std::move(index),
                                                                                              IndexType::FAISS_IVFFLAT_MIX) {};
    void BuildAll(const long &nb,
                  const float *xb,
                  const long *ids,
                  const Config &cfg,
                  const long &nt,
                  const float *xt) override;
    void Load(const zilliz::knowhere::BinarySet &index_binary) override;
};

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

X
MS-154  
xj.lin 已提交
70 71 72
}
}
}