redis/redis-py · error · DataError
Cannot set 'sortable' or 'no_index' in Vector fields.
Error message
Cannot set 'sortable' or 'no_index' in Vector fields.
What it means
Raised by VectorField.__init__() (redis/commands/search/field.py:195) as a DataError when kwargs include sortable or no_index. Vector fields cannot be made SORTABLE and are always indexed (NOINDEX is meaningless for vectors), so the client rejects these flags up front rather than letting the server reject the schema.
Solutions
- Do not pass sortable or no_index to VectorField.
- If a generic builder forwards kwargs, filter them out for vector fields: {k: v for k, v in kwargs.items() if k not in ('sortable', 'no_index')}.
- Vectors are implicitly indexed; there is no opt-out.
Example fix
# before
VectorField('embedding', 'FLAT', {'TYPE': 'FLOAT32', 'DIM': 128, 'DISTANCE_METRIC': 'L2'}, sortable=True)
# after
VectorField('embedding', 'FLAT', {'TYPE': 'FLOAT32', 'DIM': 128, 'DISTANCE_METRIC': 'L2'}) Defensive patterns
Strategy: validation
Validate before calling
def safe_vector_kwargs(kwargs):
bad = {'sortable', 'no_index'} & set(kwargs)
if bad:
raise ValueError(f'VectorField does not accept {bad}')
return {k: v for k, v in kwargs.items() if k not in bad} Type guard
def vector_kwargs_ok(kwargs) -> bool:
return not ({'sortable', 'no_index'} & set(kwargs)) Try / catch
from redis.exceptions import DataError
try:
VectorField(name, algo, attrs, **kwargs)
except DataError as e:
if 'Vector fields' in str(e):
kwargs.pop('sortable', None); kwargs.pop('no_index', None)
VectorField(name, algo, attrs, **kwargs)
else:
raise Prevention
- Never forward sortable/no_index into VectorField.
- Filter generic field-builder kwargs for vector fields.
- Vectors are always indexed - there is no opt-out.
When it happens
Trigger: Constructing VectorField('vec', 'FLAT', {...}, sortable=True) or VectorField('vec', 'HNSW', {...}, no_index=True). Passing these via **kwargs from a generic field-builder also triggers it.
Common situations: Reusing a generic field-construction helper that always forwards sortable/no_index, or assuming all field types support the same kwargs as TextField/NumericField.
Related errors
- Realtime vector indexing supporting 3 Indexing…
- Bad query
- Bad query type
- Cannot use FIELDNAME alias with no field
- EXPLAINCLI will not be implemented.
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/3e5efbf8f2f26ec2.
Report an issue: GitHub.
Appendix: source
Thrown at redis/commands/search/field.py:195
def __init__(self, name: str, algorithm: str, attributes: dict, **kwargs):
"""
Create Vector Field. Notice that Vector cannot have sortable or no_index tag,
although it's also a Field.
``name`` is the name of the field.
``algorithm`` can be "FLAT", "HNSW", or "SVS-VAMANA".
``attributes`` each algorithm can have specific attributes. Some of them
are mandatory and some of them are optional. See
https://oss.redis.com/redisearch/master/Vectors/#specific_creation_attributes_per_algorithm
for more information.
"""
sort = kwargs.get("sortable", False)
noindex = kwargs.get("no_index", False)
if sort or noindex:
raise DataError("Cannot set 'sortable' or 'no_index' in Vector fields.")
if algorithm.upper() not in ["FLAT", "HNSW", "SVS-VAMANA"]:
raise DataError(
"Realtime vector indexing supporting 3 Indexing Methods:"
"'FLAT', 'HNSW', and 'SVS-VAMANA'."
)
attr_li = []
for key, value in attributes.items():
attr_li.extend([key, value])
Field.__init__(
self, name, args=[Field.VECTOR, algorithm, len(attr_li), *attr_li], **kwargs
)
View on GitHub (pinned to 6a6b581b48)