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__ when kwargs contain sortable=True or no_index=True. Vector fields are inherently always indexed and never sortable in RediSearch — these flags have no meaning for vectors and the constructor rejects them rather than silently dropping them. Note: raises DataError.
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 da03cdc7e8)
Solutions
- Drop sortable and no_index from VectorField construction — vectors are always indexed and non-sortable.
- Filter kwargs before passing: kwargs.pop('sortable', None); kwargs.pop('no_index', None).
- Build vector fields separately from text/numeric fields to avoid shared flag templates.
Example fix
// before
VectorField('vec', 'FLAT', {'TYPE': 'FLOAT32', 'DIM': 128, 'DISTANCE_METRIC': 'L2'}, sortable=True)
// after
VectorField('vec', 'FLAT', {'TYPE': 'FLOAT32', 'DIM': 128, 'DISTANCE_METRIC': 'L2'}) Defensive patterns
Strategy: validation
Validate before calling
def make_vector_field(name, algorithm, attributes, **kw):
kw.pop("sortable", None)
kw.pop("no_index", None)
if kw:
raise ValueError(f"Unexpected vector kwargs: {list(kw)}")
from redis.commands.search.field import VectorField
return VectorField(name, algorithm, attributes) Type guard
def vector_kwargs_are_clean(kw) -> bool:
return "sortable" not in kw and "no_index" not in kw Try / catch
from redis import DataError
try:
VectorField("vec", "FLAT", attrs, sortable=True)
except DataError as e:
if "Cannot set 'sortable' or 'no_index'" in str(e):
VectorField("vec", "FLAT", attrs)
else:
raise Prevention
- Never template vector fields with the same kwargs dict as text/numeric fields.
- Strip sortable/no_index before constructing VectorField if your schema builder is generic.
- Add a schema-builder unit test that includes a vector field.
When it happens
Trigger: Construct VectorField(name, algorithm='FLAT', attributes={...}, sortable=True) or VectorField(..., no_index=True) — passing either flag through **kwargs.
Common situations: Applying a uniform 'all fields sortable' policy when building a schema that includes vectors; copy-pasting a TextField definition into a vector context with sortable=True left in.
Related errors
- Realtime vector indexing supporting 3 Indexing Methods:'FLAT
- Non-Sortable non-Indexable fields are ignored
- CLIENT KILL type must be one of {client_types!r}
- CLIENT KILL skipme must be a bool
- CLIENT KILL <filter> <value> ... ... <filter> <value> must s
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/3e5efbf8f2f26ec2.json.
Report an issue: GitHub.