Couchbase C++ SDK 1.0.2 (rev. 51f4775)
Loading...
Searching...
No Matches
vector_query.hxx
Go to the documentation of this file.
1#include <utility>
2
3/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
4/*
5 * Copyright 2023-Present Couchbase, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#pragma once
21
22namespace couchbase
23{
29{
30public:
40 vector_query(std::string vector_field_name, std::vector<double> vector_query)
41 : vector_field_name_{ std::move(vector_field_name) }
42 , vector_query_{ std::move(vector_query) }
43 {
44 if (vector_query_.value().empty()) {
45 throw std::invalid_argument("the vector_query cannot be empty");
46 }
47 }
48
59 vector_query(std::string vector_field_name, std::string base64_vector_query)
60 : vector_field_name_{ std::move(vector_field_name) }
61 , base64_vector_query_{ std::move(base64_vector_query) }
62 {
63 if (base64_vector_query_.value().empty()) {
64 throw std::invalid_argument("the base64_vector_query cannot be empty");
65 }
66 }
67
79 {
80 if (num_candidates < 1) {
81 throw std::invalid_argument("The num_candidates cannot be less than 1");
82 }
83 num_candidates_ = num_candidates;
84 return *this;
85 }
86
98 auto boost(double boost) -> vector_query&
99 {
100 boost_ = boost;
101 return *this;
102 }
103
110 [[nodiscard]] auto encode() const -> encoded_search_query;
111
112private:
113 std::string vector_field_name_;
114 std::uint32_t num_candidates_{ 3 };
115 std::optional<std::vector<double>> vector_query_{};
116 std::optional<std::string> base64_vector_query_{};
117 std::optional<double> boost_{};
118};
119} // namespace couchbase
Definition vector_query.hxx:29
vector_query(std::string vector_field_name, std::string base64_vector_query)
Creates a vector query.
Definition vector_query.hxx:59
auto encode() const -> encoded_search_query
auto num_candidates(std::uint32_t num_candidates) -> vector_query &
The number of results that will be returned from this vector query.
Definition vector_query.hxx:78
vector_query(std::string vector_field_name, std::vector< double > vector_query)
Creates a vector query.
Definition vector_query.hxx:40
auto boost(double boost) -> vector_query &
The boost parameter is used to increase the relative weight of a clause (with a boost greater than 1)...
Definition vector_query.hxx:98
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28