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) diff --git a/python/tests/unit/connectors/memory/test_redis_store.py b/python/tests/unit/connectors/memory/test_redis_store.py index e779ad945a97..2adb7e2aabdf 100644 --- a/python/tests/unit/connectors/memory/test_redis_store.py +++ b/python/tests/unit/connectors/memory/test_redis_store.py @@ -295,11 +295,22 @@ async def test_create_index(collection_hash, mock_ensure_collection_exists): await collection_hash.ensure_collection_exists() +async def test_create_index_prefix_is_list(collection_hash, mock_ensure_collection_exists): + """Verify prefix is passed as a list, not a string (#13894).""" + await collection_hash.ensure_collection_exists() + mock_ensure_collection_exists.assert_called_once() + definition = mock_ensure_collection_exists.call_args.kwargs.get("definition") + assert definition is not None + prefix_idx = definition.args.index("PREFIX") + assert definition.args[prefix_idx + 1] == 1 + assert definition.args[prefix_idx + 2] == f"{collection_hash.collection_name}:" + + 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)