Couchbase C++ SDK 1.2.0 (rev. c2439a4)
Loading...
Searching...
No Matches
vector_query.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2023-Present Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
21
22#include <memory>
23#include <optional>
24#include <string>
25
26namespace couchbase
27{
33{
34public:
44 vector_query(std::string vector_field_name, std::vector<double> vector_query)
45 : vector_field_name_{ std::move(vector_field_name) }
46 , vector_query_{ std::move(vector_query) }
47 {
48 if (vector_query_.value().empty()) {
49 throw std::invalid_argument("the vector_query cannot be empty");
50 }
51 }
52
63 vector_query(std::string vector_field_name, std::string base64_vector_query)
64 : vector_field_name_{ std::move(vector_field_name) }
65 , base64_vector_query_{ std::move(base64_vector_query) }
66 {
67 if (base64_vector_query_.value().empty()) {
68 throw std::invalid_argument("the base64_vector_query cannot be empty");
69 }
70 }
71
83 {
84 if (num_candidates < 1) {
85 throw std::invalid_argument("The num_candidates cannot be less than 1");
86 }
87 num_candidates_ = num_candidates;
88 return *this;
89 }
90
102 auto boost(double boost) -> vector_query&
103 {
104 boost_ = boost;
105 return *this;
106 }
107
119 template<typename SearchQuery>
120 auto prefilter(SearchQuery prefilter) -> vector_query&
121 {
122 prefilter_ = std::make_shared<SearchQuery>(std::move(prefilter));
123 return *this;
124 }
125
132 [[nodiscard]] auto encode() const -> encoded_search_query;
133
134private:
135 std::string vector_field_name_;
136 std::uint32_t num_candidates_{ 3 };
137 std::optional<std::vector<double>> vector_query_{};
138 std::optional<std::string> base64_vector_query_{};
139 std::optional<double> boost_{};
140 std::shared_ptr<search_query> prefilter_{};
141};
142} // namespace couchbase
vector_query(std::string vector_field_name, std::string base64_vector_query)
Creates a vector query.
Definition vector_query.hxx:63
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:82
vector_query(std::string vector_field_name, std::vector< double > vector_query)
Creates a vector query.
Definition vector_query.hxx:44
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:102
auto prefilter(SearchQuery prefilter) -> vector_query &
Sets a prefilter, which allows defining a subset of the vector index, over which the vector search wi...
Definition vector_query.hxx:120
Represents a single item from the result of scan()
Definition allow_querying_search_index_options.hxx:28