Brain Docs
Build

Wire it in

Drop it into an existing loopA chatbot that remembersHandling corrections

Production

Alongside your RAGOne space per customerErasing a subject

Working with the API

Error handlingRetries and cancellationIdempotencyStreamingGraph queriesFaithfulness checkingIdentity walkthroughNamespace lifecycle

Reference

Brain/Docs
✦ ASKBrain on GitHubDashboard
BuildGraph queries

Graph queries

When to reach past recall into the typed graph — resolve an entity, read its relations, traverse from an anchor, and export the whole graph.

PURPOSE

Query Brain's typed graph directly — entities, statements, and relations — when you already know the entity and want structured access to its neighbourhood, rather than a free-text recall.

◇Prerequisites
  • A Brain client with credentials.
  • Memories already written that mention named entities (people, orgs, products, places) — the write pipeline extracts the graph from them.
  • Familiarity with Recall and the entities concept.
▸What you'll build

An "entity explorer" that resolves a name to an entity, reads its relations, traverses one or two hops out, and falls back to recall when there is no named entity.

Recall vs the graph — pick correctly

recall answers "what do I know about X?" by fusing semantic, lexical, and entity-graph retrieval over memories. It is your default. The graph endpoints are for when you already have the entity and want structured nodes and edges — for a graph UI, or for an agent that walks relationships programmatically.

QuestionSurface
What do I know about Priya Sharma?POST /v1/recall
Which entity is "Priya"?POST /v1/entities/resolve
What relations touch Priya?GET /v1/entities/{id}/relations
Who does Priya's company connect to, two hops out?POST /v1/entities/{id}/traverse
What claims has anyone made about her, and when?GET /v1/statements
How did one claim change over time?GET /v1/statements/{id}/history
Export the whole graph for a visualisationGET /v1/graph

The typed graph is documented in full under Entities & typed graph and Graph. This guide is the task recipe.

Step-by-step

Names aren't unique. POST /v1/entities/resolve runs the multi-tier resolver and returns an outcome (resolved, created, ambiguous, or not_found) plus the bound entity_id.

curl -X POST "$BRAIN_BASE_URL/v1/entities/resolve" \
  -H "Authorization: Bearer $BRAIN_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{ "candidate_name": "Priya Sharma", "type_hint": 1 }'
{ "outcome": "resolved", "tier": 1, "confidence": 0.97, "entity_id": "0a1b2c3d-…", "candidate_ids": [] }

On ambiguous, candidate_ids holds ranked entity ids to disambiguate between. On the wire client, this is resolveEntity.

GET /v1/entities/{id}/relations lists the relations touching an entity in a direction (from outgoing, to incoming). Each relation carries its type, endpoints, confidence, and bi-temporal validity window.

curl "$BRAIN_BASE_URL/v1/entities/0a1b2c3d-…/relations?direction=from&limit=50" \
  -H "Authorization: Bearer $BRAIN_API_KEY"

To read the facts about the entity (subject–predicate–object), list statements filtered by subject: GET /v1/statements?subject=0a1b2c3d-….

POST /v1/entities/{id}/traverse walks the relation graph from an anchor entity. Depth and node count are bounded server-side (max_depth clamped [1, 5], max_nodes [1, 1000]).

curl -X POST "$BRAIN_BASE_URL/v1/entities/0a1b2c3d-…/traverse" \
  -H "Authorization: Bearer $BRAIN_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{ "direction": "outgoing", "max_depth": 2 }'

The response is { paths, total_paths, truncated }; truncated: true means a bound was hit before the graph was exhausted. On the wire client this is traverseRelations (with traverseRelationsFrames for the streamed form — see Streaming).

For a visualization, GET /v1/graph exports the typed graph as a paginated nodes-and-edges snapshot. Toggle include_memories to add provenance (which memory asserted each edge) and include_statements for value-object nodes.

curl "$BRAIN_BASE_URL/v1/graph?limit=200&include_memories=true" \
  -H "Authorization: Bearer $BRAIN_API_KEY"

Nodes and edges may repeat across pages — dedupe by id. A missing next_cursor means the export is complete. See Graph for the node/edge shapes.

A small decision tree:

  • The cue names a known entity → resolve it, then read its relations or traverse.
  • The cue is free-text with no named entity → recall.
  • You need structured neighbourhood for a UI or an agent walk → the graph endpoints.
  • You just want the answer, entity or not → recall; the entity-graph retriever already contributes to the fused result.

Managing entities over the wire

Explicit typed-graph writes — createEntity, createStatement, createRelation, mergeEntities, uploadSchema — are wire-only; the HTTP client is a read/subset surface for the graph. Typed-graph writes check per-type against the active schema: a create referencing a declared type is accepted, an undeclared type is rejected. Upload your schema first.

const { entityId } = await client.createEntity({
  entityTypeId: 1,
  canonicalName: "Priya Sharma",
  aliases: ["Priya"],
  attributesBlob: new Uint8Array(),
  requestId: newId(),
  actAs: null,
});

See Typed graph for create, resolve, schema upload, traversal, and merge.

Merged and tombstoned entities are excluded from reads by default. When you merge duplicates (mergeEntities), the source becomes an alias of the target and its relations rebind — schedule a periodic dedup pass over GET /v1/entities filtered by type, because drift here silently degrades retrieval quality.

See also
RecallThe default read; the graph is for structured access.Entities APIFull entity / statement / relation reference.Graph APIMemory-graph links and the whole-graph export.Entities conceptTyped nodes, aliases, and edge kinds.

Was this page helpful?

Streaming

Frame streaming on the wire client versus the SSE change feed over HTTP — which answers which question, and how to drain a verb's frames.

Faithfulness checking

Score whether an LLM response is grounded in the memories you recalled, and gate downstream actions on the score — a client-side pattern built on recall.

On this page

Recall vs the graph — pick correctlyStep-by-stepManaging entities over the wire
Suggest an editOpen in Playground