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 Format of collection quries |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include <vector> |
24 | #include <aitheta2/index_params.h> |
25 | #include "common/types.h" |
26 | #include "constants.h" |
27 | |
28 | namespace proxima { |
29 | namespace be { |
30 | namespace index { |
31 | |
32 | struct QueryResult; |
33 | using QueryResultList = std::vector<QueryResult>; |
34 | using QueryResultListConstIter = std::vector<QueryResult>::const_iterator; |
35 | |
36 | /* |
37 | * QueryParams represents knn query params. |
38 | */ |
39 | struct QueryParams { |
40 | uint32_t topk{0U}; |
41 | DataTypes data_type{DataTypes::UNDEFINED}; |
42 | uint32_t dimension{0U}; |
43 | float radius{0.0f}; |
44 | uint64_t query_id{0U}; |
45 | bool is_linear{false}; |
46 | aitheta2::IndexParams {}; |
47 | }; |
48 | |
49 | /* |
50 | * QueryResult describes the format of knn query response |
51 | */ |
52 | struct QueryResult { |
53 | uint64_t primary_key{0U}; |
54 | float score{0.0f}; |
55 | uint64_t revision{0U}; |
56 | std::string forward_data{}; |
57 | uint64_t lsn{0U}; |
58 | bool reverse_sort{false}; |
59 | |
60 | QueryResult() { |
61 | primary_key = INVALID_KEY; |
62 | } |
63 | |
64 | bool operator<(const QueryResult &other) const { |
65 | if (reverse_sort) { |
66 | return score > other.score; |
67 | } else { |
68 | return score < other.score; |
69 | } |
70 | } |
71 | }; |
72 | |
73 | } // end namespace index |
74 | } // namespace be |
75 | } // end namespace proxima |
76 | |