{"record":{"id":"c76c589a9eb27ade","repo":"redis/redis-rb","slug":"realtime-vector-indexing-supporting-3-indexing-met","errorCode":null,"errorMessage":"Realtime vector indexing supporting 3 Indexing Methods: 'FLAT', 'HNSW', and 'SVS-VAMANA'","messagePattern":"Realtime vector indexing supporting 3 Indexing Methods: 'FLAT', 'HNSW', and 'SVS-VAMANA'","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/modules/search/field.rb","lineNumber":247,"sourceCode":"        attr_reader :algorithm, :attributes\n\n        # Build a +VECTOR+ field.\n        #\n        # @example\n        #   Redis::Commands::Search::Field::VectorField.new(\n        #     \"embedding\", \"HNSW\", { type: \"FLOAT32\", dim: 4, distance_metric: \"L2\" }\n        #   )\n        #\n        # @param [String, Symbol] name the document attribute the field indexes\n        # @param [String, Symbol] algorithm the indexing method, one of +FLAT+, +HNSW+, +SVS-VAMANA+\n        # @param [Hash] attributes the vector attributes (e.g. +type+, +dim+, +distance_metric+)\n        # @option options [String] :as an alias for the field, rendered as +AS <alias>+\n        # @raise [ArgumentError] if +algorithm+ is not a supported indexing method\n        # @raise [Redis::CommandError] if +:sortable+ or +:no_index+ is given\n        def initialize(name, algorithm, attributes = {}, **options)\n          # Validate algorithm\n          unless ['FLAT', 'HNSW', 'SVS-VAMANA'].include?(algorithm.to_s.upcase)\n            raise ArgumentError,\n                  \"Realtime vector indexing supporting 3 Indexing Methods: 'FLAT', 'HNSW', and 'SVS-VAMANA'\"\n          end\n\n          # Validate that sortable and no_index are not used with vector fields\n          if options[:sortable]\n            raise Redis::CommandError, \"Vector fields cannot be sortable\"\n          end\n          if options[:no_index]\n            raise Redis::CommandError, \"Vector fields cannot have no_index option\"\n          end\n\n          super(name, :vector, **options)\n          @algorithm = algorithm.to_s.upcase\n          @attributes = attributes.transform_keys { |k| k.to_s.upcase }.transform_values { |v| v.to_s.upcase }\n        end\n\n        # Set or override a single vector attribute.\n        #","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/modules/search/field.rb#L229-L265","documentation":"A VECTOR field must name one of the three supported indexing methods: FLAT (brute force), HNSW (graph), or SVS-VAMANA. VectorField upcases the argument before checking, so :hnsw and \"flat\" work, but anything else raises ArgumentError at construction with the server wording of the message (lib/redis/commands/modules/search/field.rb:247). The check happens before FT.CREATE is ever sent, so nothing reaches the server.","triggerScenarios":"VectorField.new(\"emb\", \"IVF\", attrs); VectorField.new(\"emb\", \"hnswpq\", attrs); misordered arguments that put the attributes hash in the algorithm slot: VectorField.new(\"emb\", { type: \"FLOAT32\", dim: 4 }), because Hash#to_s.upcase matches nothing.","commonSituations":"Habits from other vector databases (IVF, ANNOY, DiskANN); argument-order mixups because algorithm and attributes are both positional; whitespace or trailing characters in config-provided algorithm strings.","solutions":["Pass FLAT, HNSW or SVS-VAMANA as the second positional argument (any case)","Keep the attributes hash third: VectorField.new(name, algorithm, attributes, **options)","Strip config-provided algorithm strings before comparing"],"exampleFix":"// before\nVectorField.new(\"emb\", { \"TYPE\" => \"FLOAT32\", \"DIM\" => 4 })\n// after\nVectorField.new(\"emb\", \"HNSW\", { type: \"FLOAT32\", dim: 4, distance_metric: \"L2\" })","handlingStrategy":"validation","validationCode":"VECTOR_ALGORITHMS = %w[FLAT HNSW SVS-VAMANA].freeze\n\nalgo = config.fetch(\"algorithm\").to_s.upcase.strip\nraise ArgumentError, \"algorithm must be one of #{VECTOR_ALGORITHMS.join(\", \")}\" unless VECTOR_ALGORITHMS.include?(algo)\nVectorField.new(name, algo, attrs)","typeGuard":"%w[FLAT HNSW SVS-VAMANA].include?(algorithm.to_s.upcase)","tryCatchPattern":null,"preventionTips":["Validate the algorithm name from config before building the schema","Remember only FLAT, HNSW and SVS-VAMANA exist in the Query Engine","Use wrappers that keep algorithm and attributes from being swapped positionally"],"tags":["redis-search","vector-field","ft-create","argumenterror","embeddings"],"backgroundTag":"unsupported-algorithm","analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}