Class: Redis::Commands::Search::VectorField
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Field
|
|
|
Instance Chain:
self,
Field
|
|
| Inherits: |
Redis::Commands::Search::Field
|
| Defined in: | lib/redis/commands/modules/search/field.rb |
Overview
A VECTOR field, indexing embeddings for approximate/exact nearest-neighbor search.
Class Method Summary
-
.new(name, algorithm, attributes = {}, **options) ⇒ VectorField
constructor
Build a
VECTORfield.
Field - Inherited
| .new | Build a field definition. |
Instance Attribute Summary
- #algorithm readonly
- #attributes readonly
Field - Inherited
Instance Method Summary
-
#add_attribute(key, value) ⇒ Object
Set or override a single vector attribute.
-
#args ⇒ Array
Returns field-specific args (without name/alias) for compatibility with tests.
-
#to_args ⇒ Array
Render this field as the array of
FT.CREATESCHEMAtokens. - #field_args private
Field - Inherited
| #to_args | Render this field as the array of |
Constructor Details
.new(name, algorithm, attributes = {}, **options) ⇒ VectorField
Build a VECTOR field.
# File 'lib/redis/commands/modules/search/field.rb', line 244
def initialize(name, algorithm, attributes = {}, **) # Validate algorithm unless ['FLAT', 'HNSW', 'SVS-VAMANA'].include?(algorithm.to_s.upcase) raise ArgumentError, "Realtime vector indexing supporting 3 Indexing Methods: 'FLAT', 'HNSW', and 'SVS-VAMANA'" end # Validate that sortable and no_index are not used with vector fields if [:sortable] raise Redis::CommandError, "Vector fields cannot be sortable" end if [:no_index] raise Redis::CommandError, "Vector fields cannot have no_index option" end super(name, :vector, **) @algorithm = algorithm.to_s.upcase @attributes = attributes.transform_keys { |k| k.to_s.upcase }.transform_values { |v| v.to_s.upcase } end
Instance Attribute Details
#algorithm (readonly)
[ GitHub ]# File 'lib/redis/commands/modules/search/field.rb', line 229
attr_reader :algorithm, :attributes
#attributes (readonly)
[ GitHub ]# File 'lib/redis/commands/modules/search/field.rb', line 229
attr_reader :algorithm, :attributes
Instance Method Details
#add_attribute(key, value) ⇒ Object
Set or override a single vector attribute.
# File 'lib/redis/commands/modules/search/field.rb', line 269
def add_attribute(key, value) # Normalize like #initialize does for the kwargs form, so block-DSL attributes # (vector_field(...) { type "float32" }) reach FT.CREATE with the expected casing. @attributes[key.to_s.upcase] = value.to_s.upcase end
#args ⇒ Array
Returns field-specific args (without name/alias) for compatibility with tests
# File 'lib/redis/commands/modules/search/field.rb', line 288
def args field_args end
#field_args (private)
[ GitHub ]
#to_args ⇒ Array
Render this field as the array of FT.CREATE SCHEMA tokens.
# File 'lib/redis/commands/modules/search/field.rb', line 278
def to_args args = [name] args << "AS" << @alias_name if @alias_name args += field_args args end