Brain Docs

Reference

Rust SDKInstallationHTTP clientWire client
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
Rust SDKRust SDK

Rust SDK

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

PURPOSE

brain-db-sdk is the hand-written Rust 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. Built with BrainHttpClient::new(api_key, base_url) — or ::try_new(...), which validates both arguments — or ::localhost(api_key), then configured with with_timeout and with_retry_policy.

BrainClientWire / BRN0 over TCP

The binary protocol. connect(addr, auth) for defaults, connect_with(addr, config) for full control. Every verb borrows its request, so a retry is the same call with the same borrow.

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

cargo add brain-db-sdk

See Installation for runtime and versioning notes.

Quickstart

use brain_db_sdk::http::{BrainHttpClient, EncodeInput, RecallInput};

let brain = BrainHttpClient::new(
    std::env::var("BRAIN_API_KEY")?,
    std::env::var("BRAIN_BASE_URL").unwrap_or_else(|_| "http://127.0.0.1:8080".into()),
);

brain.encode(&EncodeInput {
    text: "I prefer dark mode and live in Berlin.".into(),
    ..Default::default()
}).await?;

let answer = brain.recall(&RecallInput {
    query: "where does the user live?".into(),
    ..Default::default()
}).await?;
println!("{:?} {:?}", answer.answer_kind, answer.memories.first());

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, encode_vector, memory_list, memory_inspect, graph_fetch, link, unlink
Spaces and sessionsProvision and erase the caller's space, and the sessions inside it.create_space, list_spaces, delete_space, create_session, list_sessions, delete_session
EntitiesThe typed graph's identity layer — resolution, merging, lifecycle.create_entity, get_entity, resolve_entity, list_entities, update_entity, rename_entity, merge_entities, unmerge_entity, tombstone_entity
StatementsTyped claims, their supersession chains, and three ways to retire one.create_statement, get_statement, list_statements, supersede_statement, tombstone_statement, retract_statement, statement_history
RelationsTyped, directed, time-bounded edges between entities, and traversal.create_relation, get_relation, list_relations, traverse_relations, supersede_relation, tombstone_relation
SchemaDeclare the typed graph, and the extractors bound to it.get_schema, validate_schema, upload_schema, replace_schema, drop_schema, list_schemas, list_extractors
ReasoningPlanning, inference, the procedural block, and query introspection.plan, reason, materialize_procedural, query_explain, query_trace
StreamsThe live change feed, and stream cancellation.subscribe, cancel_stream
TransactionsGroup wire writes into one atomic unit.txn_begin, txn_commit, txn_abort
CredentialsRegister and verify the LLM provider key extraction runs on.put_llm_credential, get_llm_credential, test_llm_credential, verify_llm_credential, delete_llm_credential
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?

Pagination

Cursor-based enumeration on the HTTP tier, frame-based streaming on the wire, and the terminator each one uses.

Installation

Add brain-db-sdk to a Cargo project, its runtime requirements, and how to reach each tier.

On this page

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