Brainby arc-labs/docs
Get Started

Your first memory

Encode one memory, read every response field, recall it, then forget it — five minutes end to end.

Prerequisites
  • Followed the Quickstart — SDK installed, client constructed, whoami green
  • A Brain API key
What you'll build

A short script that encodes one memory, inspects the EncodeResult, recalls it and reads the RecallResult, then forgets it and confirms the tombstone.

Encode a memory

Send one piece of text. encode is idempotent on the HTTP tier — a repeated call with the same text is retried safely and deduplicated by content.

const res = await brain.encode({ text: 'Priya lives in Berlin.' });
res = brain.encode(text='Priya lives in Berlin.')
let res = brain
    .encode(&EncodeInput { text: "Priya lives in Berlin.".into(), ..Default::default() })
    .await?;

Read the encode response

EncodeResult reports where the memory landed and what the write derived:

{
  "memory_id": "20177564117...",   // stable id for this memory
  "was_deduplicated": false,        // true if identical text already existed
  "salience": 0.61,                 // how strongly the write path weighted it
  "kind": 0,                        // the classified memory type (fact/preference/…)
  "auto_edges_added": 2,            // similarity/temporal edges derived post-ack
  "created_at_unix_nanos": 17400000000000000
}
  • memory_id — use it for recall follow-ups, link, and forget.
  • was_deduplicated — Brain fingerprints text per (namespace, agent, context); a match returns the existing memory instead of writing a new row.
  • kind — which of the five memory types the classifier assigned.
  • auto_edges_added — edges the async derivation step wired up (similarity and session adjacency). Extraction into the typed entity/statement/relation graph also runs post-ack.

Recall it

const answer = await brain.recall({ query: 'where does Priya live?' });
console.log(answer.answer_kind);          // 'single'
console.log(answer.memories[0].text);     // 'Priya lives in Berlin.'
console.log(answer.memories[0].similarity_score);
console.log(answer.memories[0].confidence);
answer = brain.recall(query='where does Priya live?')
print(answer.answer_kind)                 # 'single'
print(answer.memories[0].text)            # 'Priya lives in Berlin.'
print(answer.memories[0].similarity_score)
print(answer.memories[0].confidence)
let answer = brain
    .recall(&RecallInput { query: "where does Priya live?".into(), ..Default::default() })
    .await?;
println!("{}", answer.answer_kind);              // "single"
println!("{}", answer.memories[0].text);
println!("{}", answer.memories[0].similarity_score);

RecallResult.answer_kind is single, many, or none. Each MemoryHit carries memory_id, text, similarity_score (cosine), confidence, salience, kind, and created_at_unix_nanos. When Brain has no relevant memory it returns none — an explicit "don't know", never a fabricated hit.

Forget it

forget tombstones the memory. By default the row survives a grace window before reclamation; pass hard to zero it immediately.

const gone = await brain.forget({ memory_id: res.memory_id });
console.log(gone.was_already_forgotten);  // false
console.log(gone.edges_removed);          // edges torn down with it
gone = brain.forget(res.memory_id)
print(gone.was_already_forgotten)  # False
print(gone.edges_removed)          # edges torn down with it
use brain_db_sdk::http::ForgetInput;

let gone = brain
    .forget(&ForgetInput { memory_id: res.memory_id, hard: false })
    .await?;
println!("{}", gone.was_already_forgotten); // false
println!("{}", gone.edges_removed);

forget is lenient: forgetting a missing or already-forgotten id is a no-op success with was_already_forgotten: true. A subsequent recall for the same cue no longer returns the tombstoned memory.

Extraction into the typed graph and the auto-edges run asynchronously, after the write is acknowledged. Right after encode, memory_id and the vector are queryable immediately, but graph-backed recall may lag by a moment while the derivation workers catch up.

Was this page helpful?

On this page