diff --git a/redisvl/redis/connection.py b/redisvl/redis/connection.py index 560004c0..6cf6cd4f 100644 --- a/redisvl/redis/connection.py +++ b/redisvl/redis/connection.py @@ -98,7 +98,30 @@ def parse_vector_attrs(attrs): return vector_attrs def parse_attrs(attrs): - return {attrs[i].lower(): attrs[i + 1] for i in range(6, len(attrs), 2)} + # 'SORTABLE', 'NOSTEM' don't have corresponding values. + # Their presence indicates boolean True + # TODO 'WITHSUFFIXTRIE' is another boolean attr, but is not returned by ft.info + original = attrs.copy() + parsed_attrs = {} + if "NOSTEM" in attrs: + parsed_attrs["no_stem"] = True + attrs.remove("NOSTEM") + if "CASESENSITIVE" in attrs: + parsed_attrs["case_sensitive"] = True + attrs.remove("CASESENSITIVE") + if "SORTABLE" in attrs: + parsed_attrs["sortable"] = True + attrs.remove("SORTABLE") + if "UNF" in attrs: + attrs.remove("UNF") # UNF present on sortable numeric fields only + + try: + parsed_attrs.update( + {attrs[i].lower(): attrs[i + 1] for i in range(6, len(attrs), 2)} + ) + except IndexError as e: + raise IndexError(f"Error parsing index attributes {original}, {str(e)}") + return parsed_attrs schema_fields = [] diff --git a/tests/integration/test_search_index.py b/tests/integration/test_search_index.py index 574cec91..4b5c9a01 100644 --- a/tests/integration/test_search_index.py +++ b/tests/integration/test_search_index.py @@ -6,7 +6,18 @@ from redisvl.redis.utils import convert_bytes from redisvl.schema import IndexSchema, StorageType -fields = [{"name": "test", "type": "tag"}] +fields = [ + {"name": "test", "type": "tag"}, + {"name": "test_text", "type": "text"}, + { + "name": "test_text_attrs", + "type": "text", + "attrs": {"no_stem": True, "sortable": True}, + }, + {"name": "test_tag", "type": "tag", "attrs": {"case_sensitive": True}}, + {"name": "test_numeric", "type": "numeric"}, + {"name": "test_numeric_attrs", "type": "numeric", "attrs": {"sortable": True}}, +] @pytest.fixture @@ -87,7 +98,7 @@ def test_search_index_from_existing_complex(client): "name": "age", "type": "numeric", "path": "$.metadata.age", - "attrs": {"sortable": False}, + "attrs": {"sortable": True}, }, { "name": "user_embedding",