Skip to content

Conversation

@ShreyP88
Copy link
Contributor

@ShreyP88 ShreyP88 commented Nov 3, 2025

Summary

  • Adding a to delete all long-term memory records within a specific namespace using batch operations.
    • Retrieves all memory records in the specified namespace
    • Performs batch deletion using batch_delete_memory_records API
    • Returns deletion results with success/failure counts

Testing

Added 3 test cases covering:
• Successful deletion of multiple records
• Empty namespace handling (no API call made)
• ClientError exception handling

tests/bedrock_agentcore/memory/test_session.py::TestSessionManager::test_delete_all_long_term_memories_in_namespace_success PASSED [ 33%]
tests/bedrock_agentcore/memory/test_session.py::TestSessionManager::test_delete_all_long_term_memories_in_namespace_empty PASSED [ 66%]
tests/bedrock_agentcore/memory/test_session.py::TestSessionManager::test_delete_all_long_term_memories_in_namespace_client_error PASSED [100%]

Manual Test:

    # Initialize the memory session manager
    manager = MemorySessionManager(
        memory_id="pantsssssdubs-HlUQcm8wdt",
        region_name="us-east-1"
    )
    
    namespace = "example/demo"
    
    print("🚀 Starting memory operations demo...")
    
    # Step 1: Batch create memory records
    print("\n1️⃣ Creating memory records...")
    memory_records = [
        {
            "requestIdentifier": "req-1",
            "content": {"text": "Python is a great programming language"},
            "namespaces": [namespace],
            "timestamp": "2024-01-01T12:00:00Z"
        },
        {
            "requestIdentifier": "req-2", 
            "content": {"text": "AWS Bedrock AgentCore provides memory services"},
            "namespaces": [namespace],
            "timestamp": "2024-01-01T12:01:00Z"
        },
        {
            "requestIdentifier": "req-3",
            "content": {"text": "Batch operations are efficient for bulk data"},
            "namespaces": [namespace],
            "timestamp": "2024-01-01T12:02:00Z"
        }
    ]
    
    create_result = manager.batch_create_memory_records(
        memoryId=manager._memory_id,
        records=memory_records
    )
    
    successful_creates = len(create_result.get("successfulRecords", []))
    print(f"✅ Created {successful_creates} memory records")
    
    # Wait for records to be indexed
    print("\n⏳ Waiting 10 seconds for records to be indexed...")
    time.sleep(10)
    
    # Step 2: List memory records in the namespace
    print(f"\n2️⃣ Listing memory records in namespace '{namespace}'...")
    records = manager.list_long_term_memory_records(namespace_prefix=namespace)
    
    print(f"📋 Found {len(records)} records:")
    for i, record in enumerate(records, 1):
        content = record.get("content", {}).get("text", "No content")
        record_id = record.get("memoryRecordId", "No ID")
        print(f"  {i}. {content[:50]}... (ID: {record_id})")
    
    # Step 3: Delete all memory records in the namespace
    print(f"\n3️⃣ Deleting all memory records in namespace '{namespace}'...")
    delete_result = manager.delete_all_long_term_memories_in_namespace(namespace)
    
    successful_deletes = len(delete_result.get("successfulRecords", []))
    failed_deletes = len(delete_result.get("failedRecords", []))
    
    print(f"🗑️ Deletion complete: {successful_deletes} successful, {failed_deletes} failed")

@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 47.36842% with 20 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@90f04bf). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/bedrock_agentcore/memory/session.py 47.36% 19 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #147   +/-   ##
=======================================
  Coverage        ?   88.74%           
=======================================
  Files           ?       24           
  Lines           ?     2452           
  Branches        ?      346           
=======================================
  Hits            ?     2176           
  Misses          ?      170           
  Partials        ?      106           
Flag Coverage Δ
unittests 88.74% <47.36%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ShreyP88 ShreyP88 closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants