Skip to main content

Memory

Struct Memory 

Source
pub struct Memory {
Show 26 fields pub id: String, pub tier: Tier, pub namespace: String, pub title: String, pub content: String, pub tags: Vec<String>, pub priority: i32, pub confidence: f64, pub source: String, pub access_count: i64, pub created_at: String, pub updated_at: String, pub last_accessed_at: Option<String>, pub expires_at: Option<String>, pub metadata: Value, pub reflection_depth: i32, pub memory_kind: MemoryKind, pub entity_id: Option<String>, pub persona_version: Option<i32>, pub citations: Vec<Citation>, pub source_uri: Option<String>, pub source_span: Option<SourceSpan>, pub confidence_source: ConfidenceSource, pub confidence_signals: Option<ConfidenceSignals>, pub confidence_decayed_at: Option<String>, pub version: i64,
}

Fields§

§id: String§tier: Tier§namespace: String§title: String§content: String§tags: Vec<String>§priority: i32§confidence: f64

0.0-1.0 — how certain is this memory

§source: String

Who/what created this row. Role-categorical, not vendor-specific. Canonical closed set lives in [crate::validate::VALID_SOURCES] at v0.7.0: user, nhi (crate::validate::DEFAULT_NHI_SOURCE — the vendor-neutral substrate default for AI-NHI-minted writes per #1175), claude (deprecated; back-compat only, removal in v0.8.x), hook, api, cli, import, consolidation, system, chaos, notify (S32 inbox replication path). Validator surface: crate::validate::validate_source.

§access_count: i64§created_at: String§updated_at: String§last_accessed_at: Option<String>§expires_at: Option<String>§metadata: Value§reflection_depth: i32

v0.7.0 Task 1/8 (recursive learning) — depth in the substrate-native reflection recursion tree. 0 for memories minted directly from a caller (or any pre-v0.7.0 row), positive for memories synthesised by the reflection pass over lower-depth peers. Operators can cap recursion depth at write time; readers can filter / sort by it.

#[serde(default)] lets pre-v0.7.0 JSON payloads (and older federation peers) deserialize cleanly — missing → 0, which matches the SQL DEFAULT 0 on the column added in schema v29 (SQLite) / v31 (Postgres).

§memory_kind: MemoryKind

L1-1 (v0.7.0) — typed memory-kind discriminator. Stored in memories.memory_kind TEXT NOT NULL DEFAULT 'observation' (schema v30). Observation for every pre-v30 row (SQL default); Reflection for memories minted by memory_reflect or the curator reflection pass.

#[serde(default)] ensures round-trips with pre-v30 federation peers that don’t yet emit the field.

§entity_id: Option<String>

v0.7.0 QW-2 — populated only when memory_kind == Persona. Identifies the subject of the persona. Stored on the SQL column memories.entity_id TEXT NULL (schema v36). skip_serializing_if = "Option::is_none" keeps the absent shape on the wire for pre-QW-2 federation peers.

§persona_version: Option<i32>

v0.7.0 QW-2 — monotonic per-(entity_id, namespace) version counter for the Persona artefact. Populated only when memory_kind == Persona. Each PersonaGenerator::generate call writes a new row with version + 1; older rows stay queryable for audit / rollback.

§citations: Vec<Citation>

v0.7.0 Form 4 (issue #757) — fact-provenance citations array. Each entry carries a typed Citation envelope (uri, accessed_at, optional hash, optional span). Stored on the memories.citations TEXT column (schema v38) as a JSON-encoded array — legacy rows default to an empty vector via the SQL DEFAULT '[]' clause and the serde default below. Validator surface lives at crate::validate::validate_citation.

NSA CSI MCP Security mapping. Part of the Form 4 fact-provenance triple (citations + source_uri + source_span) that addresses NSA concerns (b) Insecure context or data serialization + (g) Poor or missing audit logs, and contributes to NSA recommendations (c) Validate parameters + (f) Filter and monitor output pipelines per the National Security Agency Cybersecurity Information document on MCP security (U/OO/6030316-26 | PP-26-1834, May 2026 Version 1.0). Capability inventory anchor: form_4_fact_provenance. The mapping is described — without implying NSA endorsement of ai-memory or AlphaOne LLC — at docs/compliance/nsa-csi-mcp.html §3.2 / §3.7 / §4.3 / §4.6.

§source_uri: Option<String>

v0.7.0 Form 4 (issue #757) — first-class URI-form pointer to the cited source body. Distinct from the role-label source column. Accepted schemes: uri: (HTTP URL), doc: (substrate doc id), file: (filesystem path). Validator surface lives at crate::validate::validate_source_uri. Mapped onto the memories.source_uri TEXT column (schema v38). NULL on legacy rows and on rows that do not yet carry a URI form.

§source_span: Option<SourceSpan>

v0.7.0 Form 4 (issue #757) — byte-range into the parent source body. Populated by the WT-1-B atomisation writer for each atom (atom-grain span fact-provenance) and may be set by callers who can pin the offset of a memory inside its referenced source. Mapped onto the memories.source_span TEXT column (schema v38) as a JSON {start, end} envelope. Validator surface lives at crate::validate::validate_source_span.

§confidence_source: ConfidenceSource

v0.7.0 Form 5 (issue #758) — typed discriminator naming the provenance of the confidence value. Stored on memories.confidence_source TEXT NOT NULL DEFAULT 'caller_provided' (schema v39 sqlite / v38 postgres). Defaults to CallerProvided for every legacy row and every write that arrives with the auto-derive engine disabled.

§confidence_signals: Option<ConfidenceSignals>

v0.7.0 Form 5 — JSON snapshot of the signals that produced an auto-derived or calibrated confidence value. Mapped onto memories.confidence_signals TEXT NULL (schema v39 sqlite / v38 postgres). NULL on legacy rows and on rows whose confidence_source = CallerProvided.

§confidence_decayed_at: Option<String>

v0.7.0 Form 5 — RFC3339 stamp of the last decay computation. Mapped onto memories.confidence_decayed_at TEXT NULL (schema v39 sqlite / v38 postgres). NULL on legacy rows and on rows never touched by the decay updater.

§version: i64

v0.7.0 Provenance Gap 1 (issue #884, schema v45 sqlite) — optimistic-concurrency counter. Bumped on every mutation: storage::update AND the (title, namespace) upsert-merge arm of storage::insert (#1632). Two callers writing against the same expected_version race exactly one winner; the loser receives a typed CONFLICT envelope naming the current stored version. The confidence-decay sweep is the only documented non-bumping mutator (tests/non_version_bumping_sites_1036.rs). Legacy rows land at version = 1 via the SQL DEFAULT clause. #[serde(default = "default_memory_version")] keeps pre-v45 federation peers / JSON payloads deserialising cleanly.

Implementations§

Source§

impl Memory

Source

pub const FIELD_COUNT: usize = 26

Total number of declared pub <name>: <type> fields on the Memory struct at v0.7.0. SSOT for the “26-field struct at v0.7.0 (was 15 at v0.6.x)” narrative in CLAUDE.md / README.md / ROADMAP.md / release-notes. Adding or removing a field requires bumping this const in the same commit, OR the parity test pin at tests/memory_field_count_invariant.rs fails the build.

Multi-agent literal-sweep reference: scanner B finding F-B1.x (Memory shape drift), mirrors the MemoryLinkRelation::COUNT + EXPECTED_CLI_SUBCOMMANDS_* drift-blocker pattern landed in commits 960578cfd + 233e8a247.

Source

pub fn effective_expires_at(&self) -> Option<String>

v0.7.0 #1466 — the expires_at value a fresh store must persist. An explicit value the caller supplied wins; otherwise a non-Long row is stamped with created_at + Tier::default_ttl_secs() so it is reapable by GC (expires_at IS NOT NULL AND expires_at < now). Long rows have no TTL and stay immortal (returns None).

Single SSOT for the tier-default backfill across every store backend (SQLite storage::insert + the insert_with_conflict / insert_if_newer / consolidate siblings, and the Postgres store path). Before this, those paths bound expires_at verbatim, so any internal caller that hand-built a mid/short Memory with expires_at: None created an immortal row GC could never collect. The interval comes from Tier::default_ttl_secs() — no hardcoded TTL literal — so it can never drift from the canonical per-tier TTL. Output mirrors the normal store path (to_rfc3339) so the string comparison in gc() stays monotonic; a malformed created_at falls back to now rather than silently dropping the expiry.

Source§

impl Memory

Source

pub fn confidence_tier(&self) -> ConfidenceTier

v0.7.0 Gap 4 (#887) — derived ConfidenceTier for this memory’s confidence value. Stable mapping; see ConfidenceTier::from_confidence for the thresholds.

Trait Implementations§

Source§

impl Clone for Memory

Source§

fn clone(&self) -> Memory

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
Source§

impl Debug for Memory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Memory

Source§

fn default() -> Self

All-zero / empty defaults. Useful as a base for ad-hoc test fixtures — Memory { id: ..., title: ..., ..Default::default() } — and for #[serde(default)] deserialisation of partial JSON. Tier defaults to Mid to match the API-layer default in CreateMemory.

Source§

impl<'de> Deserialize<'de> for Memory

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Memory

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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