Rust SDK
The hand-written Rust client for Brain — two clients over one verb vocabulary, and every operation's reference page.
Two clients, one vocabulary
BrainHttpClientHTTP / JSONTalks 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 TCPThe 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-sdkSee 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
| Area | What it covers | Operations |
|---|---|---|
| Memory | The 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 sessions | Provision and erase the caller's space, and the sessions inside it. | create_space, list_spaces, delete_space, create_session, list_sessions, delete_session |
| Entities | The 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 |
| Statements | Typed claims, their supersession chains, and three ways to retire one. | create_statement, get_statement, list_statements, supersede_statement, tombstone_statement, retract_statement, statement_history |
| Relations | Typed, directed, time-bounded edges between entities, and traversal. | create_relation, get_relation, list_relations, traverse_relations, supersede_relation, tombstone_relation |
| Schema | Declare the typed graph, and the extractors bound to it. | get_schema, validate_schema, upload_schema, replace_schema, drop_schema, list_schemas, list_extractors |
| Reasoning | Planning, inference, the procedural block, and query introspection. | plan, reason, materialize_procedural, query_explain, query_trace |
| Streams | The live change feed, and stream cancellation. | subscribe, cancel_stream |
| Transactions | Group wire writes into one atomic unit. | txn_begin, txn_commit, txn_abort |
| Credentials | Register and verify the LLM provider key extraction runs on. | put_llm_credential, get_llm_credential, test_llm_credential, verify_llm_credential, delete_llm_credential |
| Introspection | Who 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.
| Page | What it covers |
|---|---|
| Installation | Install, imports, runtime, versioning |
| HTTP client | Construction, auth, conventions |
| Wire client | Connect, config, act_as, multiplexing, pooling |
| Errors | Both taxonomies, the categories and the code families |
| Retries | What retries automatically, and what does not |
| Pagination | Cursors and frames |
Was this page helpful?