Class: Redis::Commands::Search::HybridVsimQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/commands/modules/search/hybrid.rb

Overview

The vector-similarity VSIM leg of an FT.HYBRID query.

Chainable setters (+vsim_method_params+, filter, yield_score_as) return self; #args renders the leg into its argument tokens, beginning with "VSIM".

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vector_field_name:, vector_data:, vsim_search_method: nil, vsim_search_method_params: nil, filter: nil, yield_score_as: nil) ⇒ HybridVsimQuery

Returns a new instance of HybridVsimQuery.

Parameters:

  • vector_field_name (String)

    the vector field to search

  • vector_data (String)

    the query vector blob

  • vsim_search_method (Symbol, String, nil) (defaults to: nil)

    the search method, e.g. :knn or :range

  • vsim_search_method_params (Hash, nil) (defaults to: nil)

    the search-method parameters

  • filter (HybridFilter, nil) (defaults to: nil)

    an optional filter applied to the vector leg

  • yield_score_as (String, nil) (defaults to: nil)

    the alias to expose the vector score under



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/redis/commands/modules/search/hybrid.rb', line 65

def initialize(
  vector_field_name:, vector_data:,
  vsim_search_method: nil, vsim_search_method_params: nil,
  filter: nil, yield_score_as: nil
)
  @vector_field = vector_field_name
  @vector_data = vector_data
  @vsim_method_params = nil
  @filter = filter
  @yield_score_as = yield_score_as

  if vsim_search_method && vsim_search_method_params
    vsim_method_params(vsim_search_method, **vsim_search_method_params)
  end
end

Instance Attribute Details

#vector_dataString (readonly)

Returns:

  • (String)

    the vector field name

  • (String)

    the query vector data (blob)



57
58
59
# File 'lib/redis/commands/modules/search/hybrid.rb', line 57

def vector_data
  @vector_data
end

#vector_fieldString (readonly)

Returns:

  • (String)

    the vector field name

  • (String)

    the query vector data (blob)



57
58
59
# File 'lib/redis/commands/modules/search/hybrid.rb', line 57

def vector_field
  @vector_field
end

Instance Method Details

#argsArray

Returns the VSIM leg argument tokens, beginning with "VSIM".

Returns:

  • (Array)

    the VSIM leg argument tokens, beginning with "VSIM"



116
117
118
119
120
121
122
# File 'lib/redis/commands/modules/search/hybrid.rb', line 116

def args
  result = ["VSIM", @vector_field, @vector_data]
  result.concat(@vsim_method_params) if @vsim_method_params
  result.concat(@filter.args) if @filter
  result << "YIELD_SCORE_AS" << @yield_score_as if @yield_score_as
  result
end

#filter(flt) ⇒ self

Set a filter applied to the vector leg (+FILTER+).

Parameters:

Returns:

  • (self)


101
102
103
104
# File 'lib/redis/commands/modules/search/hybrid.rb', line 101

def filter(flt)
  @filter = flt
  self
end

#vsim_method_params(method, **kwargs) ⇒ self

Set the vector search method and its parameters (e.g. KNN / RANGE).

Parameters:

  • method (Symbol, String)

    the search method (upcased into a token)

  • kwargs (Hash)

    the method parameters, emitted as upcased key/value pairs

Returns:

  • (self)


86
87
88
89
90
91
92
93
94
95
# File 'lib/redis/commands/modules/search/hybrid.rb', line 86

def vsim_method_params(method, **kwargs)
  @vsim_method_params = [method.to_s.upcase]
  if kwargs.any?
    @vsim_method_params << kwargs.size * 2
    kwargs.each do |key, value|
      @vsim_method_params << key.to_s.upcase << value
    end
  end
  self
end

#yield_score_as(alias_name) ⇒ self

Expose the vector score under an alias (+YIELD_SCORE_AS+).

Parameters:

  • alias_name (String)

    the alias for the score

Returns:

  • (self)


110
111
112
113
# File 'lib/redis/commands/modules/search/hybrid.rb', line 110

def yield_score_as(alias_name)
  @yield_score_as = alias_name
  self
end