Skip to content

Commit 4fdd50c

Browse files
Python: Int test fix (#12298)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Integration test fixes for the vector stores ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent 9ce7462 commit 4fdd50c

File tree

4 files changed

+23
-151
lines changed

4 files changed

+23
-151
lines changed

python/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def dataclass_vector_data_model(
318318
@dataclass
319319
class MyDataModel:
320320
vector: Annotated[
321-
str | list[float] | None,
321+
list[float] | str | None,
322322
VectorStoreField(
323323
"vector",
324324
index_kind=index_kind,

python/tests/integration/memory/azure_cosmos_db/test_azure_cosmos_db_no_sql.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def test_list_collection_names(
3232
assert await store.list_collection_names() == []
3333

3434
collection_name = "list_collection_names"
35-
collection = store.get_collection(collection_name, record_type)
35+
collection = store.get_collection(collection_name=collection_name, record_type=record_type)
3636
await collection.create_collection()
3737

3838
collection_names = await store.list_collection_names()
@@ -43,9 +43,6 @@ async def test_list_collection_names(
4343
collection_names = await store.list_collection_names()
4444
assert collection_name not in collection_names
4545

46-
# Deleting the collection doesn't remove it from the vector_record_collections list in the store
47-
assert collection_name in store.vector_record_collections
48-
4946
async def test_collection_not_created(
5047
self,
5148
stores: dict[str, Callable[[], VectorStore]],
@@ -55,7 +52,7 @@ async def test_collection_not_created(
5552
"""Test get without collection."""
5653
async with stores["azure_cosmos_db_no_sql"]() as store:
5754
collection_name = "collection_not_created"
58-
collection = store.get_collection(collection_name, record_type)
55+
collection = store.get_collection(collection_name=collection_name, record_type=record_type)
5956

6057
assert await collection.does_collection_exist() is False
6158

@@ -85,8 +82,8 @@ async def test_custom_partition_key(
8582
async with stores["azure_cosmos_db_no_sql"]() as store:
8683
collection_name = "custom_partition_key"
8784
collection = store.get_collection(
88-
collection_name,
89-
record_type,
85+
collection_name=collection_name,
86+
record_type=record_type,
9087
partition_key=PartitionKey(path="/product_type"),
9188
)
9289

@@ -119,7 +116,7 @@ async def test_get_include_vector(
119116
"""Test get with include_vector."""
120117
async with stores["azure_cosmos_db_no_sql"]() as store:
121118
collection_name = "get_include_vector"
122-
collection = store.get_collection(collection_name, record_type)
119+
collection = store.get_collection(collection_name=collection_name, record_type=record_type)
123120

124121
# Upsert
125122
await collection.create_collection()
@@ -149,7 +146,7 @@ async def test_get_not_include_vector(
149146
"""Test get with include_vector."""
150147
async with stores["azure_cosmos_db_no_sql"]() as store:
151148
collection_name = "get_not_include_vector"
152-
collection = store.get_collection(collection_name, record_type)
149+
collection = store.get_collection(collection_name=collection_name, record_type=record_type)
153150

154151
# Upsert
155152
await collection.create_collection()
@@ -179,7 +176,9 @@ async def test_collection_with_key_as_key_field(
179176
"""Test collection with key as key field."""
180177
async with stores["azure_cosmos_db_no_sql"]() as store:
181178
collection_name = "collection_with_key_as_key_field"
182-
collection = store.get_collection(collection_name, record_type_with_key_as_key_field)
179+
collection = store.get_collection(
180+
collection_name=collection_name, record_type=record_type_with_key_as_key_field
181+
)
183182

184183
# Upsert
185184
await collection.create_collection()
@@ -220,7 +219,7 @@ async def test_custom_client(
220219
assert await store.list_collection_names() == []
221220

222221
collection_name = "list_collection_names"
223-
collection = store.get_collection(collection_name, record_type)
222+
collection = store.get_collection(collection_name=collection_name, record_type=record_type)
224223
await collection.create_collection()
225224

226225
collection_names = await store.list_collection_names()
@@ -230,6 +229,3 @@ async def test_custom_client(
230229
assert await collection.does_collection_exist() is False
231230
collection_names = await store.list_collection_names()
232231
assert collection_name not in collection_names
233-
234-
# Deleting the collection doesn't remove it from the vector_record_collections list in the store
235-
assert collection_name in store.vector_record_collections

python/tests/integration/memory/postgres/test_postgres_int.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from semantic_kernel.data.vector import (
1515
DistanceFunction,
1616
IndexKind,
17-
VectorSearchOptions,
1817
VectorStoreCollectionDefinition,
1918
VectorStoreField,
2019
vectorstoremodel,
@@ -111,7 +110,7 @@ async def create_simple_collection(
111110
"""
112111
suffix = str(uuid.uuid4()).replace("-", "")[:8]
113112
collection_id = f"test_collection_{suffix}"
114-
collection = vector_store.get_collection(collection_id, SimpleDataModel)
113+
collection = vector_store.get_collection(collection_name=collection_id, record_type=SimpleDataModel)
115114
assert isinstance(collection, PostgresCollection)
116115
await collection.create_collection()
117116
try:
@@ -128,7 +127,7 @@ def test_create_store(vector_store):
128127
async def test_create_does_collection_exist_and_delete(vector_store: PostgresStore):
129128
suffix = str(uuid.uuid4()).replace("-", "")[:8]
130129

131-
collection = vector_store.get_collection(f"test_collection_{suffix}", SimpleDataModel)
130+
collection = vector_store.get_collection(collection_name=f"test_collection_{suffix}", record_type=SimpleDataModel)
132131

133132
does_exist_1 = await collection.does_collection_exist()
134133
assert does_exist_1 is False
@@ -183,7 +182,9 @@ async def test_upsert_get_and_delete_pandas(vector_store):
183182

184183
suffix = str(uuid.uuid4()).replace("-", "")[:8]
185184
collection = vector_store.get_collection(
186-
f"test_collection_{suffix}", record_type=pd.DataFrame, definition=definition
185+
collection_name=f"test_collection_{suffix}",
186+
record_type=pd.DataFrame,
187+
definition=definition,
187188
)
188189
await collection.create_collection()
189190

@@ -249,9 +250,7 @@ async def test_search(vector_store: PostgresStore):
249250
await simple_collection.upsert(records)
250251

251252
try:
252-
search_results = await simple_collection.vectorized_search(
253-
[1.0, 0.0, 0.0], options=VectorSearchOptions(top=3, include_total_count=True)
254-
)
253+
search_results = await simple_collection.search(vector=[1.0, 0.0, 0.0], top=3, include_total_count=True)
255254
assert search_results is not None
256255
assert search_results.total_count == 3
257256
assert {result.record.id async for result in search_results.results} == {1, 2, 3}

python/tests/integration/memory/test_vector_store.py

Lines changed: 6 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from semantic_kernel.connectors.redis import RedisCollectionTypes
1212
from semantic_kernel.data.vector import VectorStore
1313
from semantic_kernel.exceptions import MemoryConnectorConnectionException
14-
from tests.integration.memory.data_records import RAW_RECORD_ARRAY, RAW_RECORD_LIST
14+
from tests.integration.memory.data_records import RAW_RECORD_LIST
1515
from tests.integration.memory.vector_store_test_base import VectorStoreTestBase
1616

1717
logger: logging.Logger = logging.getLogger(__name__)
@@ -38,19 +38,6 @@ class TestVectorStore(VectorStoreTestBase):
3838
],
3939
[
4040
# region Redis
41-
pytest.param(
42-
"redis",
43-
"redis_json_array_data_model",
44-
{"collection_type": RedisCollectionTypes.JSON},
45-
"dataclass_vector_data_model_array",
46-
None,
47-
None,
48-
None,
49-
None,
50-
5,
51-
RAW_RECORD_ARRAY,
52-
id="redis_json_array_data_model",
53-
),
5441
pytest.param(
5542
"redis",
5643
"redis_json_list_data_model",
@@ -77,19 +64,6 @@ class TestVectorStore(VectorStoreTestBase):
7764
RAW_RECORD_LIST,
7865
id="redis_json_pandas_data_model",
7966
),
80-
pytest.param(
81-
"redis",
82-
"redis_hashset_array_data_model",
83-
{"collection_type": RedisCollectionTypes.HASHSET},
84-
"dataclass_vector_data_model_array",
85-
None,
86-
None,
87-
None,
88-
None,
89-
5,
90-
RAW_RECORD_ARRAY,
91-
id="redis_hashset_array_data_model",
92-
),
9367
pytest.param(
9468
"redis",
9569
"redis_hashset_list_data_model",
@@ -118,19 +92,6 @@ class TestVectorStore(VectorStoreTestBase):
11892
),
11993
# endregion
12094
# region Azure AI Search
121-
pytest.param(
122-
"azure_ai_search",
123-
"azure_ai_search_array_data_model",
124-
{},
125-
"dataclass_vector_data_model_array",
126-
None,
127-
None,
128-
None,
129-
None,
130-
5,
131-
RAW_RECORD_ARRAY,
132-
id="azure_ai_search_array_data_model",
133-
),
13495
pytest.param(
13596
"azure_ai_search",
13697
"azure_ai_search_list_data_model",
@@ -159,19 +120,6 @@ class TestVectorStore(VectorStoreTestBase):
159120
),
160121
# endregion
161122
# region Qdrant
162-
pytest.param(
163-
"qdrant",
164-
"qdrant_array_data_model",
165-
{},
166-
"dataclass_vector_data_model_array",
167-
None,
168-
None,
169-
None,
170-
None,
171-
5,
172-
RAW_RECORD_ARRAY,
173-
id="qdrant_array_data_model",
174-
),
175123
pytest.param(
176124
"qdrant",
177125
"qdrant_list_data_model",
@@ -198,19 +146,6 @@ class TestVectorStore(VectorStoreTestBase):
198146
RAW_RECORD_LIST,
199147
id="qdrant_pandas_data_model",
200148
),
201-
pytest.param(
202-
"qdrant_in_memory",
203-
"qdrant_in_memory_array_data_model",
204-
{},
205-
"dataclass_vector_data_model_array",
206-
None,
207-
None,
208-
None,
209-
None,
210-
5,
211-
RAW_RECORD_ARRAY,
212-
id="qdrant_in_memory_array_data_model",
213-
),
214149
pytest.param(
215150
"qdrant_in_memory",
216151
"qdrant_in_memory_list_data_model",
@@ -237,19 +172,6 @@ class TestVectorStore(VectorStoreTestBase):
237172
RAW_RECORD_LIST,
238173
id="qdrant_in_memory_pandas_data_model",
239174
),
240-
pytest.param(
241-
"qdrant",
242-
"qdrant_grpc_array_data_model",
243-
{"prefer_grpc": True},
244-
"dataclass_vector_data_model_array",
245-
None,
246-
None,
247-
None,
248-
None,
249-
5,
250-
RAW_RECORD_ARRAY,
251-
id="qdrant_grpc_array_data_model",
252-
),
253175
pytest.param(
254176
"qdrant",
255177
"qdrant_grpc_list_data_model",
@@ -278,24 +200,6 @@ class TestVectorStore(VectorStoreTestBase):
278200
),
279201
# endregion
280202
# region Weaviate
281-
pytest.param(
282-
"weaviate_local",
283-
"weaviate_local_array_data_model",
284-
{},
285-
"dataclass_vector_data_model_array",
286-
None,
287-
None,
288-
None,
289-
None,
290-
5,
291-
RAW_RECORD_ARRAY,
292-
marks=pytest.mark.skipif(
293-
platform.system() != "Linux",
294-
reason="The Weaviate docker image is only available on Linux"
295-
" but some GitHubs job runs in a Windows container.",
296-
),
297-
id="weaviate_local_array_data_model",
298-
),
299203
pytest.param(
300204
"weaviate_local",
301205
"weaviate_local_list_data_model",
@@ -334,23 +238,6 @@ class TestVectorStore(VectorStoreTestBase):
334238
),
335239
# endregion
336240
# region Azure Cosmos DB
337-
pytest.param(
338-
"azure_cosmos_db_no_sql",
339-
"azure_cosmos_db_no_sql_array_data_model",
340-
{},
341-
"dataclass_vector_data_model_array",
342-
None,
343-
None,
344-
"flat",
345-
None,
346-
5,
347-
RAW_RECORD_ARRAY,
348-
marks=pytest.mark.skipif(
349-
platform.system() != "Windows",
350-
reason="The Azure Cosmos DB Emulator is only available on Windows.",
351-
),
352-
id="azure_cosmos_db_no_sql_array_data_model",
353-
),
354241
pytest.param(
355242
"azure_cosmos_db_no_sql",
356243
"azure_cosmos_db_no_sql_list_data_model",
@@ -387,19 +274,6 @@ class TestVectorStore(VectorStoreTestBase):
387274
),
388275
# endregion
389276
# region Chroma
390-
pytest.param(
391-
"chroma",
392-
"chroma_array_data_model",
393-
{},
394-
"dataclass_vector_data_model_array",
395-
None,
396-
None,
397-
None,
398-
None,
399-
5,
400-
RAW_RECORD_ARRAY,
401-
id="chroma_array_data_model",
402-
),
403277
pytest.param(
404278
"chroma",
405279
"chroma_list_data_model",
@@ -454,7 +328,10 @@ async def test_vector_store(
454328
async with (
455329
stores[store_id]() as vector_store,
456330
vector_store.get_collection(
457-
collection_name, record_type, definition, **collection_options
331+
record_type=record_type,
332+
definition=definition,
333+
collection_name=collection_name,
334+
**collection_options,
458335
) as collection,
459336
):
460337
try:
@@ -468,7 +345,7 @@ async def test_vector_store(
468345
pytest.fail(f"Failed to create collection: {exc}")
469346

470347
# Upsert record
471-
await collection.upsert(record_type([record]) if record_type == pd.DataFrame else record_type(**record))
348+
await collection.upsert(record_type([record]) if record_type is pd.DataFrame else record_type(**record))
472349
# Get record
473350
result = await collection.get(record["id"])
474351
assert result is not None

0 commit comments

Comments
 (0)