What to Watch When Brain Goes to Production
Most of what goes wrong with a memory store does not look like an outage. Latency stays flat, the error rate stays at zero, and retrieval quality erodes underneath — extraction starts producing claims the schema rejects, entity resolution starts coming back ambiguous and writing no links at all, a background worker stops and increments no error counter on its way out.
Standard APM cannot see any of that, because none of it is an error. What makes Brain's metrics useful is not a quality score; it is that the pipeline stages each report what they discarded and when they last ran.
What you scrape, and from where
Three endpoints, on the metrics listener — 9091 in the published image,
separate from the wire port. All three are public and unauthenticated: put them
behind your network boundary, not behind a token.
| Endpoint | Meaning |
|---|---|
/healthz | Liveness — the process is up |
/readyz | Readiness — 200 once every shard serves, 503 otherwise |
/metrics | Prometheus exposition, 74 series |
scrape_configs:
- job_name: 'brain'
static_configs:
- targets: ['brain-db:9091']
scrape_interval: 30sWire /healthz to your restart policy and /readyz to load-balancer
membership, and keep them distinct. The difference matters exactly at boot: a
shard replaying a long WAL is alive but not ready, and a liveness probe
that restarts it makes recovery start over from the beginning. That is the one
configuration mistake in this area that turns a slow start into an unbounded
one.
Scrape brain_build_info and brain_config_info too. They carry the running
version and the effective configuration as labels, and "which build is actually
running" is the first question in most incidents and the slowest to answer
without them.
The families, by the question they answer
All 74 series are brain_-prefixed, in sixteen families. These are the ones
worth a dashboard.
Serving
brain_up brain_shards_total
brain_request_total brain_request_duration_ms
brain_request_active brain_connections_total
brain_connections_active brain_connections_closed_total
brain_connections_rejected_total
brain_frame_recv_total brain_frame_send_total
brain_frame_size_bytesbrain_connections_rejected_total rising with no change in traffic usually
means keys are failing to resolve — a revoked credential, or a client pointed
at the wrong deployment. It reads as a client bug and is almost always a
configuration one.
Read path
brain_query_total brain_query_latency_ms
brain_query_outcome_total brain_query_fusion_k
brain_query_rerank_invoked_total
brain_retriever_latency_ms brain_retriever_invocations_total
brain_retriever_candidates_totalbrain_retriever_latency_ms is the one to reach for when recall feels slow: it
breaks out per retriever, so you can see which lane is dragging instead of
guessing from an end-to-end number. Read it beside
brain_retriever_candidates_total — together they tell you whether a lane is
slow because it is doing more work, or doing the same work badly.
brain_query_rerank_invoked_total should sit at zero unless you have turned
the reranker on. It ships disabled.
Storage pressure
brain_arena_slots_used brain_arena_slots_free
brain_arena_used_bytes brain_arena_capacity_bytes
brain_wal_segments brain_wal_size_bytes
brain_metadata_size_bytesArena slots are the thing to alert on early, and early is the operative word: the arena is a fixed-size memory-mapped file, so running out is a wall, not a slope. There is no gradual degradation phase in which you notice and react.
Index health
brain_hnsw_node_count brain_hnsw_tombstone_count brain_hnsw_tombstone_ratiobrain_hnsw_tombstone_ratio climbing and then staying high means maintenance
is not reclaiming deletions. Recall quality degrades before anything errors,
which is the general shape of every real problem on this list.
Background work
Every worker reports through one shared family, labelled by worker:
brain_worker_cycles_total brain_worker_cycle_duration_ms
brain_worker_processed_total brain_worker_pending_work
brain_worker_errors_total brain_worker_panics_total
brain_worker_last_run_unixtimebrain_worker_last_run_unixtime is the most valuable series here. A worker
that stops cleanly leaves errors flat and simply stops incrementing its cycle
counter — so an error-rate alert never fires, and a rate-of-change alert on a
counter that has gone constant is awkward to express. A staleness alert on this
timestamp finds it directly.
The edge-building workers add their own counters — brain_auto_edge_*,
brain_temporal_edge_*, brain_causal_edge_* — each with
_edges_written_total, _drops_total, _skipped_total and a cycle duration.
A rising _drops_total means the worker's channel is full and work is being
shed.
Extraction — including what it costs
brain_extractor_tier_runs_total brain_extractor_items_written_total
brain_extractor_drops_total brain_extractor_apply_dropped_total
brain_extractor_schema_filtered_total brain_extractor_resolver_outcome_total
brain_extractor_predicate_consolidated_total
brain_extractor_llm_micro_usd_spent_total
brain_extractor_cycle_duration_secondsTwo of these answer questions nothing else does, and they are the closest thing Brain has to a quality signal:
brain_extractor_schema_filtered_totalcounts claims extraction produced and the schema rejected. A spike means your schema and your data have drifted apart — the model is extracting things your types do not admit.brain_extractor_resolver_outcome_totalbreaks entity resolution down by outcome, which is where anAmbiguousrate becomes visible. An ambiguous resolution writes no link at all and logs nothing, so this counter is the only signal that a graph is quietly losing its edges.
brain_extractor_llm_micro_usd_spent_total is extraction spend in
micro-dollars. Extraction is the one part of the write path that costs money
per memory, so this is the series to put a budget alert on.
Statement embedding and tracing
brain_statement_embed_cycles_total brain_statement_embed_rows_embedded_total
brain_statement_embed_rows_skipped_total brain_statement_embed_errors_total
brain_statement_embed_batch_duration_seconds
brain_tracing_export_errors_total brain_tracing_spans_dropped_totalLogs and traces
Logs are configured in the engine's TOML, and json is what you want anywhere
you ship them — Loki, Elastic and CloudWatch all ingest it without a parser:
[monitoring.logging]
level = "info"
output = "stdout"
format = "json"Tracing is off by default. There is no trace unless you point it at an OTLP collector, so a deployment that has never been configured for it produces spans for nothing:
[monitoring.tracing]
enabled = true
sampler = "ratio"Watch brain_tracing_spans_dropped_total after you enable it — a collector
that cannot keep up drops spans silently, and a trace with holes in it is worse
than no trace because you reason from the gaps.
Three debugging workflows
"Why did Brain return this memory?"
Ask the recall itself for its trace. There is no explain flag and no
retrieval_detail on a hit — a MemoryHit carries memoryId, text,
similarityScore, confidence, salience, kind and createdAtUnixNanos,
and nothing about how it got there. The reasoning lives in a separate trace:
const answer = await brain.recall({
query: "what does my manager think about the new architecture?",
maxResults: 5,
includeTrace: true,
});
// A JSON STRING, not an object — the trace's ids are 128-bit integers that a
// JSON number would silently round. Parse with a big-integer-safe reader.
const trace = parseWithBigInts(answer.trace!);
// retrievers, the RRF fusion, the filter chain and the rerank passTwo things to know before you turn it on in a hot path. The trace reports
every candidate each lane considered, so it grows with the size of the
space rather than with maxResults — a three-hit recall over roughly 700
memories measured 121 KB. And it is free when off: the server only builds it
when asked, so leave it off by default and switch it on when chasing a bad
answer.
"Why was this memory NOT returned?"
There is no debugRetrieval verb and nothing that takes an
expected_memory_id, so this is two questions asked separately rather than one
call that answers it.
// 1. Does the memory say what you think it says? This is where a bad
// extraction shows up — the vector, the extracted record, the HyPE
// questions and the keyword fields the lexical lane indexes.
const { text, artifact, edges } = await brain.memoryInspect("mem_7A2B");
// 2. What did the read pipeline actually do? The trace lists every candidate
// each lane considered, so a memory that was retrieved-then-filtered looks
// different from one no lane ever surfaced.
const answer = await brain.recall({
query: "what's my manager's communication style?",
includeTrace: true,
});If the id appears in the trace's candidate lists but not in answer.memories,
the filter chain or the relevance band dropped it. If it appears in no lane's
candidates, nothing retrieved it — compare artifact.keywordFields against
your query's vocabulary and artifact.hypeQuestions against its phrasing.
For a structured query rather than a free-text cue, queryExplain and
queryTrace are the real pair. They take the same QueryInput — text,
entityAnchor, kinds, predicates, sessions, timeRange,
asOfRecordTimeUnixNanos, confidenceMin — and differ in whether anything
runs:
const plan = await brain.queryExplain({ text: cue, confidenceMin: 0.5 });
// plan.planText, plan.estimatedCostMs — an ESTIMATE; nothing executed
const ran = await brain.queryTrace({ text: cue, confidenceMin: 0.5 });
// ran.traceText, ran.totalLatencyMs — a MEASUREMENT; the query ranNo suggestion field comes back from any of these. A low similarity for a memory that should be relevant still usually means the query and the memory use different vocabulary for the same concept, and the fix is still either a wider cue or re-encoding the memory with more representative text — you just reach that conclusion from the trace yourself.
"Why is cost spiking?"
There is no costBreakdown verb. Extraction cost is a Prometheus counter,
which is the right shape for it — a time series you can already group, graph
and alert on with the tooling you run:
# micro-dollars spent on extraction LLM calls, per minute
rate(brain_extractor_llm_micro_usd_spent_total[5m]) * 60Read it alongside brain_extractor_tier_runs_total,
brain_extractor_items_written_total and brain_extractor_drops_total, which
together tell you whether the spend is buying anything, and correlate with
brain_request_total for traffic.
The most common causes of a sudden spike:
- Traffic spike — more turns in, more candidates, more extraction calls.
Check
brain_request_totalover the same window. - A write loop —
brain_extractor_tier_runs_totalclimbing whilebrain_extractor_items_written_totalstays flat means you are paying to extract and discarding the result. - Model pricing change — cost per token moved with no change on your side.
- Dropped work being retried —
brain_extractor_drops_totalrising alongside spend.
Alerts worth having
Brain ships no alert rules and no alert channels. It exposes Prometheus metrics; the rules live in your Prometheus or Alertmanager, where your thresholds and your routing already are. These five are the ones that earn their place:
| Alert | Condition | Why it matters |
|---|---|---|
| Shard not serving | /readyz non-200 for more than a minute | A shard has stopped serving |
| Arena nearly full | brain_arena_slots_free below ~10% | A fixed-size mapped file — a wall, not a slope |
| Worker stopped | brain_worker_errors_total rising, or brain_worker_last_run_unixtime going stale | Quality loss long before any error; the second case produces no errors at all |
| Extraction over budget | brain_extractor_llm_micro_usd_spent_total above budget | A runaway write loop is expensive |
| Index not reclaiming | brain_hnsw_tombstone_ratio high and flat | Maintenance is behind; recall degrades silently |
The discipline this adds up to
Every failure mode above is quiet. The arena fills without slowing down. A worker stops without erroring. Extraction and your schema drift apart and the only trace is a counter of rejections. Entity resolution turns ambiguous and writes nothing, logging nothing.
So the useful inversion is not "quality metrics before infrastructure metrics" — Brain publishes no quality score, and a dashboard built on one would be built on a number that does not exist. It is discard counters and staleness timestamps before latency and error rate. What a stage threw away, and when a worker last ran, are the two things that move first.