Class: Redis::Commands::Search::VectorField
- Defined in:
- lib/redis/commands/modules/search/field.rb
Overview
A VECTOR field, indexing embeddings for approximate/exact nearest-neighbor search.
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Attributes inherited from Field
#alias_name, #name, #options, #query, #type
Instance Method Summary collapse
-
#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.
-
#initialize(name, algorithm, attributes = {}, **options) ⇒ VectorField
constructor
Build a
VECTORfield. -
#to_args ⇒ Array
Render this field as the array of
FT.CREATESCHEMAtokens.
Constructor Details
#initialize(name, algorithm, attributes = {}, **options) ⇒ VectorField
Build a VECTOR field.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# 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 ⇒ Object (readonly)
Returns the value of attribute algorithm.
229 230 231 |
# File 'lib/redis/commands/modules/search/field.rb', line 229 def algorithm @algorithm end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
229 230 231 |
# File 'lib/redis/commands/modules/search/field.rb', line 229 def attributes @attributes end |
Instance Method Details
#add_attribute(key, value) ⇒ Object
Set or override a single vector attribute.
269 270 271 272 273 |
# 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
288 289 290 |
# File 'lib/redis/commands/modules/search/field.rb', line 288 def args field_args end |
#to_args ⇒ Array
Render this field as the array of FT.CREATE SCHEMA tokens.
278 279 280 281 282 283 |
# 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 |