Brain Docs

Reference

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

Entities

The entity graph backing Brain — canonical nouns with a stable EntityId, resolved per tenant, that statements are about and relations connect.

PURPOSE
Brain is a graph as much as it is a memory store. The extractor turns the nouns in your text into entities — canonical identities with a stable EntityId — and the graph retriever walks both directions of that graph: statements about an entity, and statements where the entity appears as an object. Read this before you reach for "I'll just stick everything in a vector store."

The entity graph is what separates Brain from a flat vector index. When the extractor lifts "Priya works at Arc Labs" from a memory, it resolves two entities (Priya, Arc Labs), creating them if they don't exist, and writes a relation between them. Later, "tell me about Priya" can return statements she's the subject of, events about her, and memories where she appears as the object ("I interviewed Priya"). That last category is where flat similarity search fails — Priya isn't the lexical center of "I interviewed Priya," but she's clearly the topic.

Entities are also what make a subject exist at all. Without them, "everything about Priya" is a similarity search against the string "everything about Priya"; with them it is a lookup keyed on an identity, and the difference shows up most on the cases similarity handles worst — a mention that is short, or oblique, or phrased nothing like the query.

The entity record

Getting the four record types apart is most of what makes the graph useful, so it is worth stating explicitly rather than leaving implied.

An entity is the identity of a referent — distinct from the memories that mention it, the statements about it, and the relations that connect it.

struct Entity {
    id: EntityId,               // UUIDv7 — stable across renames, aliases, attribute edits
    namespace_id: NamespaceId,  // owning tenant
    space_id: SpaceId,          // owning space
    entity_type_id: EntityTypeId,
    canonical_name: String,     // normalized display name
    aliases: Vec<String>,       // alternative surface forms
    attributes: EntityAttributes,
    created_at_unix_nanos: u64,
    last_seen_at_unix_nanos: u64,
    tombstoned: bool,
    merged_into: Option<EntityId>,  // Some(id) after a merge — a redirect
}

The EntityId is stable: renames change canonical_name, alias additions extend the list, and attribute updates happen in place — the id never moves. It changes only through a merge, where the merged-away entity's id becomes a redirect.

Stable ids are a contract you can build on

Because the id survives renames, aliases and attribute edits, it is safe to store an EntityId in your own database as a foreign key — a customer row pointing at the entity Brain knows them as. A merge does not break that pointer either: the merged-away id becomes a redirect rather than a dangling reference, so the stored id keeps resolving.

Entity types

entity_type_id is interned from the active schema's type declarations. The seeded brain: system schema ships built-in types; user schemas add deployment-specific ones.

Built-in typeDescription
PersonA named human
OrganizationA company, group, or institution
ProjectA named body of work
PlaceA geographic location or venue
ConceptA topic, idea, or fallback
EventA named occurrence

Concept is the fallback, and worth knowing as such: a mention the classifier can't place lands there rather than being dropped, so an unexpectedly busy Concept population is usually a signal that your schema is missing a type your domain actually uses.

An entity's owning namespace is distinct from the namespace of its type: an entity owned by tenant acme can carry the shared brain:Person type.

The distinction matters more than it looks. Type vocabulary is shared infrastructure — everyone's people are brain:Person — while the entities themselves are tenant-owned rows. Declaring your own types widens the vocabulary without creating a second Person for every tenant that uses it.

Resolution is per tenant

Turning a surface form like "Priya" into an EntityId runs through the resolver gauntlet — exact-name, then alias, then trigram similarity, and (for hard cases) an LLM tier. All of those indexes are keyed under a leading (namespace_id, space_id) scope prefix, so a surface form resolves only against entities the caller's own tenant owns. "Priya Patel" in tenant acme and "Priya Patel" in tenant globex are two separate entities with two separate ids — one tenant's resolution can never reach another's rows.

The four-tier gauntlet

Resolution is a ladder, cheapest first, and the first tier that matches wins:

TierMatchThresholdCatches
1Exact normalised name, or a registered alias—The common case, at trivial cost
2Trigram overlap≥ 0.85Typos, minor surface variation
3Embedding similarity over the entity index≥ 0.78"Acme Inc" ≈ "Acme, Inc."
4LLM tie-break with surrounding textopt-in, default offGenuine ambiguity

