Brain Docs

Reference

ConceptsArchitectureWrite pipelineEntitiesIdentity by keyNamespaces, spaces and sessionsPolicies
Brain/Docs
✦ ASKBrain on GitHubDashboard
ConceptsNamespaces, spaces and sessions

Namespaces, spaces and sessions

Two isolation axes and one grouping — a namespace is the tenant wall, a space is the isolation unit that scales to a million per org, and a session is explicitly not a boundary.

PURPOSE
Brain has two axes of isolation and one axis of grouping, and conflating them is the dominant failure mode of memory systems. This page is the contract: what each tier is, who sets it, what it guarantees, and the cardinality each is designed for. Read it before you sketch a multi-tenant deployment.

Two axes, not one

The distinction that matters is between who is calling and whose memory this is. They have different cardinalities, different lifetimes, and therefore need different mechanisms:

AxisHow manyLifetimeCarried by
Who is calling — org, product, environmentsmall, 10²–10³long-liveda credential
Whose memory this is — the end userlarge, up to 10⁶ per orgdynamic, churnya per-request partition key

Do not mint a credential per end user. Per-end-user isolation is enforced as a storage-key prefix, not as a credential. A system with a million API keys has turned a data-partitioning problem into a key-management one, and key rotation, revocation and auditing all scale with the wrong number.

The three tiers

namespace  →  space  →  session
 hard wall    hard wall   grouping

Reading that left to right: the credential decides the first, the request decides the second, and the second is where almost all of your cardinality lives.

OptionTypeDefault / Env
namespacehard wall — from the key

The organisation, product or environment. Resolved from the API key at authentication; no request flag can widen a read across namespaces. This is the outer boundary and it is unconditional.

spacehard wall — per request

The isolation unit: one end user, or one purpose. Selected per request through the act_as slot. Also a hard wall — one space's recall never sees another's rows.

sessiongrouping — not a wall

A conversation or run within a space. Explicitly not a security boundary, and deliberately absent from every index scope prefix. Isolation is the space's job; session is ergonomics.

Every stored row — memory, entity, statement, relation — carries an owner scope of (namespace_id, space_id) that is immutable for the row's life. There is no operation that moves a row between scopes: "moving" a memory means encoding it under the destination and forgetting the original.

Why session is not a wall, on purpose

It would be easy to make session a third boundary and it would be wrong. Entities are session-agnostic by design: a person first mentioned in one conversation and again in another is one entity, and recording otherwise would fragment identity along a line that was never meant to be a wall.

Statements and relations do carry the session they were extracted from, so a listed session is coherent across both the memory and the graph. Entities carry it only as first-mention provenance.

How a space id actually works

This is the part most people have to see once.

On the wire a space_id is a structured opaque string — something like support-bot:user123. You choose the convention. The server does not parse it and attaches no meaning to the separator.

At ingress the server derives the 16-byte storage key deterministically:

SpaceId = UUIDv5(namespace, space_string)

Two consequences follow, and both are load-bearing. The derivation folds in the namespace, so the same string under two namespaces produces two different ids — (nsA, "u1") and (nsB, "u1") are disjoint data, not a collision waiting to happen. And a fixed-width 16-byte key keeps every secondary-index prefix compact and range-scannable, which is what makes scope-bounded deletes and sharding work on the id directly.

The derivation seed is pinned by a golden test because changing it re-keys every space in the deployment. That is not a knob; treat the mapping from your string to the storage key as permanent from the first write.

What the isolation actually guarantees

Four properties, enforced structurally rather than by a filter someone remembered to apply:

  1. The namespace filter is unconditional. No request flag widens a read across namespaces, including the namespace-wide recall scope — that spans spaces within your namespace and nothing beyond it.
  2. Every secondary index carries a leading (namespace, space) prefix, so a range scan for one scope can physically never traverse another's rows.
  3. Every id-keyed read re-checks the row's own scope before returning it — defence in depth against a corrupt index key.
  4. A space selector naming a namespace outside the principal's allowlist is hard-rejected with ActAsDenied, never silently downgraded to something that happens to work.

Isolation includes the bill

A subtler guarantee, and one worth knowing because it shapes deployment: a system that keeps one tenant's rows apart but pays for their LLM calls out of another tenant's credential has not isolated them.

