semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

MemoryQueryResult requires a relevance value

Open dleen opened this issue 2 years ago • 0 comments

Following the tutorial notebooks:

async def populate_memory(kernel: sk.Kernel) -> None:
    # Add some documents to the semantic memory
    await kernel.memory.save_information_async(
        "aboutMe", id="info1", text="My name is Andrea"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info2", text="I currently work as a tour guide"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info3", text="I've been living in Seattle since 2005"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info4", text="I visited France and Italy five times since 2015"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info5", text="My family is from New York"
    )

and calling:

await kernel.memory.get_async("aboutMe", "info1")

Results in the error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 await kernel.memory.get_async("aboutMe", "info1")

File [~/code/ncp/semantic-kernel/python/semantic_kernel/memory/semantic_text_memory.py:116](https://file+.vscode-resource.vscode-cdn.net/Users/dleen/code/ncp/semantic-kernel/samples/notebooks/python/~/code/ncp/semantic-kernel/python/semantic_kernel/memory/semantic_text_memory.py:116), in SemanticTextMemory.get_async(self, collection, key)
    106 """Get information from the memory (calls the memory store's get method).
    107 
    108 Arguments:
   (...)
    113     Optional[MemoryQueryResult] -- The MemoryQueryResult if found, None otherwise.
    114 """
    115 record = await self._storage.get_async(collection_name=collection, key=key)
--> 116 return MemoryQueryResult.from_memory_record(record) if record else None

TypeError: MemoryQueryResult.from_memory_record() missing 1 required positional argument: 'relevance'

Since this is an exact match using get_async and None if not found, we can assign a relevance of 1.0 meaning a perfect match.

dleen avatar May 26 '23 21:05 dleen