Skip to content

Implement Memory Metadata Enhancement API #10

@doobidoo

Description

@doobidoo

Overview

Currently, updating memory metadata requires deleting and re-creating the entire memory entry. This is inefficient for operations that only need to modify tags or other metadata attributes. A dedicated API for updating just the metadata of existing memories would improve system efficiency and reduce the risk of data loss.

Problem

When users need to enhance or modify the metadata (especially tags) of an existing memory, they currently have to:

  1. Retrieve the original memory
  2. Delete the entire memory entry
  3. Create a new memory with the same content but updated metadata

This approach has several drawbacks:

  • It's resource-intensive (requires multiple API calls)
  • Risks data corruption during the process
  • Creates a new timestamp, losing the original creation time
  • Generates a new memory ID/hash, breaking any existing references
  • Consumes more storage temporarily during the replacement process

Proposed Solution

Implement a dedicated update_memory_metadata function that allows modifying just the tags/metadata of an existing memory without recreating the entire entry.

Function Specification

async def update_memory_metadata(content_hash: str, metadata: dict) -> dict:
    """
    Update the metadata of an existing memory without modifying its content or creating a new entry.
    
    Args:
        content_hash: The hash/ID of the memory to update
        metadata: The new metadata to apply (can be partial update)
        
    Returns:
        dict: Status and information about the updated memory
        
    Raises:
        MemoryNotFoundError: If the specified memory doesn't exist
        InvalidMetadataError: If the provided metadata is invalid
    """

Implementation Details

  1. Add a new MCP tool for updating memory metadata
  2. Modify the ChromaDB integration to support metadata-only updates
  3. Implement validation for metadata format
  4. Add support for partial metadata updates (only changing specified fields)
  5. Ensure timestamp preservation during updates
  6. Add proper error handling for missing memories

Benefits

  • More efficient resource usage (processing and storage)
  • Maintains original creation timestamp
  • Preserves original memory ID/hash
  • Reduces risk of data corruption during update operations
  • Enables more sophisticated memory organization strategies

Use Cases

  • Adding new tags to existing memories
  • Removing tags from memories
  • Updating memory type or other metadata attributes
  • Programmatically organizing memories into categories
  • Implementing memory linking systems (connecting related memories)
  • Setting up memory time-to-live (TTL) attributes

Related Enhancement Ideas

This feature would enable more advanced memory organization features such as:

  1. Memory graph connections (linking related memories together)
  2. Hierarchical memory organization
  3. Smart tagging based on content analysis
  4. Automatic memory consolidation (related to the multi-layered time horizon concept)

Success Criteria

  • API successfully updates metadata without recreating entries
  • Original timestamps are preserved
  • Documentation updated with usage examples
  • Tests for various metadata update scenarios
  • Performance metrics showing efficiency improvement over delete/recreate

Priority

Medium - This is a foundational improvement that will enable many other enhancements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions