Hákon Freyr

Memory Palace

Graph-Based Semantic Memory System. A graph-based semantic memory system that stores, relates, and retrieves knowledge using Neo4j and vector embeddings. Features a custom query language built on the discriminated union specification pattern, a type-safe Cypher query builder with compile-time validation, and integration as an MCP server so Claude.ai can use it as persistent external memory.

General notes

  1. Clean architecture with enforced layer boundaries: domain → infrastructure → services → api. Protocol-based interfaces for all external integrations
  2. Extensible query API using discriminated union specification pattern: 12+ composable spec types generating both Python predicates and Cypher WHERE clauses
  3. Type-safe Cypher query builder with state machine validating clause ordering at construction time
  4. Integrated as MCP server enabling Claude.ai to use the system as persistent external memory

Construction notes

  1. Discriminated union specification pattern: MemorySpecification is an Annotated union composable via .and_(), .or_(), .not_(). Each spec generates both Python predicates and Cypher WHERE clauses
  2. Type-safe Cypher query builder with state machine validating clause ordering at construction time. LiteralString typing throughout for injection safety
  3. Circuit breaker (CLOSED → OPEN → HALF_OPEN) with exponential backoff for Voyage AI embedding calls. Proper error classification (rate limit → retryable, auth → not)
  4. Typed error architecture: ApplicationError base with ErrorCode enum, ErrorLevel, typed ErrorDetails models. @with_error_handling decorator with configurable reraise behavior
  5. Event-driven background processing: DreamJobOrchestrator runs scheduled jobs including salience decay (configurable half-life), DBSCAN topic clustering, and re-indexing

12+ Composable specification types in the query DSL

4-layer Clean architecture with enforced boundaries

MCP Integrated as Claude.ai external memory server

Materials

  • Python/FastAPI
  • Neo4j
  • Voyage AI
  • OAuth
  • Cloudflare Tunnel
  • MCP
Project
Hákon Freyr Gunnarsson
Sheet
Detail G
Title
Memory Palace
Scale
N.T.S.
Rev
2026-10