redis/redis-rb · error · Redis::CommandError
Vector fields cannot be sortable
Error message
Vector fields cannot be sortable
What it means
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.
Source
Thrown at lib/redis/commands/modules/search/field.rb:253
# "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.
#
# @param [String, Symbol] key the attribute name (upcased internally)
# @param [Object] value the attribute value
# @return [Object] the stored value
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.View on GitHub (pinned to 2ba9010b91)
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
Example fix
// before
VectorField.new("emb", "HNSW", attrs, sortable: true)
// after
VectorField.new("emb", "HNSW", attrs)
# sort on a separate numeric_field instead Defensive patterns
Strategy: validation
Validate before calling
def build_field(name, type, opts) opts = opts.except(:sortable, :no_index) if type == :vector Field.build(name, type, opts) end
Type guard
field.is_a?(Redis::Commands::Search::Field::VectorField) ? opts.except(:sortable) : opts
Try / catch
begin
VectorField.new(name, algo, attrs, **opts)
rescue Redis::CommandError => e
raise SchemaConfigError, "vector field rejected: #{e.message}"
end Prevention
- 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
When it happens
Trigger: 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.
Common situations: Shared option hashes applied to all fields in a loop; copy-pasted field definitions; sorting-feature defaults colliding with newly added embedding fields.
Related errors
- Vector fields cannot have no_index option
- Realtime vector indexing supporting 3 Indexing Methods: 'FLA
- Invalid schema
- collect fields must be :all or a non-empty list
- Invalid phonetic matcher. Supported matchers are: #{valid_ma
AI-assisted analysis of redis/redis-rb@2ba9010b91 (2026-08-23).
Data as JSON: /api/errors/6d448d0fb3a93fa2.
Report an issue: GitHub.