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]
)
await self.redis_database.ft(self.collection_name).create_index(fields, definition=index_definition, **kwargs)

Expand Down
32 changes: 31 additions & 1 deletion python/tests/unit/connectors/memory/test_redis_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,40 @@ async def test_create_index_manual(collection_hash, mock_ensure_collection_exist
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)


async def test_create_index_fail(collection_hash, mock_ensure_collection_exists):
with raises(VectorStoreOperationException, match="Invalid index type supplied."):
await collection_hash.ensure_collection_exists(index_definition="index_definition", fields="fields")


@mark.parametrize(
("fixture_name", "expected_index_type"),
[
("collection_hash", "hash"),
("collection_json", "json"),
Comment on lines +310 to +315

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.

Bug: IndexType("hash") and IndexType("json") will raise ValueError because IndexType is an Enum with integer values (HASH = 1, JSON = 2), not string values. The parametrize should use the actual IndexType enum members directly.

Suggested change
@mark.parametrize(
("fixture_name", "expected_index_type"),
[
("collection_hash", "hash"),
("collection_json", "json"),
@mark.parametrize(
("fixture_name", "expected_index_type"),
[
("collection_hash", IndexType.HASH),
("collection_json", IndexType.JSON),
],
)

],
)
async def test_create_index_uses_single_collection_prefix(
request,
fixture_name,
expected_index_type,
mock_ensure_collection_exists,
):
collection = request.getfixturevalue(fixture_name)
from redis.commands.search.index_definition import IndexType

with patch("semantic_kernel.connectors.redis.IndexDefinition") as mock_index_definition:
definition = object()
mock_index_definition.return_value = definition

await collection.ensure_collection_exists()

mock_index_definition.assert_called_once_with(
prefix=["test:"],
index_type=IndexType(expected_index_type),
)
mock_ensure_collection_exists.assert_awaited_once()
assert mock_ensure_collection_exists.await_args.kwargs["definition"] is definition
Loading