{"record":{"id":"6d448d0fb3a93fa2","repo":"redis/redis-rb","slug":"vector-fields-cannot-be-sortable","errorCode":null,"errorMessage":"Vector fields cannot be sortable","messagePattern":"Vector fields cannot be sortable","errorType":"exception","errorClass":"Redis::CommandError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/modules/search/field.rb","lineNumber":253,"sourceCode":"        #     \"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        #\n        # @param [String, Symbol] key the attribute name (upcased internally)\n        # @param [Object] value the attribute value\n        # @return [Object] the stored value\n        def add_attribute(key, value)\n          # Normalize like #initialize does for the kwargs form, so block-DSL attributes\n          # (vector_field(...) { type \"float32\" }) reach FT.CREATE with the expected casing.","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/modules/search/field.rb#L235-L271","documentation":"The Query Engine cannot sort on VECTOR fields, so the client rejects the combination up front: VectorField raises Redis::CommandError (not ArgumentError) for sortable: true at field construction, before any server round trip (lib/redis/commands/modules/search/field.rb:253). The error class matters when rescuing: generic Redis error handling catches it, argument-validation handling does not.","triggerScenarios":"VectorField.new(\"emb\", \"FLAT\", attrs, sortable: true); a schema builder that merges default options (sortable: true for sort UIs) into every field; converting a TEXT field to VECTOR while keeping its old options.","commonSituations":"Shared option hashes applied to all fields in a loop; copy-pasted field definitions; sorting-feature defaults colliding with newly added embedding fields.","solutions":["Remove sortable from the vector field definition","Sort on a companion field (numeric timestamp, text title) instead of the embedding","When mass-applying options, exclude vector fields: strip :sortable unless the field is a VectorField"],"exampleFix":"// before\nVectorField.new(\"emb\", \"HNSW\", attrs, sortable: true)\n// after\nVectorField.new(\"emb\", \"HNSW\", attrs)\n# sort on a separate numeric_field instead","handlingStrategy":"validation","validationCode":"def build_field(name, type, opts)\n  opts = opts.except(:sortable, :no_index) if type == :vector\n  Field.build(name, type, opts)\nend","typeGuard":"field.is_a?(Redis::Commands::Search::Field::VectorField) ? opts.except(:sortable) : opts","tryCatchPattern":"begin\n  VectorField.new(name, algo, attrs, **opts)\nrescue Redis::CommandError => e\n  raise SchemaConfigError, \"vector field rejected: #{e.message}\"\nend","preventionTips":["Never apply blanket sortable defaults across a mixed schema","Strip :sortable and :no_index for vector fields in schema builders","Rescue Redis::CommandError, not ArgumentError, around field construction"],"tags":["redis-search","vector-field","sortable","commanderror","schema"],"backgroundTag":"invalid-option-combination","analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}