Skip to content

Core Concepts

Memory Types

MemoryLayer provides two orthogonal classification systems for memories.

Cognitive Types

Every memory has a cognitive type that describes how it is structured:

TypeDescriptionRetentionExample
EpisodicSpecific events or interactionsDecays over time“User asked about Python logging on Jan 15”
SemanticFacts, concepts, relationshipsPermanent until modified“User prefers TypeScript over JavaScript”
ProceduralHow to do thingsPermanent“To deploy, run npm run deploy”
WorkingCurrent task contextSession-scoped“Currently debugging auth.py line 42”

Domain Subtypes

An optional classification that describes what the memory is about:

SubtypeDescriptionExample
solutionWorking fixes to problems“Fixed CORS by adding allowed origins to middleware”
problemIssues encountered“Auth tokens expire silently without refresh”
code_patternReusable patterns“Use dependency injection for database connections”
fixBug fixes with context“Fixed race condition in user sync by adding mutex”
errorError patterns and resolutions“ECONNREFUSED means Redis isn’t running”
workflowProcess knowledge“Always run migrations before deploying”
preferenceUser or project preferences“Use 2-space indentation in this project”
decisionArchitectural decisions“Chose PostgreSQL over MongoDB for ACID compliance”
profilePerson or entity profiles“Alice is the backend lead, prefers Go”
entityNamed entities (people, places, things)“Project Atlas is the internal data pipeline”
eventSignificant events or milestones“Launched v2.0 on March 15”
directiveUser instructions and constraints“Always use TypeScript strict mode”
inferenceInsights derived from patterns across memories (created by entity derivation)“Alice tends to prefer typed languages”

Importance Scoring

Every memory has an importance score between 0.0 and 1.0 that influences retrieval priority and decay behavior:

Score RangeLevelUse For
0.9–1.0CriticalSecurity fixes, breaking changes, core architecture
0.7–0.8HighBug fixes, API changes, important patterns
0.5–0.6StandardPreferences, general knowledge
0.3–0.4LowObservations, temporary workarounds
0.0–0.2EphemeralDebugging traces, session context

Workspaces

Workspaces provide tenant isolation for memories. Each workspace has its own:

  • Memory store with independent vector indices
  • Relationship graph
  • Session history
  • Configuration and settings

Typical usage: one workspace per project, per user, or per environment.

# All operations are scoped to a workspace
client = MemoryLayerClient(
base_url="http://localhost:61001",
workspace_id="my-project"
)

Sessions

Sessions provide working memory — temporary context that persists within a session and can optionally be committed to long-term storage.

# Start a session
session = await client.create_session(
workspace_id="my-project",
ttl_seconds=3600
)
# Store working memory
await client.set_context(session.id, "current_task", {
"description": "Debugging authentication",
"file": "auth.py"
})
# Later: commit important items to long-term storage
await client.commit_session(session.id, min_importance=0.5)

Associations (Knowledge Graph)

Memories can be linked with typed relationships to form a knowledge graph. This enables multi-hop queries that vector similarity alone cannot answer.

Relationship Categories

Typed relationships organized across categories:

CategoryExample RelationshipsUse Case
Hierarchicalparent_of, child_of, part_of, contains“What is this part of?”
Causalcauses, triggers, leads_to, prevents“What caused this error?”
Temporalprecedes, concurrent_with, follows_temporally“What happened when?”
Similaritysimilar_to, variant_of, related_to“What else is relevant?”
Learningbuilds_on, contradicts, confirms, supersedes“Is this still accurate?”
Refinementrefines, abstracts, specializes, generalizes“How does this relate?”
Referencereferences, referenced_by“What references this?”
Solutionsolves, addresses, alternative_to, improves“What fixes this problem?”
Contextoccurs_in, applies_to, works_with, requires“Where does this apply?”
Workflowfollows, depends_on, enables, blocks“What’s the sequence?”
Qualityeffective_for, preferred_over, deprecated_by“What’s the best approach?”

Example

from memorylayer import RelationshipType
# Link a problem to its solution
await client.associate(
source_id="mem_problem_123",
target_id="mem_solution_456",
relationship=RelationshipType.SOLVES,
strength=0.9
)
# Get associations for a memory
associations = await client.get_associations("mem_problem_123", direction="both")

Context Environment

The Context Environment provides a server-side Python sandbox for working with memories programmatically. It separates the variable space (data in the sandbox) from the token space (what the LLM processes), enabling analysis of large memory sets without consuming the client’s context window.

Key Operations

OperationDescription
LoadLoad memories into sandbox variables via semantic search
ExecuteRun Python code against sandbox data
QueryAsk the server-side LLM using sandbox variables as context
RLMRun an autonomous recursive language model session
InspectView sandbox state (useful after LLM context resets)

Two Reasoning Modes

Classic RLM — The server autonomously orchestrates an iterative loop: generate code → execute → evaluate → repeat until the goal is achieved.

Inverted RLM — The calling LLM (e.g., Claude Code) drives the loop using individual sandbox operations. The sandbox state survives LLM context compaction, allowing the agent to resume analysis after a context reset by calling inspect.

See the Context Environment Guide for detailed usage.

Recall Modes

When searching memories, you can choose a retrieval strategy:

ModeDescription
RAG (default)Hybrid vector + keyword search with optional graph traversal. Fast and needs no LLM.
LLMQuery rewriting plus tiered search. Requires an LLM provider.
HybridRAG first, falling back to LLM retrieval when results are insufficient.
AgenticIterative LLM-controlled expand / re-query / stop loop. Implemented in MemoryLayer Enterprise.

For heavier LLM-driven analysis over many memories, use the Context Environment with RLM.

Core Operations

OperationDescription
RememberStore a new memory
RecallSearch memories by semantic query
ReflectSynthesize insights across memories
ForgetDelete or archive a memory
AssociateLink memories with typed relationships
DecayReduce a memory’s importance over time
TraceGet a memory’s provenance and association chain