From be90a063b427ef9f278d251dce1c4f6a61c704c8 Mon Sep 17 00:00:00 2001 From: Doondi-Ashlesh Date: Tue, 21 Apr 2026 03:10:21 +0000 Subject: [PATCH 1/2] fix(redis): wrap IndexDefinition prefix in a list redis-py's IndexDefinition expects prefix to be a list or tuple. Passing a bare string causes it to iterate character-by-character, producing a malformed FT.CREATE PREFIX command that fails at runtime. Wrap the prefix string in a list so the correct prefix is passed. Fixes #13894 Signed-off-by: Doondi-Ashlesh --- python/semantic_kernel/connectors/redis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/semantic_kernel/connectors/redis.py b/python/semantic_kernel/connectors/redis.py index 575624895aca..902337d1dacd 100644 --- a/python/semantic_kernel/connectors/redis.py +++ b/python/semantic_kernel/connectors/redis.py @@ -278,7 +278,7 @@ async def ensure_collection_exists(self, **kwargs) -> None: raise VectorStoreOperationException("Invalid index type supplied.") fields = _definition_to_redis_fields(self.definition, self.collection_type) index_definition = IndexDefinition( - prefix=f"{self.collection_name}:", index_type=INDEX_TYPE_MAP[self.collection_type] + prefix=[f"{self.collection_name}:"], index_type=INDEX_TYPE_MAP[self.collection_type] ) await self.redis_database.ft(self.collection_name).create_index(fields, definition=index_definition, **kwargs) From cc1d3fc3c3f005d5244169fe186ff1377f1cbeb7 Mon Sep 17 00:00:00 2001 From: Doondi-Ashlesh Date: Tue, 21 Apr 2026 03:36:04 +0000 Subject: [PATCH 2/2] test(python/redis): assert IndexDefinition prefix is a list in test_create_index The existing test_create_index called ensure_collection_exists() but never inspected the IndexDefinition passed to create_index, so it passed even when prefix was a bare string (the original bug). - Parametrize test_create_index over hashset and json collection types. - Assert that the IndexDefinition passed to create_index has args matching a reference built with a list prefix. A bare string prefix produces PREFIX ... while a list produces PREFIX 1 , so the args comparison catches the regression exactly. - Fix test_create_index_manual which also used a bare string prefix="test:". Changed to prefix=["test:"] to match correct usage. Signed-off-by: Doondi-Ashlesh --- .../connectors/memory/test_redis_store.py | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/python/tests/unit/connectors/memory/test_redis_store.py b/python/tests/unit/connectors/memory/test_redis_store.py index e779ad945a97..ccc7b41d93f8 100644 --- a/python/tests/unit/connectors/memory/test_redis_store.py +++ b/python/tests/unit/connectors/memory/test_redis_store.py @@ -291,15 +291,30 @@ async def test_ensure_collection_deleted(collection_hash, mock_ensure_collection await collection_hash.ensure_collection_deleted() -async def test_create_index(collection_hash, mock_ensure_collection_exists): - await collection_hash.ensure_collection_exists() +@mark.parametrize("type_", ["hashset", "json"]) +async def test_create_index(collection_hash, collection_json, mock_ensure_collection_exists, type_): + from redis.commands.search.index_definition import IndexDefinition, IndexType + + collection = collection_hash if type_ == "hashset" else collection_json + expected_index_type = IndexType.HASH if type_ == "hashset" else IndexType.JSON + + await collection.ensure_collection_exists() + + mock_ensure_collection_exists.assert_called_once() + index_def = mock_ensure_collection_exists.call_args.kwargs["definition"] + assert isinstance(index_def, IndexDefinition) + # IndexDefinition._append_prefix iterates its argument. A bare string like "test:" + # produces PREFIX 5 t e s t : instead of PREFIX 1 test:. Comparing args against a + # reference built with a list catches this regression. + expected_def = IndexDefinition(prefix=[f"{collection.collection_name}:"], index_type=expected_index_type) + assert index_def.args == expected_def.args async def test_create_index_manual(collection_hash, mock_ensure_collection_exists): from redis.commands.search.index_definition import IndexDefinition, IndexType fields = ["fields"] - index_definition = IndexDefinition(prefix="test:", index_type=IndexType.HASH) + index_definition = IndexDefinition(prefix=["test:"], index_type=IndexType.HASH) await collection_hash.ensure_collection_exists(index_definition=index_definition, fields=fields)