Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/semantic_kernel/connectors/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Comment thread
daric93 marked this conversation as resolved.
)
await self.redis_database.ft(self.collection_name).create_index(fields, definition=index_definition, **kwargs)
Comment on lines 280 to 283
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is at least one other Redis connector in this repo that still constructs IndexDefinition(prefix=f"{collection_name}:") (e.g., python/semantic_kernel/connectors/memory_stores/redis/redis_memory_store.py:132). That code path will exhibit the same character-by-character PREFIX bug against redis-py. Consider updating that call to pass a list (and/or adding coverage) so the fix is consistent across Redis connectors.

Copilot uses AI. Check for mistakes.

Expand Down
13 changes: 12 additions & 1 deletion python/tests/unit/connectors/memory/test_redis_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Loading