Only tier 4 costs a model call, and it is off unless an extractor opts in. The entity HNSW that tier 3 uses exists primarily for this — resolution — rather than for query retrieval.

Three outcomes, and the third is the one to design for

enum ResolutionOutcome {
    Resolved { entity_id, confidence },   // linked to an existing entity
    Created  { entity_id },               // a new entity, created automatically
    Ambiguous { candidates: Vec<EntityId> },
}

Resolved and Created both end with a mention linked to an entity. When all four tiers miss with no ambiguity, the resolver creates rather than discarding — a new noun is not an error.

Ambiguous writes no link at all. The extraction is recorded as skipped with a reason, and no statement or relation is persisted for that mention. The memory is stored and recallable; the structured claim never existed.

Nothing errors on your write path, because resolution runs after the ack. This is the mechanism behind the advice to name the subject in the sentence you write — a bare pronoun gives the gauntlet almost nothing to grip on, and ambiguity is the likely outcome.

Aliases are what let "Priya," "Priya P.," and "Priya Patel" collapse to one entity.

When attributes disagree

A merge has to reconcile two attribute sets, and the rule is conservative: the survivor's values win where both entities carry the same attribute, and the merged entity's values fill gaps where the survivor has none. Its canonical name joins the survivor's alias list, so the surface form that used to resolve to it still resolves — to the survivor now.

Nothing is silently discarded: the audit row records what was merged, by whom, when, and with what confidence, and it is retained indefinitely.

Traversal at retrieval time

The graph retriever operates on the entity graph — entities, relations, and statement subjects — from an anchor entity resolved out of the query. It runs in three modes:

  • Star — anchor → its outgoing/incoming relations → neighbouring entities; returns statements about them and memories that mention them.
  • Path — from entity A to entity B, find connecting paths up to a depth bound; returns the relations and entities along the way.
  • Subgraph — anchor → its k-hop neighbourhood; returns the set of entities, relations, and statements.

Which mode runs is the planner's call from the query's shape, not a flag you set: an anchored question runs star, a "how are these two connected" question runs path, and an exploratory one runs subgraph.

