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 Haichao.chc
17 * \date Oct 2020
18 * \brief VectorColumnReader provides search ability for column
19 * vector data
20 */
21
22#pragma once
23
24#include "common/macro_define.h"
25#include "common/types.h"
26#include "column_reader.h"
27#include "context_pool.h"
28#include "index_helper.h"
29#include "../typedef.h"
30
31namespace proxima {
32namespace be {
33namespace index {
34
35/*
36 * VectorColumnReader is an implementation of ColumnReader, mainly
37 * for persist column index.
38 */
39class VectorColumnReader : public ColumnReader {
40 public:
41 PROXIMA_DISALLOW_COPY_AND_ASSIGN(VectorColumnReader);
42
43 //! Constructor
44 VectorColumnReader(const std::string &coll_name, const std::string &coll_path,
45 SegmentID seg_id, const std::string &col_name) {
46 this->set_collection_name(coll_name);
47 this->set_collection_path(coll_path);
48 this->set_segment_id(seg_id);
49 this->set_column_name(col_name);
50 }
51
52 //! Destructor
53 ~VectorColumnReader();
54
55 public:
56 //! Open index
57 int open(const meta::ColumnMeta &column_meta,
58 const ReadOptions &read_options) override;
59
60 //! Close index
61 int close() override;
62
63 //! Search similar results with query
64 int search(const std::string &query, const QueryParams &query_params,
65 FilterFunction filter, IndexDocumentList *results) override;
66
67 //! Batch search similar results with query
68 int search(const std::string &query, const QueryParams &query_params,
69 uint32_t batch_count, FilterFunction filter,
70 std::vector<IndexDocumentList> *batch_result_list) override;
71
72 public:
73 //! Return index file path
74 std::string index_file_path() const override {
75 return index_file_path_;
76 }
77
78 //! Return document count
79 size_t doc_count() const override {
80 if (proxima_searcher_) {
81 return proxima_searcher_->stats().loaded_count();
82 } else {
83 return 0U;
84 }
85 }
86
87 private:
88 bool check_column_meta(const meta::ColumnMeta &column_meta);
89
90 int open_proxima_container(const ReadOptions &read_options);
91
92 int open_proxima_searcher();
93
94 private:
95 IndexContainerPtr container_{};
96 IndexParams proxima_params_{};
97 IndexSearcherPtr proxima_searcher_{};
98 IndexMeta proxima_meta_{};
99
100 ContextPool context_pool_{};
101 QuantizeTypes quantize_type_{QuantizeTypes::UNDEFINED};
102 IndexReformerPtr reformer_{};
103 IndexMeasurePtr measure_{};
104
105 std::string index_file_path_{};
106 bool opened_{false};
107};
108
109
110} // end namespace index
111} // namespace be
112} // end namespace proxima
113