SearchContext.h 1.7 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
#pragma once

G
groot 已提交
8
#include "IScheduleContext.h"
G
groot 已提交
9
#include "db/MetaTypes.h"
G
groot 已提交
10 11 12 13 14 15 16

#include <unordered_map>
#include <vector>
#include <memory>
#include <condition_variable>

namespace zilliz {
J
jinhai 已提交
17
namespace milvus {
G
groot 已提交
18 19 20 21
namespace engine {

using TableFileSchemaPtr = std::shared_ptr<meta::TableFileSchema>;

G
groot 已提交
22
class SearchContext : public IScheduleContext {
G
groot 已提交
23 24 25 26 27
public:
    SearchContext(uint64_t topk, uint64_t nq, const float* vectors);

    bool AddIndexFile(TableFileSchemaPtr& index_file);

G
groot 已提交
28 29 30
    uint64_t topk() const { return topk_; }
    uint64_t nq() const  { return nq_; }
    const float* vectors() const { return vectors_; }
G
groot 已提交
31 32 33 34

    using Id2IndexMap = std::unordered_map<size_t, TableFileSchemaPtr>;
    const Id2IndexMap& GetIndexMap() const { return map_index_files_; }

35 36
    using Id2DistanceMap = std::vector<std::pair<int64_t, double>>;
    using ResultSet = std::vector<Id2DistanceMap>;
G
groot 已提交
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
    const ResultSet& GetResult() const { return result_; }
    ResultSet& GetResult() { return result_; }

    void IndexSearchDone(size_t index_id);
    void WaitResult();

private:
    uint64_t topk_ = 0;
    uint64_t nq_ = 0;
    const float* vectors_ = nullptr;

    Id2IndexMap map_index_files_;
    ResultSet result_;

    std::mutex mtx_;
    std::condition_variable done_cond_;

    std::string identity_; //for debug
};

using SearchContextPtr = std::shared_ptr<SearchContext>;



}
}
}