Memory API

Memory Layer Configuration Guide

Setting Up Memory Layer

The SDK provides a dedicated method for configuring and initializing memory components through the add_memory_layer method:

def add_memory_layer(self, config: MemoryLayer) -> 'Cerebrum':
    """Set up the memory core component."""
    result = self._post("/core/memory/setup", asdict(config))
    self._components_initialized.add("memory")
    self.results['memory'] = result
    return self

The method communicates with the /core/memory/setup endpoint for kernel-level configuration processing.

Memory Configuration

The MemoryLayer class defines essential memory management parameters:

@dataclass
class MemoryLayer:
    memory_limit: int = 104857600    # Maximum memory usage (100MB)
    eviction_k: int = 10             # Number of items to evict
    custom_eviction_policy: Optional[str] = None  # Custom eviction strategy

Key Components:

  • memory_limit: Controls maximum memory allocation (default: 100MB)

  • eviction_k: Determines batch size for memory cleanup

  • custom_eviction_policy: Allows implementation of specialized eviction strategies

Memory Operations

Query Structure

Memory operations are handled through the MemoryQuery class:

class MemoryQuery(BaseModel):
    messages: List[Dict[str, Union[str, Any]]]  # Message list with content
    operation_type: str  # Operation specification

    class Config:
        arbitrary_types_allowed = True  # Enables complex type usage

Operation Types

  • Read Operations: Retrieve stored information

  • Write Operations: Store new data

  • Update Operations: Modify existing entries

  • Delete Operations: Remove stored data

Last updated