Skip to content

Workspaces

Workspaces

Workspaces provide tenant isolation for memories. Each workspace has completely independent:

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

Creating Workspaces

workspace = await client.create_workspace("my-project", tags=["knowledge"])
const workspace = await client.createWorkspace("My Project", { default_importance: 0.5 }, ["knowledge"]);

Workspaces are also created implicitly the first time a session or write targets a new workspace ID (MEMORYLAYER_WORKSPACE_IMPLICIT_CREATE, default true). Workspace tags are normalized to lowercase and can be used for discovery.

Using Workspaces

Set the workspace at client initialization:

client = MemoryLayerClient(
base_url="http://localhost:61001",
workspace_id="my-project"
)

All subsequent operations are scoped to that workspace.

The _default Workspace

Every MemoryLayer instance ships with a built-in _default workspace. When no workspace is specified in a request, memories are stored in and recalled from _default. This makes single-project setups zero-configuration — just start the server and begin storing memories.

# No workspace_id specified — uses _default
memory = await client.remember("Project uses FastAPI")

The _global Workspace

The _global workspace is a special cross-workspace shared store. Memories placed in _global are automatically included when recalling from any workspace (unless explicitly excluded). Use it for organization-wide knowledge that should be accessible everywhere:

# Store shared knowledge in _global
await client.remember(
content="Company coding standard: use type hints in all Python code",
workspace_id="_global"
)
# Recall from project workspace — _global memories are included automatically
results = await client.recall(
query="coding standards",
workspace_id="my-project"
)

During recall, memories from different scopes receive locality boosts:

ScopeDefault BoostDescription
Same context1.5xMemories in the same context as the query (MEMORYLAYER_SCOPE_BOOST_SAME_CONTEXT)
Same workspace1.2xMemories in the same workspace (MEMORYLAYER_SCOPE_BOOST_SAME_WORKSPACE)
Global workspace1.0xMemories from _global or _global_user (no boost)

Pass include_global: false on recall to leave _global out.

The _global_user Workspace

_global_user holds user-scoped memories: preferences and traits that follow one user across every workspace. It is partitioned by user_id, so each user only ever sees their own entries. Recall includes them when the request carries a user_id (include_global_user, default true). See Perspective & User Memory.

Workspace Isolation

Memories in different workspaces are completely separate:

Workspace: "frontend-app" Workspace: "backend-api"
├── "Uses React 18" ├── "Uses FastAPI"
├── "Prefers Tailwind CSS" ├── "PostgreSQL for persistence"
└── "Dark mode by default" └── "JWT authentication"

Isolation Patterns

PatternWorkspace StrategyWhen to Use
Per-projectOne workspace per git repositoryTeams working on separate codebases
Per-userOne workspace per user accountPersonal knowledge management
Per-environmentSeparate dev/staging/prod workspacesEnvironment-specific configurations
Per-agentEach agent instance gets its own workspaceMulti-agent systems with independent memory

Per-User Isolation

# Each user gets their own workspace
user_workspace = f"user-{user_id}"
await client.create_workspace(user_workspace)
session = await client.create_session(
workspace_id=user_workspace,
ttl_seconds=3600
)

Per-Environment Isolation

import os
env = os.getenv("ENVIRONMENT", "dev")
workspace_id = f"my-app-{env}" # my-app-dev, my-app-staging, my-app-prod
client = MemoryLayerClient(
base_url="http://localhost:61001",
workspace_id=workspace_id
)

Workspace Settings

A workspace carries a free-form settings dictionary, set with the TypeScript SDK’s createWorkspace(name, settings, tags) or with PUT /v1/workspaces/{workspace_id}:

Terminal window
curl -X PUT http://localhost:61001/v1/workspaces/my-project \
-H "Content-Type: application/json" \
-d '{"settings": {"default_importance": 0.5, "skills_index_references": true}}'

The server stores settings as-is. Most retrieval and retention behaviour is configured server-wide with MEMORYLAYER_* environment variables, not per workspace. The server’s WorkspaceSettings schema documents the recognized keys (default_importance, decay_enabled, decay_rate, session_auto_commit, skills_index_references, and others). Treat per-workspace overrides as advisory unless a feature’s documentation says it reads them.

Workspace Export and Import

Export streams a workspace’s memories and associations as NDJSON (application/x-ndjson): a header line, one memory line per memory, one association line per edge, and a footer with counts.

Terminal window
# Export via REST API (offset, limit, include_associations are optional)
curl http://localhost:61001/v1/workspaces/my-project/export -o workspace-export.ndjson
# Import into another workspace or instance
curl -X POST http://localhost:61001/v1/workspaces/my-project/import \
-H "Content-Type: application/x-ndjson" \
--data-binary @workspace-export.ndjson

The CLI wraps the same endpoints: memorylayer export --workspace my-project -o export.ndjson and memorylayer import export.ndjson --workspace my-project [--dry-run]. The SDKs provide export_workspace / import_workspace (plus streaming variants) in Python and exportWorkspace / importWorkspace in TypeScript.

During import, memories whose content_hash already exists in the target workspace are skipped. See Data Management for the full line format.

Workspace Deletion

Delete a workspace and everything that belongs to it, in one transaction:

Terminal window
curl -X DELETE http://localhost:61001/v1/workspaces/my-project

Auto-Detection (MCP Server)

The MCP server automatically detects the workspace from your project:

  1. Git remote origin URL — extracts repo name
  2. Git root directory name
  3. Current working directory name
~/code/my-app/ → workspace: "my-app"
~/code/api-server/ → workspace: "api-server"

Contexts

A context is a named sub-partition inside a workspace, such as a project area or a conversation. Every workspace has a _default context. Create more with POST /v1/workspaces/{workspace_id}/contexts (list with GET, remove with DELETE .../contexts/{context_id}) and pass context_id on writes, sessions, and recall. Recall gives memories in the caller’s own context the same-context boost.

Workspace Schema

Each workspace has a schema listing the relationship types and memory subtypes it accepts, including any contributed by plugins:

schema = await client.get_workspace_schema("ws_123")
print(schema["relationship_types"]) # Available relationship types
print(schema["memory_subtypes"]) # Available subtypes

Organizing Memories

Within a workspace, use tags for fine-grained classification of memories:

memory = await client.remember(
content="JWT tokens expire after 1 hour",
tags=["auth", "jwt", "security"]
)
# Filter by tags during recall
results = await client.recall(
query="authentication setup",
tags=["auth"]
)

Tags are flexible, per-memory labels that support AND-logic filtering during recall.