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

TextMemorySkill: Recall Can Return Many Memories, added Keyed Lookup Functions Retrieve() and Remove()

Open awharrison-28 opened this issue 2 years ago • 4 comments

Motivation and Context

Currently, TextMemorySkill Recall only returns the most relevant memory despite being reliant on methods that support returning N relevant memories.

Additionally, users should be able to Remove memories.

Description

This PR introduces new terminology to TextMemorySkill: Remove and Retrieve.

Remove and 'Retrieve' allows the TextMemorySkill get and delete memories from storage by unique key (since memories are stored as key-value pairs).

Users may Retrieve/Remove a single memory using the unique key associated with the memory.

Redefined function:

  • Recall -> look up a number of memories relevant to a given idea string. The number of results depends on a LimitParam and RelevanceParam provided by the SKContext. The results text records are concatenated to a single Json string.

New functions:

  • RetrieveAsync -> look up a specific memory associated with a unique key.
  • RemoveAsync -> delete a specific memory associated with a unique key.

Additional Changes:

  • Modified KernelSyntaxExample Example15_MemorySkill to use the new functions and features.
  • Added RemoveAsync to ISemanticTextMemory and its implementors SemanticTextMemory and NullMemory

Note: If the result of 'Recall' will be used for a completion skill, this could result in unexpected behavior if the text for N memories exceeds the model's token limit. Addressing input chunking to a completion model is not in scope for this PR.

Contribution Checklist

  • [x] The code builds clean without any errors or warnings
  • [x] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
  • [x] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with dotnet format
  • [x] All unit tests pass, and I have added new tests where possible
  • [x] I didn't break anyone :smile:

awharrison-28 avatar Mar 08 '23 01:03 awharrison-28

@awharrison-28 if there are any breaking changes, can we also get them reflected in the memory notebook?

https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/6-memory-and-embeddings.ipynb

alexchaomander avatar Mar 08 '23 02:03 alexchaomander

@alexchaomander great call out. Will update shortly.

awharrison-28 avatar Mar 08 '23 17:03 awharrison-28

@alexchaomander I updated the notebook to address breaking changes as is. We should update notebook 6 to reflect new TextMemorySkill features, but I believe that should be a separate PR.

awharrison-28 avatar Mar 08 '23 20:03 awharrison-28

@dluc will present a design proposal asap.

To address your concern (I think), this PR introduces the ability to forget both by 'key' and by 'idea' (i.e. semantically).

awharrison-28 avatar Mar 09 '23 00:03 awharrison-28