Skip to content
Open
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
4 changes: 2 additions & 2 deletions python/semantic_kernel/connectors/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ def _lambda_parser(self, node: ast.AST) -> dict[str, Any] | str | int | float |
case ast.Constant():
value = node.value
if isinstance(value, str):
return value.replace("'", "''")
return value
if isinstance(value, bytes):
return value.decode("utf-8").replace("'", "''")
return value.decode("utf-8")
if isinstance(value, (int, float, bool)) or value is None:
return value
raise VectorStoreOperationException(f"Unsupported constant type: {type(value)}")
Expand Down
4 changes: 2 additions & 2 deletions python/semantic_kernel/connectors/weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ def _lambda_parser(self, node: ast.AST) -> "_Filters | FilterValues":
case ast.Constant():
value = node.value
if isinstance(value, str):
return value.replace("'", "''")
return value
if isinstance(value, bytes):
return value.decode("utf-8").replace("'", "''")
return value.decode("utf-8")
if isinstance(value, (int, float, bool)) or value is None:
return value
raise VectorStoreOperationException(f"Unsupported constant type: {type(value)}")
Expand Down
6 changes: 6 additions & 0 deletions python/tests/unit/connectors/memory/test_chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ async def test_chroma_collection_search(chroma_collection, mock_client, include_
async for res in results.results:
assert res.record["id"] == "1"
assert res.score == 0.1


def test_chroma_collection_build_filter_keeps_apostrophes(chroma_collection):
"""Chroma filters are dicts, not SQL, so the value must reach Chroma unchanged."""
assert chroma_collection._build_filter('lambda x: x.content == "O\'Brien"') == {"content": "O'Brien"}
assert chroma_collection._build_filter('lambda x: x.content != "O\'Brien"') == {"content": {"$ne": "O'Brien"}}
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,19 @@ async def test_weaviate_collection_deserialize_data(
await collection.get(key=data.id)

mock_inner_get.assert_called_once_with([data.id], include_vectors=False, options=None)


def test_weaviate_collection_build_filter_keeps_apostrophes(clear_weaviate_env, record_type, definition) -> None:
"""Weaviate filters are objects, not query strings, so the value must be passed through unchanged."""
collection = WeaviateCollection(
record_type=record_type,
definition=definition,
collection_name="TestCollection",
async_client=AsyncMock(spec=WeaviateAsyncClient),
env_file_path="fake_env_file_path.env",
)

result = collection._build_filter('lambda x: x.content == "O\'Brien"')

assert result.target == "content"
assert result.value == "O'Brien"
Loading