Skip to content

Intro

What are Nested Memories?

Nested memories (also called related memories) are memories that are linked together through the related_memory_ids field. When you retrieve a memory, the system automatically loads all related memories recursively, up to 3 levels deep, providing complete context.

Key Concepts

  • Related Memory IDs: Each memory can have an array of related memory IDs
  • Automatic Loading: Related memories are automatically loaded when using retrieve_memory, search_memory, or get_project_main_memory
  • Recursive Depth: The system loads related memories up to 3 levels deep
  • Cross-Collection: Related memories can be in different collections
  • Bidirectional Links: The system automatically maintains bidirectional relationships

Example: E-commerce API Project

Let's see how nested memories work with a real-world example. Here's a complete memory hierarchy for an "E-commerce API" project:

graph TD
    Main[Project Main Memory<br/>E-commerce API<br/>ID: mem-main-001<br/>Type: project-main]

    Main -->|related_memory_ids| Decision1[Decision: Database Choice<br/>PostgreSQL Selected<br/>ID: mem-db-001]
    Main -->|related_memory_ids| Module1[Module: Authentication<br/>JWT Implementation<br/>ID: mem-auth-001]
    Main -->|related_memory_ids| Task1[Task: Shopping Cart<br/>Implementation Plan<br/>ID: mem-cart-001]

    Decision1 -->|related_memory_ids| Config1[Config: Index Strategy<br/>PostgreSQL Indexes<br/>ID: mem-index-001]
    Decision1 -->|related_memory_ids| Config2[Config: Backup Strategy<br/>Daily Backups<br/>ID: mem-backup-001]

    Module1 -->|related_memory_ids| Impl1[Implementation: JWT Tokens<br/>Token Generation<br/>ID: mem-jwt-001]
    Module1 -->|related_memory_ids| Impl2[Implementation: Refresh Tokens<br/>Token Refresh Logic<br/>ID: mem-refresh-001]

    Task1 -->|related_memory_ids| Model1[Model: Cart Data<br/>Cart Schema Design<br/>ID: mem-model-001]
    Task1 -->|related_memory_ids| API1[API: Cart Endpoints<br/>REST API Design<br/>ID: mem-api-001]

    Config1 -->|related_memory_ids| Detail1[Detail: Index Types<br/>B-tree vs Hash<br/>ID: mem-detail-001]

    Impl1 -->|related_memory_ids| Detail2[Detail: Token Expiry<br/>30min Access Tokens<br/>ID: mem-detail-002]

    Model1 -->|related_memory_ids| Detail3[Detail: Cart Items<br/>Item Structure<br/>ID: mem-detail-003]

    style Main fill:#667eea,stroke:#764ba2,stroke-width:3px,color:#fff
    style Decision1 fill:#4facfe,stroke:#00f2fe,stroke-width:2px
    style Module1 fill:#4facfe,stroke:#00f2fe,stroke-width:2px
    style Task1 fill:#4facfe,stroke:#00f2fe,stroke-width:2px
    style Config1 fill:#fa709a,stroke:#fee140,stroke-width:2px
    style Config2 fill:#fa709a,stroke:#fee140,stroke-width:2px
    style Impl1 fill:#fa709a,stroke:#fee140,stroke-width:2px
    style Impl2 fill:#fa709a,stroke:#fee140,stroke-width:2px
    style Model1 fill:#fa709a,stroke:#fee140,stroke-width:2px
    style API1 fill:#fa709a,stroke:#fee140,stroke-width:2px
    style Detail1 fill:#a8edea,stroke:#fed6e3,stroke-width:2px
    style Detail2 fill:#a8edea,stroke:#fed6e3,stroke-width:2px
    style Detail3 fill:#a8edea,stroke:#fed6e3,stroke-width:2px

Memory Hierarchy Breakdown

Level 0 (Root): - Main Memory: "E-commerce API" project overview - Contains: Project architecture, tech stack, core decisions - Type: project-main, State: active

Level 1 (Direct Relations): - Decision: "PostgreSQL Selected" - Database choice decision - Module: "Authentication" - JWT implementation module - Task: "Shopping Cart" - Implementation plan

Level 2 (Second Level): - From Decision: Index strategy, Backup strategy - From Module: JWT token generation, Refresh token logic - From Task: Cart data model, Cart API endpoints

Level 3 (Third Level): - From Config: Index type details (B-tree vs Hash) - From Implementation: Token expiry details (30min access tokens) - From Model: Cart item structure details