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

#pragma once

X
xj.lin 已提交
9 10 11 12 13 14
//#include <vector>
//#include <string>
//#include <unordered_map>
//#include <memory>
//#include <fstream>
//
X
xj.lin 已提交
15 16
#include "faiss/AutoTune.h"
#include "faiss/index_io.h"
X
xj.lin 已提交
17 18
//
//#include "Operand.h"
X
xj.lin 已提交
19

X
xj.lin 已提交
20
#include "knowhere/vec_index.h"
X
xj.lin 已提交
21 22 23


namespace zilliz {
J
jinhai 已提交
24
namespace milvus {
X
xj.lin 已提交
25 26
namespace engine {

X
xj.lin 已提交
27 28 29 30 31
using Index_ptr = VecIndexPtr;

#if 0
//class Index;
//using Index_ptr = std::shared_ptr<Index>;
X
Xu Peng 已提交
32

X
xj.lin 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45
class Index {
    typedef long idx_t;

public:
    int dim;         ///< std::vector dimension
    idx_t ntotal;    ///< total nb of indexed std::vectors
    bool store_on_gpu;

    explicit Index(const std::shared_ptr<faiss::Index> &raw_index);

    virtual bool reset();

    /**
X
xj.lin 已提交
46 47 48 49 50
    * @brief Same as add, but stores xids instead of sequential ids.
    *
    * @param data input matrix, size n * d
    * @param if ids is not empty ids for the std::vectors
    */
X
xj.lin 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63
    virtual bool add_with_ids(idx_t n, const float *xdata, const long *xids);

    /**
    * @brief for each query std::vector, find its k nearest neighbors in the database
    *
    * @param n queries size
    * @param data query std::vectors
    * @param k top k nearest neighbors
    * @param distances top k nearest distances
    * @param labels neighbors of the queries
    */
    virtual bool search(idx_t n, const float *data, idx_t k, float *distances, long *labels) const;

X
xj.lin 已提交
64 65
    //virtual bool search(idx_t n, const std::vector<float> &data, idx_t k,
    //                    std::vector<float> &distances, std::vector<float> &labels) const;
X
xj.lin 已提交
66

X
xj.lin 已提交
67 68 69
    //virtual bool remove_ids(const faiss::IDSelector &sel, long &nremove, long &location);
    //virtual bool remove_ids_range(const faiss::IDSelector &sel, long &nremove);
    //virtual bool index_display();
X
xj.lin 已提交
70

X
Xu Peng 已提交
71
    virtual std::shared_ptr<faiss::Index> data() { return index_; }
X
xj.lin 已提交
72

X
Xu Peng 已提交
73
    virtual const std::shared_ptr<faiss::Index>& data() const { return index_; }
X
xj.lin 已提交
74 75

private:
X
Xu Peng 已提交
76
    friend void write_index(const Index_ptr &index, const std::string &file_name);
X
xj.lin 已提交
77 78 79 80
    std::shared_ptr<faiss::Index> index_ = nullptr;
};


X
Xu Peng 已提交
81
void write_index(const Index_ptr &index, const std::string &file_name);
X
xj.lin 已提交
82 83

extern Index_ptr read_index(const std::string &file_name);
X
xj.lin 已提交
84
#endif
X
xj.lin 已提交
85 86 87 88 89


}
}
}