Class: Couchbase::VectorQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/search_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vector_field_name, vector_query) {|self| ... } ⇒ VectorQuery

Constructs a VectorQuery instance

Parameters:

  • vector_field_name (String)

    the document field that contains the vector.

  • vector_query (Array<Float>)

    the vector query to run.

Yield Parameters:

  • self (MatchPhraseQuery)


1075
1076
1077
1078
1079
1080
# File 'lib/couchbase/search_options.rb', line 1075

def initialize(vector_field_name, vector_query)
  @vector_field_name = vector_field_name
  @vector_query = vector_query

  yield self if block_given?
end

Instance Attribute Details

#boostFloat?

Returns:

  • (Float, nil)


1067
1068
1069
# File 'lib/couchbase/search_options.rb', line 1067

def boost
  @boost
end

#num_candidatesInteger?

Returns:

  • (Integer, nil)


1064
1065
1066
# File 'lib/couchbase/search_options.rb', line 1064

def num_candidates
  @num_candidates
end

Instance Method Details

#to_hObject

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.



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
# File 'lib/couchbase/search_options.rb', line 1083

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

  {
    field: @vector_field_name,
    vector: @vector_query,
    k: num_candidates || 3,
    boost: boost,
  }.compact
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.



1098
1099
1100
# File 'lib/couchbase/search_options.rb', line 1098

def to_json(*args)
  to_h.to_json(*args)
end