From 518219a36834d78bd7790d644b0bc2b2314745ce Mon Sep 17 00:00:00 2001 From: Justin Cechmanek Date: Tue, 29 Oct 2024 12:54:56 -0700 Subject: [PATCH 1/2] manually parse special attributes that have no associated value --- redisvl/redis/connection.py | 20 +++++++++++++++++++- tests/integration/test_search_index.py | 12 ++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/redisvl/redis/connection.py b/redisvl/redis/connection.py index 560004c0..cfec50ab 100644 --- a/redisvl/redis/connection.py +++ b/redisvl/redis/connection.py @@ -98,7 +98,25 @@ 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', 'UNF', 'NOSTEM' don't have corresponding values. + # Their presence indicates boolean True + original = attrs.copy() + parsed_attrs = {} + if "NOSTEM" in attrs: + parsed_attrs["no_stem"] = True + attrs.remove("NOSTEM") + for special_attr in ["SORTABLE", "UNF"]: + if special_attr in attrs: + parsed_attrs[special_attr.lower()] = True + attrs.remove(special_attr) + + 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..ff0f2681 100644 --- a/tests/integration/test_search_index.py +++ b/tests/integration/test_search_index.py @@ -6,7 +6,15 @@ 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}, + }, +] @pytest.fixture @@ -87,7 +95,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", From 363ef39d4266963ff8460c0698c36275b0c070fb Mon Sep 17 00:00:00 2001 From: Justin Cechmanek Date: Tue, 29 Oct 2024 16:50:07 -0700 Subject: [PATCH 2/2] adds CASESENSITIVE to manually processed index attributes --- redisvl/redis/connection.py | 15 ++++++++++----- tests/integration/test_search_index.py | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/redisvl/redis/connection.py b/redisvl/redis/connection.py index cfec50ab..6cf6cd4f 100644 --- a/redisvl/redis/connection.py +++ b/redisvl/redis/connection.py @@ -98,17 +98,22 @@ def parse_vector_attrs(attrs): return vector_attrs def parse_attrs(attrs): - # 'SORTABLE', 'UNF', 'NOSTEM' don't have corresponding values. + # '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") - for special_attr in ["SORTABLE", "UNF"]: - if special_attr in attrs: - parsed_attrs[special_attr.lower()] = True - attrs.remove(special_attr) + 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( diff --git a/tests/integration/test_search_index.py b/tests/integration/test_search_index.py index ff0f2681..4b5c9a01 100644 --- a/tests/integration/test_search_index.py +++ b/tests/integration/test_search_index.py @@ -14,6 +14,9 @@ "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}}, ]