1/**
2 * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * \author guonix
17 * \date Nov 2020
18 * \brief
19 */
20
21#include "knn_task.h"
22#include "common/error_code.h"
23
24namespace proxima {
25namespace be {
26namespace query {
27
28KNNTask::KNNTask(index::SegmentPtr segment, KNNQueryContext *context)
29 : BthreadTask("KNNTask"), segment_(std::move(segment)), context_(context) {}
30
31KNNTask::KNNTask(const std::string &name_val, index::SegmentPtr segment,
32 KNNQueryContext *context)
33 : BthreadTask(name_val), segment_(std::move(segment)), context_(context) {}
34
35KNNTask::~KNNTask() = default;
36
37const std::vector<index::QueryResultList> &KNNTask::result() const {
38 return result_;
39}
40
41int KNNTask::do_run() {
42 if (!segment_ || !context_) {
43 return PROXIMA_BE_ERROR_CODE(InvalidSegment);
44 }
45
46 LOG_DEBUG("KNNTask start to run, query_id[%zu], segment_id[%zu]",
47 (size_t)context_->query_params().query_id,
48 (size_t)segment_->segment_id());
49 return segment_->knn_search(context_->column(), context_->features(),
50 context_->query_params(), context_->batch_count(),
51 &result_);
52}
53
54} // namespace query
55} // namespace be
56} // namespace proxima
57