Skip to main content

AppState

Struct AppState 

Source
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: bool

Whether 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: Metrics

Prometheus 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

Source

pub fn resolve_allow_labels_from_env() -> bool

Read MNEM_BENCH at startup. See Self::parse_allow_labels for the truthy / falsy string rules.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for AppState

Source§

fn clone(&self) -> AppState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,