Traversal defaults to depth 3 (capped at 5); one to two hops are O(log N) fast, deeper hops are cost-capped by the planner because cost grows as branching^depth — a three-hop walk from a well-connected entity is the shape that turns a fast query slow. Results carry a proximity score (1 / (hop_distance + 1)) that feeds RRF fusion as one lane among three — see Read pipeline. The two directions aren't symmetric: "what do we know about Priya" (she's the subject) and "where does Priya appear" (she's an object) surface different, both-useful sets.

Merging duplicates

Names drift — "Arc Labs," "Arc Labs Inc.," "ArcLabs" — and the resolver isn't perfect. When two entity rows should be one, a merge collapses them. The survivor becomes canonical; the merged entity's merged_into points at the survivor and its id transparently redirects; every statement and relation that referenced the merged id is re-routed to the survivor, aliases and attributes fold in, and an audit row records the merge. A merge is atomic — every table sees the change or none do — and reversible within a grace window by an unmerge that walks the audit record back. Past the window it is permanent, which is the asymmetry that justifies the confidence bands above: an over-eager merge is expensive to undo, while two entities that should have been one are cheap to fix later.

Merging is gated by confidence, and the middle band is the interesting one

Merging is irreversible in a way an ordinary write is not, so it is banded:

ConfidenceResolver-initiatedOperator-initiated
≥ 0.95Merges autonomously, audit row writtenApplies immediately
0.70 – 0.95Not applied — parked in a review queue as a proposalApplies immediately: the operator is the reviewer
< 0.70Not a candidateRejected as invalid — a caller bug, not a policy call

A machine guess in the middle band neither merges nor vanishes. It is queued with its reason and an evidence summary, bucketed so the strongest proposals surface first.

And it does not wait indefinitely for a human. An ambiguity resolver re-runs resolution against every pending proposal every six hours as evidence accumulates — more statements citing one or the other, new aliases, fresh mentions. Crossing 0.95 promotes it to an automatic merge; dropping below 0.70 dequeues it and both entities stay separate.

That worker is the design idea worth taking away: ambiguity is allowed to remain ambiguous while evidence accumulates. The system is not forced to guess at write time, and it is not forced to interrupt a human either.

Merges are driven either by the resolver (when the auto-merge confidence threshold passes) or by an operator via the ENTITY_MERGE wire op. The entity/statement/relation surface is reachable two ways: directly over the wire protocol (see Typed graph) and over the HTTP edge under /v1/entities, /v1/statements, and /v1/relations (see API: entities).

Relations: the edges between entities

Statements attach a claim to one entity. Relations connect two, and they carry something statements don't — a cardinality declared on the relation type, which drives automatic supersession:

CardinalityAt most one current relation touching…Example
OneToOneeither sidemarried_to
OneToManythe to sideemployed_by
ManyToOnethe from sidereports_to
ManyToManynothing — concurrent relations are validdiscussed_with

So asserting that Priya now reports to Dev closes her previous reports_to automatically, inside the same transaction, linking the chain and leaving the old edge queryable. No second call, and no Preference involved.

Symmetric relations are stored once under a deterministic ordering of the two endpoint ids, while the from- and to-indexes treat the relation as present in both directions — so you read it from either end without the storage carrying two rows that could drift apart.

A relation type interned without a schema never auto-supersedes. Types created implicitly on first write default to ManyToMany with no from/to constraints, so the cardinality that would trigger supersession doesn't exist and a cardinality violation is never raised. Two reports_to edges both stay current.

Declaring the type later preserves its id and starts enforcing on new writes. It does not retroactively close the edges that should have been superseded.

Relation or statement?

The most common modelling question, and both answers are queryable — a wrong call costs ergonomics, not correctness:

Use a Relation when
Use a Statement when
Shape
You're connecting two tracked entities
One entity has a property or claim attached
Query pattern
Graph traversal is common
Filter-by-subject is common
Cardinality
It matters — one employer, one manager
It doesn't
Direction
Bidirectional reads are useful
Unidirectional suffices

The test that settles most cases: would I ever start from the other end? "Who reports to Priya" as well as "who does Bob report to" is a relation. "Priya's timezone" is a statement — nobody asks which people are in CET by walking from the timezone.

Where an entity does not appear

Two absences are worth knowing, because both look like bugs the first time.

A fully isolated entity does not surface in a graph export. The typed-graph export paginates over the subject-anchored statement index and derives the entity set from traversal — statement subjects and objects, plus the relation and mention neighbours of those entities. An entity that nothing says anything about and nothing connects to has no path by which the export reaches it.

Entities are session-agnostic. A person first mentioned in one conversation and again in another is one entity, and the entity view exposes no session at all. The session is recorded as first-mention provenance only. That is deliberate — recording otherwise would fragment identity along a line that is explicitly not a wall.

Statements and relations do carry their session, so listing a session stays coherent across both the memory and the graph.

Why this is the wedge

Without typed entities, "tell me about Priya" is a similarity search against the verbatim string "tell me about Priya" — a flat store returns whatever's lexically closest, possibly a generic biography, possibly nothing. With entities, the retriever resolves the anchor and expands: run the graph lane from Priya, weight subject hits, walk relations one hop for context, and fuse with semantic and lexical search. That's a meaningfully different recall surface, and it exists only because the graph knows what an entity is.

The cost of that surface is the thing to weigh honestly: extraction is asynchronous work on every write, resolution can be ambiguous, and merges need either confidence or a human. A flat index has none of those failure modes because it never attempts the thing they are failure modes of.

See also
Memory types

Fact / Preference / Event statements and how relations encode (subject, predicate, object).

Read pipeline

Where the graph retriever fires and how its ranks fuse.

Namespaces

The (namespace, space) scope that resolution is keyed under.

Typed graph

Create, resolve, get, traverse, relations — the wire verb reference.

API: entities

The same verbs over the HTTP edge — the endpoint reference.

Was this page helpful?

Write pipeline

How encode works — a synchronous fast path (validate → embed → reserve → persist) split from asynchronous derivation by the WAL-fsync acknowledgement barrier.

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.

On this page

The entity recordEntity typesResolution is per tenantThe four-tier gauntletThree outcomes, and the third is the one to design forWhen attributes disagreeTraversal at retrieval timeMerging duplicatesMerging is gated by confidence, and the middle band is the interesting oneRelations: the edges between entitiesRelation or statement?Where an entity does not appearWhy this is the wedge
Suggest an editOpen in Playground