So every LLM call — HyPE, the extractor's LLM tier, the entity disambiguator, the summariser, with no privileged exemption — resolves its authority per namespace from the credential broker. There is no shard-wide, deployment-wide or fallback credential.

Brain never accepts a provider API key, from any source, and there is no configuration that supplies one. What it holds is a broker service key — its own identity to the broker — which cannot spend anything upstream.

That is why nothing credential-shaped is ever persisted: not to the log, the metadata store, a snapshot, a backup, the response cache or a diagnostic. The property holds structurally rather than by careful redaction, because a provider key never arrives in the first place. The LLM response cache is keyed by credential scope too, so a completion one tenant paid for is never served to another.

A namespace with no registered credential is a non-fatal case: the write lands, the stages needing an LLM report that they could not run, and the caller is told why.

Creating and deleting spaces

A space exists two ways, and you can use both in one deployment:

  • Implicitly, on first write — zero ceremony. Encode into a space string that has never been seen and it is registered for you.
  • Explicitly — pre-provision it to attach metadata or quota before any traffic arrives.

Listing is namespace-scoped: a caller sees only its own namespace's spaces.

Deleting one is where the behaviour is unusual enough to call out:

SPACE_DELETE is always hard. It zeroes immediately — a sanctioned deviation from the default seven-day tombstone grace, with no soft mode, because a deletion request that leaves the data recoverable for a week has not satisfied the request.

