Skip to main content
This section shows how to update an existing memory’s content using the default configuration.

Basic Update

  • Python SDK
  • JavaScript SDK
from gravixlayer import GravixLayer

client = GravixLayer()
memory = client.memory

# Add a memory to update
add_result = memory.add("User likes pizza", user_id="alice")
memory_id = add_result['results'][0]['id']

# Update the memory content
update_result = memory.update(memory_id, "alice", "User loves pizza and Italian cuisine")
print(f"Update result: {update_result['message']}")

# Verify the update
updated_memories = memory.get_all(user_id="alice")
for mem in updated_memories['results']:
    if mem['id'] == memory_id:
        print(f"Updated content: {mem['memory']}")
        break
Expected Output:
Update result: Memory a1b2c3d4-e5f6-7890-abcd-ef1234567890 updated successfully!
Updated content: User loves pizza and Italian cuisine

Update in Categories

Update memories in specific categories for better organization:
  • Python SDK
  • JavaScript SDK
from gravixlayer import GravixLayer

client = GravixLayer()
memory = client.memory

# Set up memories in different categories
print("Setting up categorized memories...")

# Add to user preferences
memory.switch_index("user_preferences")
pref_result = memory.add("User prefers light theme", user_id="alice", metadata={"type": "ui"})
pref_memory_id = pref_result['results'][0]['id']

# Add to work info
memory.switch_index("work_info")
work_result = memory.add("User works as junior developer", user_id="alice", metadata={"type": "job"})
work_memory_id = work_result['results'][0]['id']

print("Added memories to different categories\n")

# Update memory in user preferences
print("Updating user preference...")
memory.switch_index("user_preferences")
pref_update = memory.update(pref_memory_id, "alice", "User strongly prefers dark theme", 
                           metadata={"type": "ui", "strength": "strong"})
print(f"Preference update: {pref_update['message']}")

# Update memory in work info
print("\nUpdating work information...")
memory.switch_index("work_info")
work_update = memory.update(work_memory_id, "alice", "User works as senior software engineer", 
                           metadata={"type": "job", "level": "senior"})
print(f"Work update: {work_update['message']}")

# Verify updates in each category
print("\n=== VERIFICATION ===")
categories = [
    ("user_preferences", pref_memory_id),
    ("work_info", work_memory_id)
]

for category, mem_id in categories:
    memory.switch_index(category)
    memories = memory.get_all(user_id="alice")
    
    for mem in memories['results']:
        if mem['id'] == mem_id:
            print(f"\n{category}:")
            print(f"  Content: {mem['memory']}")
            print(f"  Metadata: {mem.get('metadata', {})}")
            print(f"  Updated: {mem.get('updated_at', 'N/A')}")
            break

# List all available indexes
indexes = memory.list_available_indexes()
print(f"\nAvailable indexes: {indexes}")
Expected Output:
Setting up categorized memories...
✅ Switched to index: user_preferences
✅ Switched to index: work_info
Added memories to different categories

Updating user preference...
✅ Switched to index: user_preferences
Memory b2c3d4e5-f6g7-8901-bcde-f23456789012 updated successfully!

Updating work information...
✅ Switched to index: work_info
Memory c3d4e5f6-g7h8-9012-cdef-345678901234 updated successfully!

=== VERIFICATION ===
✅ Switched to index: user_preferences

user_preferences:
  Content: User strongly prefers dark theme
  Metadata: {'type': 'ui', 'strength': 'strong'}
  Updated: 2025-10-22T10:40:15.123456

✅ Switched to index: work_info

work_info:
  Content: User works as senior software engineer
  Metadata: {'type': 'job', 'level': 'senior'}
  Updated: 2025-10-22T10:40:16.234567

Available indexes: ['gravixlayer_memories', 'user_preferences', 'work_info']
I