What happens
VolatileMemoryStore.get_nearest_match is declared async def, but it returns the result of calling self.get_nearest_matches(...) without awaiting it. get_nearest_matches is also async def, so await store.get_nearest_match(...) gives the caller a coroutine, not the tuple[MemoryRecord, float] the signature promises. The inner coroutine is never run and Python warns "coroutine ... was never awaited". Even if it were awaited, it would be a list of tuples, not a single tuple.
Where
python/semantic_kernel/memory/volatile_memory_store.py, get_nearest_match (current main):
) -> tuple[MemoryRecord, float]:
...
return self.get_nearest_matches(
collection_name=collection_name,
embedding=embedding,
limit=1,
min_relevance_score=min_relevance_score,
with_embeddings=with_embedding,
)
Reproduce
import asyncio, numpy as np
from semantic_kernel.memory.volatile_memory_store import VolatileMemoryStore
from semantic_kernel.memory.memory_record import MemoryRecord
async def main():
s = VolatileMemoryStore()
await s.create_collection("c")
await s.upsert("c", MemoryRecord.local_record("id1", "text", "desc", None, np.array([1.0, 0.0])))
m = await s.get_nearest_match("c", np.array([1.0, 0.0]))
print(type(m))
asyncio.run(main())
Output on semantic-kernel main (also 1.44.1): <class 'coroutine'>
Expected
await store.get_nearest_match(...) returns a (MemoryRecord, score) tuple, as MemoryStoreBase.get_nearest_match documents. ChromaMemoryStore.get_nearest_match already does this: results = await self.get_nearest_matches(...) followed by return results[0].
Notes
The class is deprecated, but it is still exported from semantic_kernel.memory. I can send a fix with a test.
What happens
VolatileMemoryStore.get_nearest_matchis declaredasync def, but it returns the result of callingself.get_nearest_matches(...)without awaiting it.get_nearest_matchesis alsoasync def, soawait store.get_nearest_match(...)gives the caller a coroutine, not thetuple[MemoryRecord, float]the signature promises. The inner coroutine is never run and Python warns "coroutine ... was never awaited". Even if it were awaited, it would be a list of tuples, not a single tuple.Where
python/semantic_kernel/memory/volatile_memory_store.py,get_nearest_match(current main):Reproduce
Output on semantic-kernel main (also 1.44.1):
<class 'coroutine'>Expected
await store.get_nearest_match(...)returns a(MemoryRecord, score)tuple, asMemoryStoreBase.get_nearest_matchdocuments.ChromaMemoryStore.get_nearest_matchalready does this:results = await self.get_nearest_matches(...)followed byreturn results[0].Notes
The class is deprecated, but it is still exported from
semantic_kernel.memory. I can send a fix with a test.