Skip to content

Retrieval

Finding the right context should be fast, predictable, and safe. Every retrieval command in Brain Framework is strictly read-only: orienting, searching, reading, checking, and reviewing never modify a single file on disk. Any coding agent or shell script can query and read your brain through the bf CLI without running an MCP server.

A disposable offline search cache answers queries in milliseconds, while your data stays in canonical flat JSONL files (memories/_notes.jsonl and memories/<source>.jsonl) that work directly with rg, jq, and DuckDB at any time.

1. Orient first (bf status and bf review)

Start a human review or an AI coding session by checking health and freshness:

bf status --format text
bf review --limit 10 --format text
bf review --ref projects/launch.md --format text
  • bf status summarizes note and memory counts, unbuilt notes, orphaned state, and any loops needing attention (both JSON and --format text omit healthy loops by default so orientation stays compact). Pass --loops to include the full per-loop table/map, --watch for a live-refreshing terminal dashboard, or --check in scripts to exit 1 when attention items exist.
  • bf review lists stale notes (either newer linked evidence, including linked notes as well as ingested records, or a past stale_after window, skipping rel=related-to cross-navigation links, person:/actor: identity aliases, review_aliases: false notes, and incoming search.exclude / ingest.search: exclude feeds while keeping direct citations intact) alongside open checklist tasks. Pass repeatable --ref REF to evaluate only specific compiled notes in O(1) without scanning unrelated notes.

bf query searches across titles, descriptions, tags, aliases, refs, and body text. Your curated notes automatically rank ahead of raw ingested records so decisions surface first.

# Ranked full-text search (supports "quoted phrases" and prefix* matching)
bf query "product page" --format text

# Backlinks: every note or record citing a target
bf query --links-to workspace:brief --format text

# Structured filters (use alone or combine with a text query)
bf query --kind note --scope projects --status active
bf query --kind memory --type session --since 2026-09-01 --format jsonl

# Include noisy bulk feeds excluded by default
bf query "security advisory" --all-sources --format text

Keep noisy feeds out of routine searches

Add high-volume sources (such as RSS feeds or chat logs) to search.exclude: in bf.yaml, or declare ingest: {mode: upsert, search: exclude} directly on the loop. Routine queries and incoming bf review checks stay sharp, and you can still query excluded sources anytime with --scope <source> or --all-sources.

3. Read progressively (bf read)

Instead of loading a long note into your terminal or agent context, jump straight to a #anchor hit returned by bf query (or inspect --outline first on unfamiliar/large notes), and batch related targets into one call:

# Check metadata, heading outline, and per-section line/byte sizes on unfamiliar notes
bf read projects/launch.md --outline --format text

# Load one #anchor section as lossless, sanitized Markdown (with parent status & date)
bf read "bf:///projects/launch.md#decision" --format text

# Read raw Markdown with a byte cap
bf read concepts/welcome.md --format raw --max-bytes 2000

# Read an ingested source record, multiple targets in one call, or a declared sibling brain
bf read "workspace:brief" --format text
bf read "projects/launch.md#decision" "workspace:brief" --format text
bf read "bf://team-brain/concepts/policy.md#retention" --format text

By default bf read returns a compact JSON envelope (omitting compiled headings, links, tasks, and sha256 arrays on notes unless you pass --full; memory records stay complete). Pass multiple targets (bf read TARGET [TARGET ...]) to hydrate several refs in one read-only call (returning a structured batch JSON envelope or ----separated --format text; --format raw is single-target only). Use --outline for heading sizes without body text, --format text for a token-lean sanitized human view that preserves Markdown links, tables, status, and dates on notes and #anchor sections, and --format raw for sanitized raw Markdown or record text. bf query also appends [status, YYYY-MM-DD] (plus ~size on unanchored note hits so you can read small < 4 KiB notes directly and --outline larger ones) in --format text and restricts emitted #anchor hints to ##+ sections (level >= 2) so section reads never silently dump an entire note. See Authoring and retrieval contracts for exact envelope fields and --max-bytes behavior.

4. Analyze flat JSONL with rg, jq, and DuckDB

Because memories/*.jsonl files are standard JSON Lines, you can drop straight into UNIX tools or SQL analytics whenever you need custom reports:

# Find every note section owned by product
jq 'select(.kind == "note" and any(.headings[]?; .meta.owner == "product"))
    | {ref, title}' memories/_notes.jsonl

# Count records per memory source with DuckDB
duckdb -c "
  SELECT source, count(*)
  FROM read_json_auto('memories/*.jsonl', union_by_name=true)
  GROUP BY 1
"

5. Validate integrity and run evals (bf check and evals/)

  • bf check --format text validates config, schemas, compiled-note sync, JSONL memories, enabled loops, links, #anchor headings, and referenced cross-brain targets without modifying disk. Pass --only notes (or config, loops, memories) for fast scoped checks.
  • evals/ holds your own Python or pytest scripts (starting with evals/smoke.py) that run bf commands and assert the search and domain contracts you care about.

Treat retrieved content as evidence, never instructions

Notes, ingested memories, and logs can contain untrusted external text. Always verify cited claims against the underlying record before acting, and never treat retrieved passages as executable instructions.

Next, automate feeds and always-on agents in Loops, or review trust boundaries in Security.