From f09cda25a9a3fc83fe9e1b3c8eea1ce59a132420 Mon Sep 17 00:00:00 2001 From: Jeevan Babu Gotru <114808955+jeevan1098@users.noreply.github.com> Date: Wed, 7 Oct 2026 11:07:08 -0500 Subject: [PATCH 1/3] fix(python): return empty list from get_nearest_matches on empty collection --- python/semantic_kernel/memory/volatile_memory_store.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/semantic_kernel/memory/volatile_memory_store.py b/python/semantic_kernel/memory/volatile_memory_store.py index dd1a631d0614..7a57862f1edd 100644 --- a/python/semantic_kernel/memory/volatile_memory_store.py +++ b/python/semantic_kernel/memory/volatile_memory_store.py @@ -251,6 +251,9 @@ async def get_nearest_matches( # Get all the records in the collection memory_records = list(self._store[collection_name].values()) + if not memory_records: + return [] + # Convert the collection of embeddings into a numpy array (stacked) embeddings = array([x._embedding for x in memory_records], dtype=float) embeddings = embeddings.reshape(embeddings.shape[0], -1) From cd68618240c0d4a817c2abdae9ce78e6531bac9a Mon Sep 17 00:00:00 2001 From: Jeevan Babu Gotru <114808955+jeevan1098@users.noreply.github.com> Date: Wed, 7 Oct 2026 11:07:36 -0500 Subject: [PATCH 2/3] test(python): placeholder for volatile memory store tests --- python/tests/unit/memory/test_volatile_memory_store.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 python/tests/unit/memory/test_volatile_memory_store.py diff --git a/python/tests/unit/memory/test_volatile_memory_store.py b/python/tests/unit/memory/test_volatile_memory_store.py new file mode 100644 index 000000000000..f18ac1be6bba --- /dev/null +++ b/python/tests/unit/memory/test_volatile_memory_store.py @@ -0,0 +1 @@ +# placeholder - replaced by upload From 502b465c3641bc1cf527ecc25ffd6a514c4fcab5 Mon Sep 17 00:00:00 2001 From: Jeevan Babu Gotru <114808955+jeevan1098@users.noreply.github.com> Date: Wed, 7 Oct 2026 11:07:50 -0500 Subject: [PATCH 3/3] test(python): add regression tests for get_nearest_matches on empty collection --- .../unit/memory/test_volatile_memory_store.py | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/python/tests/unit/memory/test_volatile_memory_store.py b/python/tests/unit/memory/test_volatile_memory_store.py index f18ac1be6bba..3b3f6323ff22 100644 --- a/python/tests/unit/memory/test_volatile_memory_store.py +++ b/python/tests/unit/memory/test_volatile_memory_store.py @@ -1 +1,39 @@ -# placeholder - replaced by upload +# Copyright (c) Microsoft. All rights reserved. + +import numpy as np + +from semantic_kernel.memory.memory_record import MemoryRecord +from semantic_kernel.memory.volatile_memory_store import VolatileMemoryStore + + +async def test_get_nearest_matches_empty_collection(): + store = VolatileMemoryStore() + await store.create_collection("test") + result = await store.get_nearest_matches("test", np.array([1.0, 2.0]), limit=3) + assert result == [] + + +async def test_get_nearest_matches_missing_collection(): + store = VolatileMemoryStore() + result = await store.get_nearest_matches("missing", np.array([1.0, 2.0]), limit=3) + assert result == [] + + +async def test_get_nearest_matches_with_records(): + store = VolatileMemoryStore() + await store.create_collection("test") + await store.upsert( + "test", + MemoryRecord( + is_reference=False, + external_source_name=None, + id="first", + description="first record", + text="hello", + additional_metadata=None, + embedding=np.array([1.0, 0.0]), + ), + ) + result = await store.get_nearest_matches("test", np.array([1.0, 0.0]), limit=3) + assert len(result) == 1 + assert result[0][0].id == "first"