123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Inherits: Object
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".

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(vector_field_name:, vector_data:, vsim_search_method: nil, vsim_search_method_params: nil, filter: nil, yield_score_as: nil) ⇒ HybridVsimQuery

Parameters:

  • vector_field_name (String)

    the vector field to search

  • vector_data (String)

    the query vector blob

  • vsim_search_method (Symbol, String, nil)

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

  • vsim_search_method_params (Hash, nil)

    the search-method parameters

  • filter (HybridFilter, nil)

    an optional filter applied to the vector leg

  • yield_score_as (String, nil)

    the alias to expose the vector score under

[ GitHub ]

  
# 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)

[ GitHub ]

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

attr_reader :vector_field, :vector_data

#vector_fieldString (readonly)

Returns:

  • (String)

    the vector field name

  • (String)

    the query vector data (blob)

[ GitHub ]

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

attr_reader :vector_field, :vector_data

Instance Method Details

#argsArray

Returns:

  • (Array)

    the VSIM leg argument tokens, beginning with "VSIM"

[ GitHub ]

  
# 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:

[ GitHub ]

  
# 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

[ GitHub ]

  
# 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

[ GitHub ]

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

def yield_score_as(alias_name)
  @yield_score_as = alias_name
  self
end