-
Notifications
You must be signed in to change notification settings - Fork 770
Description
Describe the bug
I noticed that in static class ISemanticMemoryClientExtensions in extension method RemoveChatMemoriesAsync, it is parsing the document ids wrong.
public static async Task RemoveChatMemoriesAsync(
this IKernelMemory memoryClient,
string indexName,
string chatId,
CancellationToken cancellationToken = default)
{
var memories = await memoryClient.SearchMemoryAsync(indexName, "*", 0.0F, chatId, cancellationToken: cancellationToken);
var documentIds = memories.Results.Select(memory => memory.Link.Split('/').First()).Distinct().ToArray();
var tasks = documentIds.Select(documentId => memoryClient.DeleteDocumentAsync(documentId, indexName, cancellationToken)).ToArray();
Task.WaitAll(tasks, cancellationToken);
}The method above tries to get the document id for each result with memory.Link.Split('/').First(). As the link is actually in format of $"{index}/{documentId}/{fileId}", it ends up picking up the index name. The documentIds array variable will always only contain the index names. Because of that, the document deletion doesn't work properly.
I can create a pull request to fix this if you agree of the issue. Instead of using the first element, we must get the second element in the split array. I don't have an instance of chat-copilot running so I couldn't test it in practice, but by reading the code, it seems to be a clear case.
To Reproduce
Steps to reproduce the behavior:
- Create a conversation
- Chat a few times to collect memories
- Confirm that the index contains memories for the session
- Delete the conversation (chat session)
- Check if the memories exist in the index
Expected behavior
Memories for the deleted chat session are deleted.
Platform
- Language: C#
- Source: main branch