Skip to content

Python: VolatileMemoryStore.get_nearest_match returns an un-awaited coroutine instead of a (MemoryRecord, score) tuple #14521

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonPull requests for the Python Semantic Kerneltriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions