TextMemorySkill: Recall Can Return Many Memories, added Keyed Lookup Functions Retrieve() and Remove()
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 aLimitParamandRelevanceParamprovided 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_MemorySkillto use the new functions and features. - Added
RemoveAsynctoISemanticTextMemoryand its implementorsSemanticTextMemoryandNullMemory
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 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 great call out. Will update shortly.
@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.
@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).