pub struct AppState {
pub repo: Arc<Mutex<ReadonlyRepo>>,
pub embed_cfg: Option<ProviderConfig>,
pub sparse_cfg: Option<ProviderConfig>,
pub indexes: Arc<Mutex<IndexCache>>,
pub allow_labels: bool,
pub metrics: Metrics,
pub push_token: Option<String>,
pub graph_cache: Arc<Mutex<GraphCache>>,
pub traverse_cfg: Arc<TraverseAnswerCfg>,
pub ner_cfg: Option<NerConfig>,
}Expand description
Shared application state passed to every axum handler via
State<AppState>. Clones are cheap (shared Arc).
Fields§
§repo: Arc<Mutex<ReadonlyRepo>>The open repo, held behind a mutex because redb keeps an
exclusive file lock per-process. Writes replace the value
inside the mutex with the post-commit ReadonlyRepo.
embed_cfg: Option<ProviderConfig>Optional embed-provider config resolved from the repo’s
config.toml at startup.
sparse_cfg: Option<ProviderConfig>Optional sparse-provider config resolved from the repo’s
config.toml at startup. When present, POST /v1/nodes and
POST /v1/nodes/bulk auto-populate Node.sparse_embed on
ingest, and /v1/retrieve auto-encodes the query via
SparseEncoder::encode_query so the neural-sparse lane fires
end-to-end.
indexes: Arc<Mutex<IndexCache>>Index cache keyed by commit CID. Fixes audit gap G1: without
this, every /v1/retrieve call rebuilt the vector + sparse
indexes from scratch (O(N) per query). With this, the first
retrieve after a commit pays the build cost; every subsequent
retrieve returns in microseconds.
Invalidation is automatic: any write path that commits also
produces a new head commit CID (via
Transaction::commit -> ReadonlyRepo). The cache sees the
mismatch next time and evicts.
allow_labels: boolWhether the server accepts caller-supplied label values on
ingest and label filters on retrieve. Read from the
MNEM_BENCH environment variable at startup.
Defaults to false. Casual / single-tenant / personal-graph
installations keep label hidden: every ingested node gets
ntype = Node::DEFAULT_NTYPE (“Node”) regardless of what the
caller sent, and retrieve ignores any label filter. No way to
flip this via a CLI flag or request body - operators opt in by
setting MNEM_BENCH=1 at server launch, which is how the
reference benchmark harnesses in this repo pin per-item
isolation. Zero surface area for a regular user to stumble
into label-scoped state.
metrics: MetricsPrometheus metrics registry shared with the /metrics route
and the track_metrics middleware. Clones are cheap (Arc
inside); no per-request allocation.
push_token: Option<String>Bearer token that authorises /remote/v1/push-blocks and
/remote/v1/advance-head. Read from MNEM_HTTP_PUSH_TOKEN
at startup. None means those routes are administratively
disabled (fail-closed): they return 503 regardless of
whatever the caller presented.
The token never touches disk and is never emitted to tracing.
See [crate::auth] for the extractor that enforces the
check.
graph_cache: Arc<Mutex<GraphCache>>C3 FIX-1 + FIX-2: authored-edges adjacency + Leiden community
assignment cache, keyed on the repo’s op-id. Populated lazily
on the first retrieve that asks for community_filter=true or
graph_mode="ppr". Invalidated whenever the op-id changes
(any write path). Single-slot cache: one authored-adjacency
snapshot is shared across requests until the next commit.
traverse_cfg: Arc<TraverseAnswerCfg>Gap 09 - /v1/traverse_answer runtime config. Default OFF per
architect Decision 4; opt in via
[experimental] single_call_multihop = true in the repo’s
config.toml. Wrapped in Arc for cheap clones across handler
dispatch.
ner_cfg: Option<NerConfig>NER provider config resolved from the repo’s config.toml at
startup. When None, ingest paths default to NerConfig::Rule.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn resolve_allow_labels_from_env() -> bool
pub fn resolve_allow_labels_from_env() -> bool
Read MNEM_BENCH at startup. See Self::parse_allow_labels
for the truthy / falsy string rules.
Sourcepub fn resolve_push_token_from_env() -> Option<String>
pub fn resolve_push_token_from_env() -> Option<String>
Read MNEM_HTTP_PUSH_TOKEN at startup. Empty / unset -> None
(writes fail-closed). See [crate::auth::RequireBearer] for the
extractor that enforces the check.
Sourcepub fn parse_allow_labels(val: Option<&str>) -> bool
pub fn parse_allow_labels(val: Option<&str>) -> bool
Pure parser for the MNEM_BENCH value. None (unset) is
false. Falsy strings ("0", "false", "no", "off", empty,
all case-insensitive) are false. Anything else is true.