Walk the entity graph
Encode a transcript, list the entities the pipeline extracted, and walk the relation graph with /v1/entities and /v1/graph.
Every encode runs the extraction pipeline (pattern → classifier → LLM). When
it sees a name, place, or organization it creates or merges an entity, and
it connects two entities with a typed relation. This structured knowledge is
the typed graph, distinct from the whole-memory recall path.
Reading the typed graph is a wire-client / HTTP-edge capability — it is not on
the strict HTTP-client verb subset. The examples below use the HTTP edge routes
directly (Entities, Graph); the wire client
(BrainClient) exposes the same surface programmatically via listEntities,
traverseRelations, and graphFetch.
Encode a transcript
import { BrainHttpClient } from '@brain-db/sdk';
const brain = new BrainHttpClient({ apiKey: process.env.BRAIN_API_KEY! });
for (const turn of [
'I met with Lina from Globex yesterday at their HQ in Hamburg.',
'Productive meeting. She introduced me to Marco, their CTO.',
]) {
await brain.encode({ text: turn });
}from brain_db_sdk import BrainHttpClient
brain = BrainHttpClient(os.environ['BRAIN_API_KEY'])
for turn in [
'I met with Lina from Globex yesterday at their HQ in Hamburg.',
'Productive meeting. She introduced me to Marco, their CTO.',
]:
brain.encode(turn)Extraction runs asynchronously after the durable ack, so give the pipeline a
moment before reading the graph. It produces entities for Lina, Globex,
Hamburg, and Marco, plus relations such as Lina —brain:works_at→ Globex.
List entities
Filter by name prefix (see GET /v1/entities):
curl -s "$BRAIN_BASE_URL/v1/entities?prefix=Globex&limit=10" \
-H "Authorization: Bearer $BRAIN_API_KEY"{
"entities": [
{
"entity_id": "0a1b2c3d-…",
"entity_type_id": 2,
"canonical_name": "Globex",
"aliases": ["globex"],
"mention_count": 2,
"merged_into": null
}
],
"count": 1
}Walk from an entity
Traverse relations outward from an anchor entity, two hops
(POST /v1/entities/{id}/traverse):
curl -s -X POST "$BRAIN_BASE_URL/v1/entities/0a1b2c3d-…/traverse" \
-H "Authorization: Bearer $BRAIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "direction": "both", "max_depth": 2 }'{
"paths": [
{ "steps": [{ "relation_id": "…", "from": "…lina", "to": "0a1b2c3d-…", "relation_type": "brain:works_at", "depth": 1 }] }
],
"total_paths": 1,
"truncated": false
}Export the whole graph
To render the graph yourself, page the typed-graph export
(GET /v1/graph) — a nodes-and-edges snapshot with keyset
pagination:
curl -s "$BRAIN_BASE_URL/v1/graph?limit=200" \
-H "Authorization: Bearer $BRAIN_API_KEY"{
"nodes": [
{ "id": "0a1b2c3d-…", "kind": "entity", "label": "Globex", "type_qname": "brain:Organization" }
],
"edges": [
{ "from_id": "…lina", "to_id": "0a1b2c3d-…", "kind": "relation", "label": "brain:works_at" }
],
"next_cursor": "9f8e7d6c"
}The entity-graph retriever already walks this graph inside recall — you get
graph-backed hits without touching these endpoints. Reach for the graph
routes when you want to render the graph, not to retrieve.
Entities merge across encodes within a scope — "Globex" mentioned twice is one
entity with mention_count: 2, not two. For isolated graphs per user, isolate
by (namespace, space) scope (see Identity from a JWT),
not by trying to tag memories apart.
The timing that trips this recipe up
Extraction is asynchronous. encode returns at the durability barrier,
before the typed graph exists — so a listing run immediately after a write
comes back empty and looks like extraction failed.
Three ways to deal with it, in order of preference:
Ask for the derived waitwire tierEncodeBuilder(...).wait(WaitMode.Derived) returns only once derivation
has finished. The client applies its 120-second derived-write timeout
instead of the usual 30, because the normal one would fire first.
Watch the feedeither tiersubscribe emits stage events as the pipeline
works, so you can react when extraction lands rather than polling.
Poll the memoryHTTP tierinspect_memory shows exactly what has been
derived so far — an empty artifact.vector means even the embed stage has
not run.
Two reasons a graph comes back empty
Neither is an error, and they look identical from the outside.
No active schema. Nothing in the typed graph can exist outside the schema,
so a space with none extracts no statements, entities or relations at all —
just memories. The wire encode response's hasActiveSchema is how you tell
this apart from a failure, and getSchema is the
check over HTTP.
No LLM credential. The pattern and classifier extractor tiers still run,
but the LLM tier reports that it could not run — so you get entities without
statements rather than a failed write. Check
capabilities for llm_extractor, and the
credential with
verifyLlmCredential.
Brain v1.0 refuses an unfiltered entity listing rather than scanning one.
Get the type ids from getSchema first and list
per type — a bare list call is a rejected request, not an empty result.
Ambiguous resolution is the silent failure
When a surface form could mean two entities, Brain does not pick and does not link. The statement is stored with no entity attached, nothing is logged, and the graph quietly has fewer edges than you expect.
The only signals are
resolveEntity's Ambiguous outcome, and the
brain_extractor_resolver_outcome_total metric. If a transcript's graph looks
sparser than the text warrants, check that counter before tuning anything else.
Was this page helpful?
Tune salience decay
Run the salience-decay worker on a faster cadence for a deployment whose memories go stale quickly — and understand why that changes what recall filters, not how it ranks.
Manual rate-limit backoff
Catch a 429 / 503, honor Retry-After, and retry — taking over from the SDK's built-in auto-retry when you need to.