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

#pragma once

#include <string>
#include <memory>

X
xj.lin 已提交
12 13
#include "utils/Error.h"

X
MS-154  
xj.lin 已提交
14 15 16 17 18
#include "knowhere/common/config.h"
#include "knowhere/common/binary_set.h"


namespace zilliz {
X
xj.lin 已提交
19
namespace milvus {
X
MS-154  
xj.lin 已提交
20 21 22 23 24
namespace engine {

// TODO(linxj): jsoncons => rapidjson or other.
using Config = zilliz::knowhere::Config;

X
xj.lin 已提交
25 26 27 28 29 30 31 32 33
enum class IndexType {
    INVALID = 0,
    FAISS_IDMAP = 1,
    FAISS_IVFFLAT_CPU,
    FAISS_IVFFLAT_GPU,
    FAISS_IVFFLAT_MIX, // build on gpu and search on cpu
    FAISS_IVFPQ_CPU,
    FAISS_IVFPQ_GPU,
    SPTAG_KDT_RNT_CPU,
X
xj.lin 已提交
34
    FAISS_IVFSQ8_MIX,
X
xj.lin 已提交
35
    NSG_MIX,
X
xj.lin 已提交
36 37
};

38 39 40
class VecIndex;
using VecIndexPtr = std::shared_ptr<VecIndex>;

X
MS-154  
xj.lin 已提交
41 42
class VecIndex {
 public:
X
xj.lin 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    virtual server::KnowhereError BuildAll(const long &nb,
                                           const float *xb,
                                           const long *ids,
                                           const Config &cfg,
                                           const long &nt = 0,
                                           const float *xt = nullptr) = 0;

    virtual server::KnowhereError Add(const long &nb,
                                      const float *xb,
                                      const long *ids,
                                      const Config &cfg = Config()) = 0;

    virtual server::KnowhereError Search(const long &nq,
                                         const float *xq,
                                         float *dist,
                                         long *ids,
                                         const Config &cfg = Config()) = 0;
X
MS-154  
xj.lin 已提交
60

61 62 63 64 65
    virtual VecIndexPtr CopyToGpu(const int64_t& device_id,
                                  const Config &cfg = Config()) = 0;

    virtual VecIndexPtr CopyToCpu(const Config &cfg = Config()) = 0;

X
xj.lin 已提交
66 67
    virtual IndexType GetType() = 0;

X
xj.lin 已提交
68 69 70 71
    virtual int64_t Dimension() = 0;

    virtual int64_t Count() = 0;

X
MS-154  
xj.lin 已提交
72 73
    virtual zilliz::knowhere::BinarySet Serialize() = 0;

X
xj.lin 已提交
74
    virtual server::KnowhereError Load(const zilliz::knowhere::BinarySet &index_binary) = 0;
X
MS-154  
xj.lin 已提交
75 76
};

X
xj.lin 已提交
77
extern server::KnowhereError write_index(VecIndexPtr index, const std::string &location);
X
xj.lin 已提交
78 79

extern VecIndexPtr read_index(const std::string &location);
X
xj.lin 已提交
80 81

extern VecIndexPtr GetVecIndexFactory(const IndexType &type);
X
MS-154  
xj.lin 已提交
82

X
xj.lin 已提交
83
extern VecIndexPtr LoadVecIndex(const IndexType &index_type, const zilliz::knowhere::BinarySet &index_binary);
X
MS-154  
xj.lin 已提交
84

X
xj.lin 已提交
85 86
extern void AutoGenParams(const IndexType& type, const long& size, Config& cfg);

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