feat(memory): add session and user memory deletion APIs - #7175
Open
ArulJerald wants to merge 1 commit into
Open
ArulJerald wants to merge 1 commit into
ArulJerald wants to merge 1 commit into
Conversation
Session deletion in session services leaves previously ingested conversations in memory services without a removal path. Add `delete_session_memory` and `delete_user_memory` to `BaseMemoryService`, implement them in `InMemoryMemoryService`, and expose corresponding convenience helpers on `Context` for retention lifecycle management and right-to-be-forgotten / GDPR compliance. Closes google#7109
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
Calling
BaseSessionService.delete_session()removes session records from the session store, but leaves behind memories copied or synthesized intoBaseMemoryServiceviaadd_session_to_memory()oradd_events_to_memory(). Furthermore,BaseMemoryServiceoffered no removal or purge API, making it impossible to clean up session memory or comply with user-level data retention / right-to-be-forgotten requirements.Solution:
delete_session_memory(*, app_name, user_id, session_id)anddelete_user_memory(*, app_name, user_id)toBaseMemoryServicewith default implementations raisingNotImplementedError.InMemoryMemoryServiceunderself._lock, safely cleaning up empty user buckets.delete_session_memory(session_id=None)(defaulting to the current session) anddelete_user_memory()convenience helpers onContext.BaseSessionService.delete_session()and added a Lifecycle & Removal guide indocs/guides/memory/memory_service/index.md.Testing Plan
Unit Tests:
Summary of passed
pytestresults:Tests added:
test_delete_session_memory: Verifies session deletion removes matching session memories while leaving other sessions intact.test_delete_session_memory_cleans_up_empty_user_bucket: Verifies user entry cleanup when the last session memory is purged.test_delete_session_memory_nonexistent_is_noop: Verifies idempotent no-op deletion.test_delete_user_memory: Verifies purging all memories for a user across multiple sessions.test_delete_user_memory_nonexistent_is_noop: Verifies idempotent no-op on missing user.test_base_memory_service_default_deletion_methods: VerifiesNotImplementedErrorraised on unimplemented backends.test_delete_memory_is_thread_safe_against_concurrent_searches: Verifies thread safety under concurrent reader and deleter threads.test_delete_session_memory_default_current_session,test_delete_session_memory_explicit_session_id,test_delete_user_memory_success, and no-service error cases intest_context.py.Checklist