redis/redis-rb · error · ArgumentError

Realtime vector indexing supporting 3 Indexing Methods: 'FLA

Error message

Realtime vector indexing supporting 3 Indexing Methods: 'FLAT', 'HNSW', and 'SVS-VAMANA'

What it means

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.

Source

Thrown at lib/redis/commands/modules/search/field.rb:247

        attr_reader :algorithm, :attributes

        # Build a +VECTOR+ field.
        #
        # @example
        #   Redis::Commands::Search::Field::VectorField.new(
        #     "embedding", "HNSW", { type: "FLOAT32", dim: 4, distance_metric: "L2" }
        #   )
        #
        # @param [String, Symbol] name the document attribute the field indexes
        # @param [String, Symbol] algorithm the indexing method, one of +FLAT+, +HNSW+, +SVS-VAMANA+
        # @param [Hash] attributes the vector attributes (e.g. +type+, +dim+, +distance_metric+)
        # @option options [String] :as an alias for the field, rendered as +AS <alias>+
        # @raise [ArgumentError] if +algorithm+ is not a supported indexing method
        # @raise [Redis::CommandError] if +:sortable+ or +:no_index+ is given
        def initialize(name, algorithm, attributes = {}, **options)
          # 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 options[:sortable]
            raise Redis::CommandError, "Vector fields cannot be sortable"
          end
          if options[:no_index]
            raise Redis::CommandError, "Vector fields cannot have no_index option"
          end

          super(name, :vector, **options)
          @algorithm = algorithm.to_s.upcase
          @attributes = attributes.transform_keys { |k| k.to_s.upcase }.transform_values { |v| v.to_s.upcase }
        end

        # Set or override a single vector attribute.
        #

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Pass FLAT, HNSW or SVS-VAMANA as the second positional argument (any case)
  2. Keep the attributes hash third: VectorField.new(name, algorithm, attributes, **options)
  3. Strip config-provided algorithm strings before comparing

Example fix

// before
VectorField.new("emb", { "TYPE" => "FLOAT32", "DIM" => 4 })
// after
VectorField.new("emb", "HNSW", { type: "FLOAT32", dim: 4, distance_metric: "L2" })
Defensive patterns

Strategy: validation

Validate before calling

VECTOR_ALGORITHMS = %w[FLAT HNSW SVS-VAMANA].freeze

algo = config.fetch("algorithm").to_s.upcase.strip
raise ArgumentError, "algorithm must be one of #{VECTOR_ALGORITHMS.join(", ")}" unless VECTOR_ALGORITHMS.include?(algo)
VectorField.new(name, algo, attrs)

Type guard

%w[FLAT HNSW SVS-VAMANA].include?(algorithm.to_s.upcase)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of redis/redis-rb@2ba9010b91 (2026-08-23). Data as JSON: /api/errors/c76c589a9eb27ade. Report an issue: GitHub.