Skip to content

Memory Architecture

Overview

Archety uses Supermemory as its primary memory service, with mem0 available as a legacy fallback. The memory system provides persistent, cross-session context for AI personas to remember user information, trips, preferences, and conversation history.

Why Supermemory Over mem0

We migrated from mem0 to Supermemory in December 2025. Here's the comparison:

Feature Supermemory mem0
Latency <300ms (25x faster) 2-8 seconds
User Profiles Built-in static/dynamic facts Manual implementation
Knowledge Graph Automatic entity relationships Not available
Smart Forgetting Automatic temporal decay Manual cleanup
Container Tags Multi-dimensional filtering Single namespace string
Token Limits More generous 100k tokens, 2k metadata
Cost Competitive Higher at scale

Key Benefits

  1. User Profiles for Cross-Session Context
  2. Supermemory automatically maintains user profiles with static facts (name, preferences) and dynamic facts (current activities, trips)
  3. This solves the "Sage forgets my trip the next day" problem
  4. Profiles are injected into system prompts for every conversation

  5. Knowledge Graph

  6. Automatic entity extraction and relationship mapping
  7. "User mentioned friend Sarah who lives in Tokyo" creates linked entities
  8. Better context retrieval for complex queries

  9. Performance

  10. Sub-300ms latency vs 2-8 second waits with mem0
  11. Better user experience, especially for real-time chat

  12. Container Tags

  13. More flexible than single namespace strings
  14. Can filter by multiple dimensions: ["user_+15551234567", "persona_sage", "type_trip"]

Architecture

┌─────────────────────────────────────────────────────────────┐
│                     Application Layer                        │
├─────────────────────────────────────────────────────────────┤
│  TwoStageHandler    TripPlanner    GroupFeatures            │
│       │                 │               │                    │
│       └────────────────┼───────────────┘                    │
│                        ▼                                     │
│              get_memory_service()                            │
│                        │                                     │
│         ┌──────────────┼──────────────┐                     │
│         ▼              │              ▼                      │
│  SupermemoryService    │      MemoryService (mem0)          │
│  (Primary)             │      (Legacy Fallback)             │
│         │              │              │                      │
└─────────┼──────────────┼──────────────┼─────────────────────┘
          │              │              │
          ▼              │              ▼
   Supermemory API       │        mem0 API
              Feature Flag: use_supermemory

Service Selection

The memory service is selected based on configuration in app/config.py:

# Feature flag (default: True)
use_supermemory: bool = True

# API keys
supermemory_api_key: Optional[str] = None  # Primary
mem0_api_key: Optional[str] = None         # Fallback

Selection logic in app/memory/__init__.py: 1. If use_supermemory=True AND supermemory_api_key is set → Use Supermemory 2. Else if mem0_api_key is set → Use mem0 (legacy) 3. Else → Raise error

Namespace Isolation

Supermemory (Container Tags)

# Direct messages: user + persona isolation
container_tags = ["user_+15551234567", "persona_sage"]

# Group chats: group-level isolation
container_tags = ["group_iMessage;+;chat123456"]

mem0 (Legacy - Namespace Strings)

# Direct: "{user_id}_{persona_id}"
namespace = "+15551234567_sage"

# Group: "group_{chat_guid}"
namespace = "group_iMessage;+;chat123456"

Key Features

1. User Profiles (Supermemory Only)

# Get user profile for system prompt injection
profile = memory_service.get_user_profile(
    user_id="+15551234567",
    persona_id="sage"
)

# Returns structured profile:
{
    "static_facts": ["Name: John", "Lives in: San Francisco"],
    "dynamic_facts": ["Planning trip to Tokyo (Dec 10-15)"],
    "interests": ["photography", "Japanese food"],
    "preferences": ["prefers morning messages"]
}

2. Trip Memory Persistence

# Save trip to user profile for cross-session recall
memory_service.add_trip_memory(
    user_id="+15551234567",
    persona_id="sage",
    trip_destination="Tokyo",
    trip_dates="Dec 10-15, 2025",
    venue_count=12,
    trip_id="session_abc123"
)
# Search with semantic similarity
results = memory_service.search_memories(
    query="coffee preferences",
    user_id="+15551234567",
    persona_id="sage",
    limit=5
)

Configuration

Environment Variables

# Supermemory (Primary)
SUPERMEMORY_API_KEY=sm_your_api_key_here
USE_SUPERMEMORY=true  # Feature flag

# mem0 (Legacy Fallback)
MEM0_API_KEY=your_mem0_key  # Optional, for fallback

Railway Setup

# Set Supermemory key
railway variables set SUPERMEMORY_API_KEY=sm_your_key

# Optional: Keep mem0 as fallback
railway variables set MEM0_API_KEY=your_mem0_key

Ingestion Safeguards

To prevent oversized payloads (learned from mem0 incidents):

  1. Text Limits: Summarizes text above 8k chars with head/tail excerpt
  2. Metadata Limits: Prunes metadata above ~1.9k chars
  3. Logging: Warns when truncation occurs for debugging
  4. Async Processing: Large artifacts processed in background

See app/memory/supermemory_service.py for implementation.

Migration Guide

From mem0 to Supermemory

  1. Set API Key:

    export SUPERMEMORY_API_KEY=sm_your_key
    

  2. Enable Feature Flag (already default):

    use_supermemory: bool = True
    

  3. Deploy: Existing mem0 memories remain accessible via fallback

Backward Compatibility

  • get_memory_service() returns whichever service is active
  • Both services implement the same interface
  • Fallback to mem0 if Supermemory unavailable

Files

File Purpose
app/memory/__init__.py Factory function, service selection
app/memory/supermemory_service.py Supermemory implementation
app/memory/event_tracker.py Proactive "I Remember" event detection
app/memory/query_synthesizer.py Multi-query auxiliary question generation
app/memory/memory_maintenance.py Nightly deduplication service
app/memory/mem0_service.py mem0 legacy implementation
app/config.py Configuration and feature flags

Testing

# Test memory service initialization
python -c "
from app.memory import get_memory_service
service = get_memory_service()
print(f'Using: {type(service).__name__}')
"

# Expected output with Supermemory configured:
# Using: SupermemoryService

Troubleshooting

"No memory service configured"

  • Ensure either SUPERMEMORY_API_KEY or MEM0_API_KEY is set

Falling back to mem0 unexpectedly

  • Check SUPERMEMORY_API_KEY is set correctly
  • Check USE_SUPERMEMORY is not set to false

Slow memory operations

  • Supermemory should be <300ms
  • If using mem0 fallback, 2-8s is expected

Last Updated: December 2025 Migration Status: Supermemory is primary, mem0 is legacy fallback