{"id":"3e5efbf8f2f26ec2","repo":"redis/redis-py","slug":"cannot-set-sortable-or-no-index-in-vector-fiel","errorCode":null,"errorMessage":"Cannot set 'sortable' or 'no_index' in Vector fields.","messagePattern":"Cannot set 'sortable' or 'no_index' in Vector fields\\.","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/search/field.py","lineNumber":195,"sourceCode":"    def __init__(self, name: str, algorithm: str, attributes: dict, **kwargs):\n        \"\"\"\n        Create Vector Field. Notice that Vector cannot have sortable or no_index tag,\n        although it's also a Field.\n\n        ``name`` is the name of the field.\n\n        ``algorithm`` can be \"FLAT\", \"HNSW\", or \"SVS-VAMANA\".\n\n        ``attributes`` each algorithm can have specific attributes. Some of them\n        are mandatory and some of them are optional. See\n        https://oss.redis.com/redisearch/master/Vectors/#specific_creation_attributes_per_algorithm\n        for more information.\n        \"\"\"\n        sort = kwargs.get(\"sortable\", False)\n        noindex = kwargs.get(\"no_index\", False)\n\n        if sort or noindex:\n            raise DataError(\"Cannot set 'sortable' or 'no_index' in Vector fields.\")\n\n        if algorithm.upper() not in [\"FLAT\", \"HNSW\", \"SVS-VAMANA\"]:\n            raise DataError(\n                \"Realtime vector indexing supporting 3 Indexing Methods:\"\n                \"'FLAT', 'HNSW', and 'SVS-VAMANA'.\"\n            )\n\n        attr_li = []\n\n        for key, value in attributes.items():\n            attr_li.extend([key, value])\n\n        Field.__init__(\n            self, name, args=[Field.VECTOR, algorithm, len(attr_li), *attr_li], **kwargs\n        )\n","sourceCodeStart":177,"sourceCodeEnd":211,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/search/field.py#L177-L211","documentation":"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.","triggerScenarios":"Construct VectorField(name, algorithm='FLAT', attributes={...}, sortable=True) or VectorField(..., no_index=True) — passing either flag through **kwargs.","commonSituations":"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.","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."],"exampleFix":"// before\nVectorField('vec', 'FLAT', {'TYPE': 'FLOAT32', 'DIM': 128, 'DISTANCE_METRIC': 'L2'}, sortable=True)\n// after\nVectorField('vec', 'FLAT', {'TYPE': 'FLOAT32', 'DIM': 128, 'DISTANCE_METRIC': 'L2'})","handlingStrategy":"validation","validationCode":"def make_vector_field(name, algorithm, attributes, **kw):\n    kw.pop(\"sortable\", None)\n    kw.pop(\"no_index\", None)\n    if kw:\n        raise ValueError(f\"Unexpected vector kwargs: {list(kw)}\")\n    from redis.commands.search.field import VectorField\n    return VectorField(name, algorithm, attributes)","typeGuard":"def vector_kwargs_are_clean(kw) -> bool:\n    return \"sortable\" not in kw and \"no_index\" not in kw","tryCatchPattern":"from redis import DataError\ntry:\n    VectorField(\"vec\", \"FLAT\", attrs, sortable=True)\nexcept DataError as e:\n    if \"Cannot set 'sortable' or 'no_index'\" in str(e):\n        VectorField(\"vec\", \"FLAT\", attrs)\n    else:\n        raise","preventionTips":["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."],"tags":["redis-search","vector","schema","validation","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}