SearchTask.h 2.4 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
2
//
3 4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
J
jinhai 已提交
5
//
6 7 8 9 10
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
J
jinhai 已提交
11

12 13
#pragma once

Z
Zhiru Zhu 已提交
14
#include <memory>
15
#include <string>
Z
Zhiru Zhu 已提交
16 17
#include <vector>

G
groot 已提交
18 19
#include "db/SnapshotVisitor.h"
#include "db/engine/ExecutionEngine.h"
W
wxyu 已提交
20
#include "scheduler/Definition.h"
S
starlord 已提交
21
#include "scheduler/job/SearchJob.h"
G
groot 已提交
22
#include "scheduler/task/Task.h"
23 24

namespace milvus {
W
wxyu 已提交
25
namespace scheduler {
26

G
groot 已提交
27
class SearchTask : public Task {
S
starlord 已提交
28
 public:
29 30 31
    explicit SearchTask(const server::ContextPtr& context, engine::snapshot::ScopedSnapshotT snapshot,
                        const engine::DBOptions& options, const query::QueryPtr& query_ptr,
                        engine::snapshot::ID_TYPE segment_id, TaskLabelPtr label);
W
wxyu 已提交
32

G
groot 已提交
33 34 35 36 37 38 39 40
    inline json
    Dump() const override {
        json ret{
            {"type", type_},
            {"segment_id", segment_id_},
        };
        return ret;
    }
41

G
groot 已提交
42 43 44 45 46
    Status
    OnLoad(LoadType type, uint8_t device_id) override;

    Status
    OnExecute() override;
47

48 49 50 51
    static void
    MergeTopkToResultSet(const engine::ResultIds& src_ids, const engine::ResultDistances& src_distances, size_t src_k,
                         size_t nq, size_t topk, bool ascending, engine::QueryResultPtr& result);

G
groot 已提交
52 53
    int64_t
    nq();
54

55 56 57 58 59 60
    milvus::json
    ExtraParam();

    std::string
    IndexType();

G
groot 已提交
61 62 63
 private:
    void
    CreateExecEngine();
64

S
starlord 已提交
65
 public:
Z
Zhiru Zhu 已提交
66
    const std::shared_ptr<server::Context> context_;
67
    engine::snapshot::ScopedSnapshotT snapshot_;
Z
Zhiru Zhu 已提交
68

G
groot 已提交
69 70 71
    const engine::DBOptions& options_;
    query::QueryPtr query_ptr_;
    engine::snapshot::ID_TYPE segment_id_;
72
    std::string index_type_;
G
groot 已提交
73

G
groot 已提交
74
    engine::ExecutionEnginePtr execution_engine_;
75 76 77 78

    // distance -- value 0 means two vectors equal, ascending reduce, L2/HAMMING/JACCARD/TONIMOTO ...
    // similarity -- infinity value means two vectors equal, descending reduce, IP
    bool ascending_reduce_ = true;
79 80
};

S
starlord 已提交
81 82
}  // namespace scheduler
}  // namespace milvus