Brain Docs

Reference

TypeScript SDKInstallationHTTP clientWire client
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
TypeScript SDKTypeScript SDK

TypeScript SDK

The hand-written TypeScript client for Brain — two clients over one verb vocabulary, and every operation's reference page.

PURPOSE

@brain-db/sdk is the hand-written TypeScript client for the Brain memory database. It re-implements Brain's wire protocol independently — the specification, not a shared library, is the contract — and is verified byte-for-byte against Brain's conformance corpus. This page is the map: 62 operations, each with its own reference page.

Two clients, one vocabulary

OptionTypeDefault / Env
BrainHttpClientHTTP / JSON

Talks JSON to the Brain HTTP edge — brain-edge self-hosted, or the Arc cloud gateway. Covers every data route the edge exposes.

BrainClientWire / BRN0 over TCP

Talks the binary protocol directly to a Brain shard: everything the HTTP client does, plus transactions, act_as, frame-level streaming, ping and stream cancellation — multiplexed over one socket.

The client is flat. There are no namespaced resource objects and no separate query verb: the write verb is encode and the read verb is recall.

Install

npm install @brain-db/sdk

See Installation for runtime and versioning notes.

Quickstart

import { BrainHttpClient } from "@brain-db/sdk/http";

const brain = new BrainHttpClient({
  apiKey: process.env.BRAIN_API_KEY!,
  baseUrl: process.env.BRAIN_BASE_URL, // unset → http://127.0.0.1:8080
});

await brain.encode({ text: "I prefer dark mode and live in Berlin." });

const answer = await brain.recall({ query: "where does the user live?" });
console.log(answer.answerKind, answer.memories[0]?.text);

recall never fabricates: the hit list is empty when Brain has nothing to say.

Every operation

AreaWhat it coversOperations
MemoryThe three verbs, plus the store-level operations and memory edges.encode, recall, forget, encodeVector, memoryList, memoryInspect, graphFetch, link, unlink
Spaces and sessionsProvision and erase the caller's space, and the sessions inside it.createSpace, listSpaces, deleteSpace, createSession, listSessions, deleteSession
EntitiesThe typed graph's identity layer — resolution, merging, lifecycle.createEntity, getEntity, resolveEntity, listEntities, updateEntity, renameEntity, mergeEntities, unmergeEntity, tombstoneEntity
StatementsTyped claims, their supersession chains, and three ways to retire one.createStatement, getStatement, listStatements, supersedeStatement, tombstoneStatement, retractStatement, statementHistory
RelationsTyped, directed, time-bounded edges between entities, and traversal.createRelation, getRelation, listRelations, traverseRelations, supersedeRelation, tombstoneRelation
SchemaDeclare the typed graph, and the extractors bound to it.getSchema, validateSchema, uploadSchema, replaceSchema, dropSchema, listSchemas, listExtractors
ReasoningPlanning, inference, the procedural block, and query introspection.plan, reason, materializeProcedural, queryExplain, queryTrace
StreamsThe live change feed, and stream cancellation.subscribe, cancelStream
TransactionsGroup wire writes into one atomic unit.txnBegin, txnCommit, txnAbort
CredentialsRegister and verify the LLM provider key extraction runs on.putLlmCredential, getLlmCredential, testLlmCredential, verifyLlmCredential, deleteLlmCredential
IntrospectionWho you are, what the server can do, and whether it is alive.whoami, capabilities, ping

Reading the reference

Each operation has one page covering both tiers. Where the two differ — a field name, an extra filter, a frame-level form — the page says so rather than splitting into two near-identical pages.

PageWhat it covers
InstallationInstall, imports, runtime, versioning
HTTP clientConstruction, auth, conventions
Wire clientConnect, config, act_as, multiplexing, pooling
ErrorsBoth taxonomies, the categories and the code families
RetriesWhat retries automatically, and what does not
PaginationCursors and frames
See also
InstallationStart with encodeHow Brain is built

Was this page helpful?

GET /llm/ns/{namespace}/resolve

Resolve which provider and model a namespace's stored credential selects.

Installation

Install @brain-db/sdk, its one dependency, the runtime floor, and how to import each tier.

On this page

Two clients, one vocabularyInstallQuickstartEvery operationReading the reference
Suggest an editOpen in Playground