Brainby arc-labs/docs

recall

Read memories by cue on either client, and branch on the answer_kind membership shape — Single, Many, or None.

Recall by cue

use brain_db_sdk::BrainHttpClient;
use brain_db_sdk::http::RecallInput;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BrainHttpClient::localhost("my-api-key");

    let answer = client
        .recall(&RecallInput {
            query: "where does Ada live?".to_string(),
            max_results: Some(5),
            ..Default::default()
        })
        .await?;

    println!("answer_kind = {}", answer.answer_kind); // "Single" | "Many" | "None"
    for hit in &answer.memories {
        println!("{} ({:.3})", hit.text, hit.similarity_score);
    }
    Ok(())
}
use std::net::SocketAddr;
use brain_db_sdk::{Auth, BrainClient, RecallBuilder};
use brain_db_sdk::wire::types::AnswerKindWire;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr: SocketAddr = "127.0.0.1:9090".parse()?;
    let client = BrainClient::connect(addr, Auth::Token(b"my-token".to_vec())).await?;

    let req = RecallBuilder::new("where does Ada live?").max_results(5).build();
    let answer = client.recall(&req).await?;

    match answer.answer_kind {
        AnswerKindWire::Single => println!("one answer: {}", answer.memories[0].text),
        AnswerKindWire::Many => println!("{} memories", answer.memories.len()),
        AnswerKindWire::None => println!("no memory found"),
    }
    Ok(())
}

The membership shape

recall returns a membership verdict, not a ranked page. The answer_kind field reports which shape the answer took:

answer_kindMeaning
NoneNothing matched. Brain returns an explicit empty answer — it never fabricates one.
SingleExactly one memory answers the cue.
ManySeveral memories are relevant.

Over HTTP answer_kind is a String ("Single" / "Many" / "None"); over the wire it is the AnswerKindWire enum, so you can match on it exhaustively.

Absence is a first-class answer. When Brain has no memory for a cue it returns None with an empty memories list — treat that as "I don't know", not as an error.

Request fields

RecallInput:

ParameterTypeRequired
queryStringoptional

The recall cue. Brain embeds and matches it.

max_resultsOption<u32>optional

Cap on the number of memories returned. Omit for the server default.

subjectOption<String>optional

Pin the recall to a named subject — anchors fact-shaped lookups.

Build with RecallBuilder — it defaults to answering the cue across the agent's own memories with text and edges included:

use brain_db_sdk::RecallBuilder;

let req = RecallBuilder::new("what does Ada prefer?")
    .subject("Ada")            // pin to a named subject
    .max_results(10)           // default is 10
    .confidence_threshold(0.5) // drop low-confidence hits
    .include_graph(true)       // attach typed-graph enrichment
    .trace(true)               // per-stage read trace on the final frame
    .build();
ParameterTypeRequired
subjectStringoptional

Named subject to anchor fact-shaped lookups.

max_resultsu32optional

Result cap. Defaults to 10.

confidence_thresholdf32optional

Drop results below this confidence, in 0.0..=1.0.

include_graphbooloptional

Attach typed-graph enrichment (entities / statements / relations) to each hit.

tracebooloptional

Ask for the per-stage read-pipeline trace on the final frame. Off by default; costs nothing when off.

The result

RecallResult { answer_kind: String, memories: Vec<MemoryHit> }, where each hit is:

pub struct MemoryHit {
    pub memory_id: String,
    pub text: String,
    pub similarity_score: f32,
    pub confidence: f32,
    pub salience: f32,
    pub kind: u8,
    pub created_at_unix_nanos: u64,
}

recall drains the streamed frames into one RecallAnswer:

pub struct RecallAnswer {
    pub answer_kind: AnswerKindWire,
    pub memories: Vec<MemoryResult>,
}

It offers is_empty() and memories() helpers. MemoryResult carries the hit text, similarity_score, confidence, salience, the contributing_retrievers that surfaced it, the fused_score, an optional rerank_score, and — when include_graph was set — a graph enrichment. For the raw streamed frames (cumulative counts, estimated_remaining, the trace), call recall_frames instead.

Was this page helpful?

On this page