Skip to content

Architecture

System Overview

MemoryLayer is infrastructure: a memory backend that agents and agent frameworks consume, the way applications use PostgreSQL for relational data or Redis for caching.

┌──────────────────────────────────────────────────────────────────┐
│ Agent hosts & frameworks │
│ Claude Code · OpenCode · Codex · OpenClaw · LangChain · LlamaIndex│
├──────────────────────────────────────────────────────────────────┤
│ Clients │
│ Python SDK · TypeScript SDK · Go SDK · MCP server (TypeScript) │
│ Transport: HTTP, or optionally an Aether relay │
├──────────────────────────────────────────────────────────────────┤
│ MemoryLayer server (FastAPI) `memorylayer` CLI │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ REST API /v1/* │ │
│ ├────────────────────────────────────────────────────────────┤ │
│ │ Services (plugins) │ │
│ │ Memory · Recall · Reflect · Session · Context pack │ │
│ │ Association · Ontology · Entity registry · Representation │ │
│ │ Graph analysis · Knowledge base · Documents · Chat │ │
│ │ Skills · MCP registry · Context environment · Tasks │ │
│ ├────────────────────────────────────────────────────────────┤ │
│ │ Server plugins: memorylayer-server-rpg (/v1/rpg) │ │
│ ├────────────────────────────────────────────────────────────┤ │
│ │ Storage: SQLite + sqlite-vec + FTS5 (optional Turso) │ │
│ └────────────────────────────────────────────────────────────┘ │
├──────────────────────────────────────────────────────────────────┤
│ Peers: embedding provider (hash · embed-server · OpenAI · │
│ Google) · LLM provider (OpenAI · Anthropic · Google · │
│ Fireworks) │
└──────────────────────────────────────────────────────────────────┘

Editions

MemoryLayer comes in three open-source, self-hosted editions. See Editions & Licensing for the full comparison.

EditionLicenseRole in the architecture
MemoryLayer (core)Apache-2.0Everything on this page unless marked otherwise: the server, the full retrieval engine, SDKs, the MCP server, agent-host plugins, the embed server, and the RPG plugin
MemoryLayer EnterpriseAGPL-3.0-onlyReplaces the storage substrate (PostgreSQL + pgvector + Apache AGE + pg_textsearch) and adds background workers, tiering, datasets, collections, trajectories, data connectors, tenant and admin services, and an admin dashboard
MemoryLayer StorageAGPL-3.0-only (Python client Apache-2.0)Content-addressed object storage and a POSIX filesystem with deduplication and compression. Enterprise uses it for blob storage.

The retrieval engine is entirely in core: hybrid search, retrieval channels, the knowledge graph, the entity registry, perspective, reflection, temporal recall, the knowledge base, and the context sandbox. Enterprise does not unlock retrieval features. It swaps the storage and task substrate underneath them and adds what you need to run memory as shared production infrastructure.

Clients

All clients wrap the same REST API.

ClientPackageNotes
Python SDKmemorylayer-clientAsync MemoryLayerClient and SyncMemoryLayerClient; Pydantic models; optional Aether transport
TypeScript SDK@scitrera/memorylayer-sdkfetch-based; typed errors; browser-safe bundle
Go SDKgithub.com/scitrera/memorylayer/memorylayer-sdk-gocontext.Context-aware; a nested aether/ module provides an Aether-relay transport. See Go SDK.
MCP server@scitrera/memorylayer-mcp-serverA separate process that wraps the TypeScript SDK

The SDKs expose namespaces for memories, sessions, workspaces, entities, skills, MCP servers, the knowledge base (kb), and RPG (rpg). On-behalf-of authority can be attached per request.

MCP Server

MCP client (Claude, Codex, …) ←→ MCP server ←→ TypeScript SDK ←→ REST API ←→ MemoryLayer server

The MCP server offers tool profiles, selected with MEMORYLAYER_TOOL_PROFILE:

ProfileToolsContents
cc (default)28Core memory (remember, recall, reflect, forget, briefing); sessions (session_start, session_end, session_commit, session_status, session_checkpoint); context_pack and context_delta; 8 context-environment tools; 4 chat-thread tools; 4 read-only skills tools
full40Everything in cc, plus associate, statistics, graph_query, audit, chat_thread_decompose, chat_thread_delete, skills_save, and 5 MCP-server registry tools
minimal2remember, recall

Agent-Host Plugins

The Claude Code and OpenCode plugins add session briefings, recall hooks, and pre-compaction transcript capture on top of the MCP server. The Codex plugin connects Codex to MemoryLayer through MCP. The OpenClaw plugin backs OpenClaw’s memory capability directly through the TypeScript SDK. See the Integrations pages.

Server

memorylayer serve runs a FastAPI application on port 61001. The same memorylayer CLI also provides export, import, info, version, and the skills and mcp registry command groups (see CLI). memorylayer-eval is the retrieval evaluation harness.

Key Endpoints

EndpointDescription
POST /v1/memoriesStore a memory
POST /v1/memories/recallHybrid recall
POST /v1/memories/reflectLLM synthesis across memories
POST /v1/memories/batchBatch create, update, and delete
POST /v1/memories/{id}/associateCreate a typed relationship
POST /v1/memories/{id}/traverseGraph traversal from a memory
POST /v1/sessionsCreate a working-memory session
POST /v1/sessions/{id}/commitCommit a session to long-term memory
POST /v1/sessions/{id}/context-packBudgeted resume bundle (sessions)
POST /v1/workspacesCreate a workspace
/v1/entities/*Entity registry
POST /v1/representationPerspective assembly
/v1/graph/*Graph analysis
/v1/knowledgebase/*Knowledge base generation and export
/v1/documents/*, POST /v1/ingest/emailIngestion
/v1/threads/*Chat threads
/v1/skills/*, /v1/mcp-servers/*Skills and MCP registries
/v1/context/*Context environment sandbox
/v1/rpg/*Repository Planning Graph (plugin)

Service Layer

Business logic is organized into focused services. Each is loaded as a plugin through an extension point, and most can be replaced through a MEMORYLAYER_* setting.

ServiceResponsibility
MemoryServiceRemember, recall, and forget. Coordinates embedding, deduplication, storage, user-scope routing, entity accretion, and the post-store enrichment pipeline.
ReflectServiceLLM synthesis over recalled memories, with source citations
SessionServiceWorking-memory lifecycle: create, touch, commit, expire. Persistent by default.
ContextPackServiceCheckpoints, budgeted context packs, and signed delta cursors
WorkspaceServiceWorkspace and context CRUD, export and import, transactional purge
AssociationServiceTyped relationship graph, auto-association, traversal
OntologyService85 base relationship types in 12 categories, memory subtypes, and entity types. Plugins can extend all three.
EntityRegistryServiceCanonical entities, aliases, member accretion, merge, dedup, provenance
EntityLinkerServiceExternal knowledge-base linking (a no-op in core; Wikidata in Enterprise)
EntityRelationServiceTyped entity relations and bounded relational recall
RepresentationServiceObserver/subject perspective and user self-representation
InferenceServiceDerived inference insights about entities
GraphAnalysisService / GraphQueryServiceCommunities, centrality, bridges; entity neighbourhoods
KnowledgebaseServiceKnowledge-base article generation, OKF front matter, coverage
EmbeddingServicePluggable providers: hash (default, lexical), embed_server, openai, google
LLMServicePluggable LLM providers and profiles, gated by the generation policy
ExtractionServiceFact decomposition, classification, and entity extraction
DeduplicationServiceContent-hash and semantic duplicate detection (skip, update, merge, or create)
ContradictionServiceContradiction detection and resolution
SemanticTieringServiceAbstract and overview tiers for progressive detail
DecayServiceImportance decay; pinned memories are exempt
RerankerServiceOptional reranking (none by default) and MMR diversification
CacheServiceRecall-result caching (in-process LRU by default)
DocumentServiceDocument parsing, pages, chunking, ColPali page search
ChatServiceChat threads, ownership, decomposition, and idle policy
SkillsService / McpServersServiceScoped registries with precedence resolution
ContextEnvironmentServiceServer-side Python sandbox and RLM
TaskServiceBackground tasks: enrichment, decomposition, tiering, cleanup, decay

Storage Layer

  • SQLite is the default store (MEMORYLAYER_STORAGE_BACKEND=sqlite). It holds memories, associations, sessions, workspaces, entities, documents, skills, threads, and the rest in a single database file in WAL mode.
  • sqlite-vec provides vector search. When it is unavailable, the server falls back to Python cosine similarity. Embeddings are stored as plain BLOBs, so the schema does not depend on the embedding dimension. Mixing dimensions in one workspace breaks vector search, however: changing the embedding model means re-embedding.
  • FTS5 provides full-text (BM25) search with Porter stemming, including memory aliases.
  • Turso / libSQL is an optional backend (memorylayer-server[turso]) with local, remote, and embedded-replica modes.

Request Flow

Remember (Write Path)

Client
→ REST API (validate, authenticate, authorize)
→ MemoryService.remember()
→ Route scope (workspace, or user → _global_user)
→ Content hash + embedding
→ Deduplication: SKIP · UPDATE · MERGE · CREATE
→ Store (StorageBackend)
→ Entity accretion (if the entity registry is enabled)
→ Post-store enrichment (inline or as background tasks; MEMORYLAYER_POST_STORE_ENRICHMENT_ENABLED):
semantic tiers · contradiction check · auto-association ·
fact decomposition · relationship classification
← Memory

Recall (Read Path)

Client
→ REST API
→ MemoryService.recall()
→ Recall cache
→ Query intent (rule-based: entity / temporal / event / general)
softly tunes recency, alias boosts, graph expansion, date window
→ Candidate channels, fused by Reciprocal Rank Fusion:
vector (sqlite-vec) + keyword (FTS5/BM25) [on]
entity-anchored [on]
fact · graph traversal · cue · registry [off by default]
bounded typed-relation recall [on]
→ Scope, recency, alias, and backlink boosts
→ Association expansion (BFS)
→ Rerank or MMR (optional), truncate to limit
→ Detail level + token budget
→ match_signals, trust, freshness, retrieval_confidence
← RecallResult

llm and hybrid recall modes add LLM query rewriting. agentic is an iterative loop implemented in MemoryLayer Enterprise. See Recall & Retrieval.

Reflect (Synthesis Path)

Client → REST API → ReflectService → recall relevant memories → LLM synthesis → ReflectResult (+ source IDs)

Plugin Architecture

Every service is registered against a named extension point and resolved at startup, based on configuration. For example, MEMORYLAYER_STORAGE_BACKEND=sqlite selects the SQLite storage plugin. MemoryLayer Enterprise uses the same seams to swap in PostgreSQL storage, Redis caching, worker-backed tasks, and its own entity-registry and graph-query backends, without changing application code.

Server plugins are Python packages that register the memorylayer_server.plugin_packages entry point. Installing one is enough: the server scans it and registers its API routers, services, task handlers, and ontology contributions. The RPG plugin (memorylayer-server-rpg) works this way. It adds /v1/rpg, its task handlers, 9 memory subtypes, and 12 code_structure relationship types through an OntologyContributorPlugin.

Semantic Tiers

Each memory can be returned at three detail levels: abstract (a brief summary), overview (a high-level overview), and full (the complete content). Tiers are generated after a memory is stored, and recall and briefings choose a level with detail_level to save context.

Deployment

Local Development

Single process, a single SQLite file, no API key:

Terminal window
pip install memorylayer-server
memorylayer serve

The default hash embedding provider is lexical, not semantic. Add a memorylayer-embed-server peer or a cloud embedding provider for real retrieval quality, or run docker compose up to get the server plus a CPU embed-server peer. The official Docker image ships all optional dependencies and the RPG plugin.

Production

MemoryLayer Enterprise (AGPL-3.0, self-hosted) adds the production substrate: PostgreSQL with pgvector, Apache AGE, and pg_textsearch; a Redis cache; dedicated memorylayer-worker processes; hot/cold memory tiering; data connectors; and tenant, user, and admin services with an admin dashboard. It installs as container images. See Enterprise installation.