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]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fix is not covered by any test. test_create_index in test_redis_store.py:294 mocks create_index and never inspects the IndexDefinition argument. Please add a test that asserts create_index was called with a definition whose prefix is a list (e.g., via mock.call_args). Without this, the bug could regress silently.

)
await self.redis_database.ft(self.collection_name).create_index(fields, definition=index_definition, **kwargs)

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


Expand Down
Loading