Class: Couchbase::VectorQuery
- Inherits:
-
Object
- Object
- Couchbase::VectorQuery
- Defined in:
- lib/couchbase/search_options.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(vector_field_name, vector_query) {|self| ... } ⇒ VectorQuery
constructor
Constructs a
VectorQuery
instance. - #to_h ⇒ Object private
- #to_json(*args) ⇒ Object private
Constructor Details
#initialize(vector_field_name, vector_query) ⇒ VectorQuery #initialize(vector_field_name, base64_vector_query) ⇒ VectorQuery
Constructs a VectorQuery
instance
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 |
# File 'lib/couchbase/search_options.rb', line 1087 def initialize(vector_field_name, vector_query) @vector_field_name = vector_field_name if vector_query.respond_to?(:to_str) @base64_vector_query = vector_query.to_str else @vector_query = vector_query end yield self if block_given? end |
Instance Attribute Details
#boost ⇒ Float?
1074 1075 1076 |
# File 'lib/couchbase/search_options.rb', line 1074 def boost @boost end |
#num_candidates ⇒ Integer?
1071 1072 1073 |
# File 'lib/couchbase/search_options.rb', line 1071 def num_candidates @num_candidates end |
Instance Method Details
#to_h ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 |
# File 'lib/couchbase/search_options.rb', line 1100 def to_h if !num_candidates.nil? && num_candidates < 1 raise Error::InvalidArgument, "Number of candidates must be at least 1, #{num_candidates} given" end h = { field: @vector_field_name, vector: @vector_query, vector_base64: @base64_vector_query, k: num_candidates || 3, boost: boost, }.compact raise Error::InvalidArgument, "The vector cannot be nil" if !h.include?(:vector) && !h.include?(:vector_base64) raise Error::InvalidArgument, "The vector query cannot be an empty array" if h.include?(:vector) && h[:vector].empty? if h.include?(:vector_base64) && h[:vector_base64].empty? raise Error::InvalidArgument, "The base64-encoded vector query cannot be empty" end h end |
#to_json(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1126 1127 1128 |
# File 'lib/couchbase/search_options.rb', line 1126 def to_json(*args) to_h.to_json(*args) end |