It is scope-prefix bounded, so it costs O(that space's data) rather than a full scan: it range-scans the space's memory timeline and tombstones each memory through the one write path, and each tombstone fans out to the same forget cascade that tears down the backing entity, statement and relation rows. Reusing that machinery rather than writing a second graph teardown is what keeps one code path correct instead of two.

In v1 the cascade is synchronous, so the call's duration scales with the space's size. A very large space delete is not a quick call — plan for it rather than putting it behind a request timeout.

Sessions have the same shape with softer defaults: create implicitly or explicitly, list within one space, and delete with a seven-day grace by default and a hard mode available. The default session is non-deletable — memories encoded without naming one land there.

Sessions in practice

A session is the softest of the three tiers and the one with the most day-to-day consequence, because three mechanisms key off it even though it guards nothing:

  • Content dedup is scoped per (shard, space, session), so the same sentence in two sessions is two memories by design.
  • The surprise term in initial salience is measured against the centroid of recent memories in that session — what counts as novel is session-relative.
  • Consolidation clusters within a session and never across one.

So the guidance is about coherence rather than safety: a session should be one conversation, one task, one ticket. A week of unrelated work in one session makes novelty detection meaningless, because the centroid averages everything. A new session per turn means consolidation never finds five related memories and dedup never catches a repeat.

Statements and relations extracted from a session's memories carry that session id, so listing a session is coherent across both tiers. Entities do not — they carry it only as first-mention provenance, and expose no session at all.

Spaces are indexed separately, and that is the point

The per-user world inverts the assumption most vector stores are built on: millions of spaces with few memories each, rather than one corpus with millions of vectors.

That breaks the obvious implementation. A shared index with a post-hoc scope filter misses a sparse space's own results at high selectivity — the index returns its global top candidates, the filter discards the ones from other spaces, and a space with twelve memories can come back empty even though one of its twelve was the answer.

So a query scoped to a single space routes to a per-space path: an exact brute-force scan over that space's vectors when it's small, or a per-space HNSW when it's large. Never shared-index-with-filter. A space's vectors are given physical locality so a recall touches only them.

This is the mechanism behind a piece of advice that otherwise sounds arbitrary: give each end user their own space rather than tagging their memories inside a shared one. The tag approach is the shared-index-filter path by another name, and it fails in exactly the way described above — silently, and worst for your smallest users.

When no space is named — a namespace-wide analytics or admin read — the shared lower-selectivity path is fine, because there is no sparse scope to miss.

When to draw which boundary

A heuristic: create a namespace when you want a hard tenant wall; create a space when you want an isolated memory, which is most of the time.

  • Per product — two products on Brain, independent corpuses, cross-retrieval would be a bug. Two namespaces.
  • Per customer — each customer its own namespace, so no query can cross a customer boundary. One namespace per customer.
  • Per environment — dev, staging, production are namespaces, not separate deployments.
  • Per end user — a space, never a namespace and never a key. This is the axis built for 10⁶ cardinality.

A worked example

A B2B SaaS product with 400 customers, each with ~2,000 end users:

namespace  acme-prod                    ← one. Your product, in production.
├─ space  "tenant:cust-0001:user-a9f"   ← 800,000 of these
├─ space  "tenant:cust-0001:user-b21"
├─ space  "tenant:cust-0002:user-c7e"
└─ …
     └─ session  per conversation       ← grouping inside a space

One credential for your gateway. One namespace. 800,000 spaces, each a storage-key prefix rather than a row in your identity provider. The customer id inside the space string is your convention — the server treats the whole string as opaque — and it gives you a prefix you can enumerate and delete by.

If a customer demands a harder wall than a space (a contractual data-segregation requirement, say), that is when the customer becomes its own namespace. The cost is a second credential and losing cross-customer reads, which is exactly what they asked for.

Spinning up a namespace per end user fails on both axes at once: you get the key-management problem the warning at the top describes, and you lose the ability to run a namespace-wide read across your own users — because the namespace filter is unconditional and will not span them.

What lives inside the boundary

(namespace, space)
├─ memories        text + 384-dim vector, arena slot, redb row
├─ entities        canonical nouns — id, type, aliases, attributes
├─ statements      Fact / Preference / Event claims about entities
├─ relations       directed edges between entities
├─ edges           SimilarTo / FollowedBy / Caused / … between memories
├─ sessions        groupings within the space
├─ schema          the active type + predicate declarations
└─ audit           the change trail

No cross-space edges exist — relations and memory edges are both space-scoped, so a fully isolated space's data is invisible to every other.

One documented exception to the index-prefix rule is worth knowing rather than discovering: the shared directional edge table is not scope-prefixed and is isolated instead by a sidecar scope re-check after the scan. The guarantee is the same; the mechanism differs, which matters if you are reasoning about whether a scan can physically touch another scope's rows.

Schema is always on

Every shard has an active schema from byte zero: the seeded brain: system namespace. It ships the built-in entity types (Person, Organization, Project, Place, Concept, Event) and system predicates, so extraction, retrieval and indexing run whether or not anyone has declared anything.

Uploading your own declarations merges additively into the active state — byte-equal idempotent, all-or-nothing on conflict. Declarations narrow what an explicit create accepts and which extracted candidates persist: a write naming a declared type is accepted, one naming an undeclared type is rejected (explicit) or dropped (extractor best-effort). They do not gate any retrieval, extraction or index path. The destructive escape hatch — removing or narrowing a declaration — is admin-only and requires an explicit force flag.

Minimal by design

The brain: namespace stays deliberately minimal and seeds no domain attributes. Upload a schema for the types and predicates your product needs rather than expecting Brain to guess them.

The operations that manage them

Spaces and sessions each get a create / list / delete triple, all non-admin and all scoped to the caller's namespace:

OperationSpaceSession
Createimplicit on first write, or explicitimplicit on first write, or explicit
Listthe caller's namespace's spacesone space's sessions
Deletealways hard, scope-boundedsoft by default (7-day grace), hard available

Two asymmetries are deliberate. Listing spaces is namespace-wide while listing sessions is single-space, because a space is the thing you enumerate across and a session is the thing you enumerate within. And deleting a space is always hard while deleting a session is not, because the former is the operation an erasure obligation reaches for and the latter is usually housekeeping.

How this maps onto shards

A request routes to a shard by its effective space, so one tenant's data lands consistently on the same shard and single-writer discipline holds. Under act_as the routing follows the effective identity rather than the connection principal — a gateway serving many tenants over one connection still routes each operation to the right shard.

See also
Identity by keyArchitectureOne space per customerErasing a subject

Was this page helpful?

Identity by key

How API keys carry tenancy in Brain — a key is bound to a (namespace, space, permissions) scope at creation, and the server derives every request's scope from it.

Policies

The knobs Brain exposes — the four enable/disable categories, per-request recall filters, and worker tuning — and where each one applies.

On this page

Two axes, not oneThe three tiersHow a space id actually worksWhat the isolation actually guaranteesIsolation includes the billCreating and deleting spacesSessions in practiceSpaces are indexed separately, and that is the pointWhen to draw which boundaryA worked exampleWhat lives inside the boundarySchema is always onThe operations that manage themHow this maps onto shards
Suggest an editOpen in Playground