pub struct MemoryStore { /* private fields */ }Expand description
Thread-safe handle to the memory database.
Clone is cheap (Arc internals). Send + Sync.
Implementations§
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn create_session(&self, channel: &str) -> Result<String, MemoryError>
pub async fn create_session(&self, channel: &str) -> Result<String, MemoryError>
Create a new conversation session. Returns the session ID (UUID v4).
Sourcepub async fn create_session_with_metadata(
&self,
channel: &str,
metadata: Option<Value>,
) -> Result<String, MemoryError>
pub async fn create_session_with_metadata( &self, channel: &str, metadata: Option<Value>, ) -> Result<String, MemoryError>
Create a new conversation session with metadata.
Metadata can be used to carry namespace tags and trace data for retention and deletion policy decisions.
Sourcepub async fn rename_session(
&self,
session_id: &str,
new_channel: &str,
) -> Result<(), MemoryError>
pub async fn rename_session( &self, session_id: &str, new_channel: &str, ) -> Result<(), MemoryError>
Rename a session’s channel (display name).
Sourcepub async fn list_sessions(
&self,
limit: usize,
offset: usize,
) -> Result<Vec<Session>, MemoryError>
pub async fn list_sessions( &self, limit: usize, offset: usize, ) -> Result<Vec<Session>, MemoryError>
List recent sessions, newest first.
Sourcepub async fn delete_session(&self, session_id: &str) -> Result<(), MemoryError>
pub async fn delete_session(&self, session_id: &str) -> Result<(), MemoryError>
Delete a session and all its messages.
Cleans up HNSW entries for embedded messages before CASCADE delete.
Sourcepub async fn add_message(
&self,
session_id: &str,
role: Role,
content: &str,
token_count: Option<u32>,
metadata: Option<Value>,
) -> Result<i64, MemoryError>
pub async fn add_message( &self, session_id: &str, role: Role, content: &str, token_count: Option<u32>, metadata: Option<Value>, ) -> Result<i64, MemoryError>
Append a message to a session. Returns the message’s auto-increment ID.
Sourcepub async fn add_message_with_trace(
&self,
session_id: &str,
role: Role,
content: &str,
token_count: Option<u32>,
metadata: Option<Value>,
trace_ctx: Option<&TraceCtx>,
) -> Result<i64, MemoryError>
pub async fn add_message_with_trace( &self, session_id: &str, role: Role, content: &str, token_count: Option<u32>, metadata: Option<Value>, trace_ctx: Option<&TraceCtx>, ) -> Result<i64, MemoryError>
Append a message to a session with optional trace metadata.
Sourcepub async fn add_message_fts(
&self,
session_id: &str,
role: Role,
content: &str,
token_count: Option<u32>,
metadata: Option<Value>,
) -> Result<i64, MemoryError>
pub async fn add_message_fts( &self, session_id: &str, role: Role, content: &str, token_count: Option<u32>, metadata: Option<Value>, ) -> Result<i64, MemoryError>
Append a message to a session with FTS indexing but no embedding.
Fallback path when embedding fails: messages still appear in conversation history and are findable via BM25 search, just not via vector search.
Sourcepub async fn add_message_fts_with_trace(
&self,
session_id: &str,
role: Role,
content: &str,
token_count: Option<u32>,
metadata: Option<Value>,
trace_ctx: Option<&TraceCtx>,
) -> Result<i64, MemoryError>
pub async fn add_message_fts_with_trace( &self, session_id: &str, role: Role, content: &str, token_count: Option<u32>, metadata: Option<Value>, trace_ctx: Option<&TraceCtx>, ) -> Result<i64, MemoryError>
Append a message with FTS indexing and optional trace metadata.
Sourcepub async fn get_recent_messages(
&self,
session_id: &str,
limit: usize,
) -> Result<Vec<Message>, MemoryError>
pub async fn get_recent_messages( &self, session_id: &str, limit: usize, ) -> Result<Vec<Message>, MemoryError>
Get the most recent N messages from a session, in chronological order.
Sourcepub async fn get_messages_within_budget(
&self,
session_id: &str,
max_tokens: u32,
) -> Result<Vec<Message>, MemoryError>
pub async fn get_messages_within_budget( &self, session_id: &str, max_tokens: u32, ) -> Result<Vec<Message>, MemoryError>
Get messages from a session up to max_tokens total.
Sourcepub async fn session_token_count(
&self,
session_id: &str,
) -> Result<u64, MemoryError>
pub async fn session_token_count( &self, session_id: &str, ) -> Result<u64, MemoryError>
Get total token count for a session.
Sourcepub async fn add_message_embedded(
&self,
session_id: &str,
role: Role,
content: &str,
token_count: Option<u32>,
metadata: Option<Value>,
) -> Result<i64, MemoryError>
pub async fn add_message_embedded( &self, session_id: &str, role: Role, content: &str, token_count: Option<u32>, metadata: Option<Value>, ) -> Result<i64, MemoryError>
Append a message to a session with automatic embedding and FTS indexing.
Sourcepub async fn add_message_embedded_with_trace(
&self,
session_id: &str,
role: Role,
content: &str,
token_count: Option<u32>,
metadata: Option<Value>,
trace_ctx: Option<&TraceCtx>,
) -> Result<i64, MemoryError>
pub async fn add_message_embedded_with_trace( &self, session_id: &str, role: Role, content: &str, token_count: Option<u32>, metadata: Option<Value>, trace_ctx: Option<&TraceCtx>, ) -> Result<i64, MemoryError>
Append an embedded message with optional trace metadata.
Sourcepub async fn search_conversations(
&self,
query: &str,
top_k: Option<usize>,
session_ids: Option<&[&str]>,
) -> Result<Vec<SearchResult>, MemoryError>
pub async fn search_conversations( &self, query: &str, top_k: Option<usize>, session_ids: Option<&[&str]>, ) -> Result<Vec<SearchResult>, MemoryError>
Hybrid search over conversation messages only.
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn retrieve_evidence(
&self,
request: EvidenceGapRequestV1,
) -> Result<EvidencePacketV1, MemoryError>
pub async fn retrieve_evidence( &self, request: EvidenceGapRequestV1, ) -> Result<EvidencePacketV1, MemoryError>
Retrieve a bounded evidence packet. Every terminal result includes both a state-resolution receipt and a witnessed retrieval envelope at answer level.
pub async fn retrieve_evidence_gap( &self, request: EvidenceGapRequestV1, ) -> Result<EvidencePacketV1, MemoryError>
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn compile_procedure(
&self,
artifact: ProceduralMemoryArtifactV1,
caller_idempotency_key: impl Into<String>,
) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
pub async fn compile_procedure( &self, artifact: ProceduralMemoryArtifactV1, caller_idempotency_key: impl Into<String>, ) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
Compile and persist an immutable procedure version. Invalid input is durably quarantined.
Sourcepub async fn test_procedure(
&self,
artifact_id: &str,
caller_idempotency_key: impl Into<String>,
) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
pub async fn test_procedure( &self, artifact_id: &str, caller_idempotency_key: impl Into<String>, ) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
Run deterministic fixture simulation. No external tool or command is invoked.
pub async fn promote_procedure( &self, permit: ProcedureLifecyclePermitV1, artifact_id: &str, caller_idempotency_key: impl Into<String>, ) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
pub async fn quarantine_procedure( &self, permit: ProcedureLifecyclePermitV1, artifact_id: &str, caller_idempotency_key: impl Into<String>, reason: impl Into<String>, ) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
pub async fn revoke_procedure( &self, permit: ProcedureLifecyclePermitV1, artifact_id: &str, caller_idempotency_key: impl Into<String>, reason: impl Into<String>, ) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
Sourcepub async fn rollback_procedure(
&self,
permit: ProcedureLifecyclePermitV1,
artifact_id: &str,
caller_idempotency_key: impl Into<String>,
reason: impl Into<String>,
) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
pub async fn rollback_procedure( &self, permit: ProcedureLifecyclePermitV1, artifact_id: &str, caller_idempotency_key: impl Into<String>, reason: impl Into<String>, ) -> Result<ProcedureLifecycleReceiptV1, MemoryError>
Roll back an active promotion without mutating or deleting the immutable version.
Sourcepub async fn retrieve_procedure(
&self,
request: ProcedureRetrievalRequestV1,
) -> Result<GovernedProcedureRetrievalV1, MemoryError>
pub async fn retrieve_procedure( &self, request: ProcedureRetrievalRequestV1, ) -> Result<GovernedProcedureRetrievalV1, MemoryError>
Return at most one procedure candidate plus a witnessed fit/authority decision. This function never invokes the procedure or any tool named by it.
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn ingest_document(
&self,
title: &str,
content: &str,
namespace: &str,
source_path: Option<&str>,
metadata: Option<Value>,
) -> Result<String, MemoryError>
pub async fn ingest_document( &self, title: &str, content: &str, namespace: &str, source_path: Option<&str>, metadata: Option<Value>, ) -> Result<String, MemoryError>
Ingest a document: chunk, embed all chunks, store everything.
Sourcepub async fn ingest_document_with_trace(
&self,
title: &str,
content: &str,
namespace: &str,
source_path: Option<&str>,
metadata: Option<Value>,
trace_ctx: Option<&TraceCtx>,
) -> Result<String, MemoryError>
pub async fn ingest_document_with_trace( &self, title: &str, content: &str, namespace: &str, source_path: Option<&str>, metadata: Option<Value>, trace_ctx: Option<&TraceCtx>, ) -> Result<String, MemoryError>
Ingest a document with optional trace metadata.
Sourcepub async fn ingest_chunk_manifest(
&self,
options: ChunkManifestIngestOptions,
entries: Vec<ChunkManifestEntry>,
) -> Result<ChunkManifestIngestResult, MemoryError>
pub async fn ingest_chunk_manifest( &self, options: ChunkManifestIngestOptions, entries: Vec<ChunkManifestEntry>, ) -> Result<ChunkManifestIngestResult, MemoryError>
Ingest an externally chunked document manifest and return exact chunk mappings.
This API preserves semantic-memory as the owner of document/chunk storage and embeddings: callers provide chunk boundaries and external IDs, while semantic-memory generates and stores its own document/chunk IDs atomically.
Sourcepub async fn ingest_chunk_manifest_with_trace(
&self,
options: ChunkManifestIngestOptions,
entries: Vec<ChunkManifestEntry>,
trace_ctx: Option<&TraceCtx>,
) -> Result<ChunkManifestIngestResult, MemoryError>
pub async fn ingest_chunk_manifest_with_trace( &self, options: ChunkManifestIngestOptions, entries: Vec<ChunkManifestEntry>, trace_ctx: Option<&TraceCtx>, ) -> Result<ChunkManifestIngestResult, MemoryError>
Ingest an externally chunked document manifest with optional trace metadata.
Sourcepub async fn delete_document(
&self,
document_id: &str,
) -> Result<(), MemoryError>
pub async fn delete_document( &self, document_id: &str, ) -> Result<(), MemoryError>
Delete a document and all its chunks.
Sourcepub async fn list_documents(
&self,
namespace: &str,
limit: usize,
offset: usize,
) -> Result<Vec<Document>, MemoryError>
pub async fn list_documents( &self, namespace: &str, limit: usize, offset: usize, ) -> Result<Vec<Document>, MemoryError>
List documents in a namespace.
Sourcepub async fn count_chunks_for_document(
&self,
document_id: &str,
) -> Result<usize, MemoryError>
pub async fn count_chunks_for_document( &self, document_id: &str, ) -> Result<usize, MemoryError>
Count the number of chunks for a document.
Sourcepub async fn filter_search_results_by_scope(
&self,
results: Vec<SearchResult>,
scope: &ScopeKey,
) -> Result<Vec<SearchResult>, MemoryError>
pub async fn filter_search_results_by_scope( &self, results: Vec<SearchResult>, scope: &ScopeKey, ) -> Result<Vec<SearchResult>, MemoryError>
Filter search results to those whose source scope exactly matches the requested scope.
Only source families that carry or can be joined to full scope metadata are retained: chunks, episodes, and imported projection rows. Facts and messages are excluded because they do not carry domain/workspace/repo provenance.
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn ingest_episode(
&self,
document_id: &str,
meta: &EpisodeMeta,
) -> Result<String, MemoryError>
pub async fn ingest_episode( &self, document_id: &str, meta: &EpisodeMeta, ) -> Result<String, MemoryError>
Ingest or update a causal episode attached to a document.
The document must already exist. Existing episodes keep their original created_at
timestamp while their searchable text, outcome state, verification metadata, embeddings,
and updated_at are refreshed.
Sourcepub async fn ingest_episode_with_trace(
&self,
document_id: &str,
meta: &EpisodeMeta,
trace_ctx: Option<&TraceCtx>,
) -> Result<String, MemoryError>
pub async fn ingest_episode_with_trace( &self, document_id: &str, meta: &EpisodeMeta, trace_ctx: Option<&TraceCtx>, ) -> Result<String, MemoryError>
Ingest a causal episode with optional trace metadata. Returns the episode_id.
Sourcepub async fn create_episode(
&self,
episode_id: &str,
document_id: &str,
meta: &EpisodeMeta,
) -> Result<String, MemoryError>
pub async fn create_episode( &self, episode_id: &str, document_id: &str, meta: &EpisodeMeta, ) -> Result<String, MemoryError>
Create a new episode with an explicit episode_id. Returns the episode_id.
Sourcepub async fn create_episode_with_trace(
&self,
episode_id: &str,
document_id: &str,
meta: &EpisodeMeta,
trace_ctx: Option<&TraceCtx>,
) -> Result<String, MemoryError>
pub async fn create_episode_with_trace( &self, episode_id: &str, document_id: &str, meta: &EpisodeMeta, trace_ctx: Option<&TraceCtx>, ) -> Result<String, MemoryError>
Create a new episode with an explicit episode_id and optional trace metadata.
Sourcepub async fn get_episode(
&self,
episode_id: &str,
) -> Result<Option<(String, EpisodeMeta)>, MemoryError>
pub async fn get_episode( &self, episode_id: &str, ) -> Result<Option<(String, EpisodeMeta)>, MemoryError>
Retrieve an episode by its episode_id.
Sourcepub async fn update_episode_outcome_by_id(
&self,
episode_id: &str,
outcome: EpisodeOutcome,
confidence: f32,
experiment_id: Option<&str>,
) -> Result<(), MemoryError>
pub async fn update_episode_outcome_by_id( &self, episode_id: &str, outcome: EpisodeOutcome, confidence: f32, experiment_id: Option<&str>, ) -> Result<(), MemoryError>
Update the outcome of an episode by its episode_id.
Sourcepub async fn update_episode_outcome(
&self,
document_id: &str,
outcome: EpisodeOutcome,
confidence: f32,
experiment_id: Option<&str>,
) -> Result<(), MemoryError>
pub async fn update_episode_outcome( &self, document_id: &str, outcome: EpisodeOutcome, confidence: f32, experiment_id: Option<&str>, ) -> Result<(), MemoryError>
Update the outcome of an existing episode.
Sourcepub async fn search_episodes(
&self,
effect_type: Option<&str>,
outcome: Option<&EpisodeOutcome>,
limit: usize,
) -> Result<Vec<(String, EpisodeMeta)>, MemoryError>
pub async fn search_episodes( &self, effect_type: Option<&str>, outcome: Option<&EpisodeOutcome>, limit: usize, ) -> Result<Vec<(String, EpisodeMeta)>, MemoryError>
Search for episodes by effect_type and/or outcome.
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn add_fact_raw_compat(
&self,
namespace: &str,
content: &str,
source: Option<&str>,
metadata: Option<Value>,
trace_ctx: Option<&TraceCtx>,
) -> Result<Fact, MemoryError>
pub async fn add_fact_raw_compat( &self, namespace: &str, content: &str, source: Option<&str>, metadata: Option<Value>, trace_ctx: Option<&TraceCtx>, ) -> Result<Fact, MemoryError>
Explicitly ungoverned compatibility write.
This preserves the pre-authority raw storage API for migrations and local tooling. It does not create an origin label and its output is therefore denied by every governed path.
Sourcepub async fn add_fact(
&self,
namespace: &str,
content: &str,
source: Option<&str>,
metadata: Option<Value>,
) -> Result<String, MemoryError>
pub async fn add_fact( &self, namespace: &str, content: &str, source: Option<&str>, metadata: Option<Value>, ) -> Result<String, MemoryError>
Store a fact with automatic embedding. Returns the fact ID (UUID v4).
This is a non-authoritative storage primitive. Governed mutations must
use MemoryStore::authority so admission and lineage are enforced.
Sourcepub async fn add_fact_with_trace(
&self,
namespace: &str,
content: &str,
source: Option<&str>,
metadata: Option<Value>,
trace_ctx: Option<&TraceCtx>,
) -> Result<String, MemoryError>
pub async fn add_fact_with_trace( &self, namespace: &str, content: &str, source: Option<&str>, metadata: Option<Value>, trace_ctx: Option<&TraceCtx>, ) -> Result<String, MemoryError>
Store a fact with automatic embedding and optional trace metadata.
Sourcepub async fn add_fact_with_embedding(
&self,
namespace: &str,
content: &str,
embedding: &[f32],
source: Option<&str>,
metadata: Option<Value>,
) -> Result<String, MemoryError>
pub async fn add_fact_with_embedding( &self, namespace: &str, content: &str, embedding: &[f32], source: Option<&str>, metadata: Option<Value>, ) -> Result<String, MemoryError>
Store a fact with a pre-computed embedding.
Sourcepub async fn add_fact_with_embedding_and_trace(
&self,
namespace: &str,
content: &str,
embedding: &[f32],
source: Option<&str>,
metadata: Option<Value>,
trace_ctx: Option<&TraceCtx>,
) -> Result<String, MemoryError>
pub async fn add_fact_with_embedding_and_trace( &self, namespace: &str, content: &str, embedding: &[f32], source: Option<&str>, metadata: Option<Value>, trace_ctx: Option<&TraceCtx>, ) -> Result<String, MemoryError>
Store a fact with a pre-computed embedding and optional trace metadata.
Sourcepub async fn delete_namespace(
&self,
namespace: &str,
) -> Result<NamespaceDeleteReport, MemoryError>
pub async fn delete_namespace( &self, namespace: &str, ) -> Result<NamespaceDeleteReport, MemoryError>
Delete all memory in a namespace and return a per-surface report.
Sourcepub async fn get_fact(&self, fact_id: &str) -> Result<Option<Fact>, MemoryError>
pub async fn get_fact(&self, fact_id: &str) -> Result<Option<Fact>, MemoryError>
Get a fact by ID.
Sourcepub async fn get_fact_raw_compat(
&self,
fact_id: &str,
) -> Result<Option<Fact>, MemoryError>
pub async fn get_fact_raw_compat( &self, fact_id: &str, ) -> Result<Option<Fact>, MemoryError>
Explicitly ungoverned compatibility read. Prefer authority().get_fact_governed.
Sourcepub async fn get_fact_embedding(
&self,
fact_id: &str,
) -> Result<Option<Vec<f32>>, MemoryError>
pub async fn get_fact_embedding( &self, fact_id: &str, ) -> Result<Option<Vec<f32>>, MemoryError>
Get a fact’s embedding vector.
Sourcepub async fn list_facts(
&self,
namespace: &str,
limit: usize,
offset: usize,
) -> Result<Vec<Fact>, MemoryError>
pub async fn list_facts( &self, namespace: &str, limit: usize, offset: usize, ) -> Result<Vec<Fact>, MemoryError>
List all facts in a namespace using the default Current view.
Sourcepub async fn list_facts_with_view(
&self,
namespace: &str,
limit: usize,
offset: usize,
view: StateView,
) -> Result<Vec<Fact>, MemoryError>
pub async fn list_facts_with_view( &self, namespace: &str, limit: usize, offset: usize, view: StateView, ) -> Result<Vec<Fact>, MemoryError>
List facts under an explicit bitemporal authority-state view.
Sourcepub async fn list_fact_namespaces(&self) -> Result<Vec<String>, MemoryError>
pub async fn list_fact_namespaces(&self) -> Result<Vec<String>, MemoryError>
List the distinct namespaces that currently contain facts.
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn invalidate_derivations(
&self,
source_kind: &str,
source_id: &str,
trigger_mode: &str,
reason: &str,
) -> Result<usize, MemoryError>
pub async fn invalidate_derivations( &self, source_kind: &str, source_id: &str, trigger_mode: &str, reason: &str, ) -> Result<usize, MemoryError>
Invalidate derivation edges matching a trigger mode, bounded by source artifact.
Returns the number of edges invalidated. This enables bounded recomputation: only derived artifacts downstream of the specified source are affected.
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn import_projection_batch<B: ProjectionImportBatchLike>(
&self,
batch: &B,
) -> Result<ProjectionImportResult, MemoryError>
pub async fn import_projection_batch<B: ProjectionImportBatchLike>( &self, batch: &B, ) -> Result<ProjectionImportResult, MemoryError>
Import a projection batch from forge-memory-bridge.
This is the canonical in-process import path for the stack:
ExportEnvelopeV3 -> transform_envelope_v3() -> ProjectionImportBatchV3 -> semantic-memory import transaction.
V2 remains supported as a compatibility-normalized import batch shape.
The old import_envelope() method remains functional only during the
migration cycle. JSON parsing is retained only via
import_projection_batch_json_compat().
Sourcepub async fn import_projection_batch_json_compat(
&self,
batch_json: &str,
) -> Result<ProjectionImportResult, MemoryError>
pub async fn import_projection_batch_json_compat( &self, batch_json: &str, ) -> Result<ProjectionImportResult, MemoryError>
Deserialize and import a projection batch from JSON.
This is a compatibility boundary for callers that still cross the
in-process seam as serialized JSON. New code should pass
ProjectionImportBatchV3 directly to import_projection_batch().
Sourcepub async fn query_projection_imports(
&self,
scope_namespace: Option<&str>,
limit: usize,
) -> Result<Vec<ProjectionImportLogEntry>, MemoryError>
pub async fn query_projection_imports( &self, scope_namespace: Option<&str>, limit: usize, ) -> Result<Vec<ProjectionImportLogEntry>, MemoryError>
Query the V11 projection import log.
Sourcepub async fn latest_rebuildable_kernel_projection_import_for_scope(
&self,
scope_key: &ScopeKey,
) -> Result<Option<ProjectionImportLogEntry>, MemoryError>
pub async fn latest_rebuildable_kernel_projection_import_for_scope( &self, scope_key: &ScopeKey, ) -> Result<Option<ProjectionImportLogEntry>, MemoryError>
Return the most recent exact-scope import receipt carrying a rebuildable kernel V3 batch.
Sourcepub async fn query_projection_import_failures(
&self,
scope_namespace: Option<&str>,
limit: usize,
) -> Result<Vec<ProjectionImportFailureReceiptEntry>, MemoryError>
pub async fn query_projection_import_failures( &self, scope_namespace: Option<&str>, limit: usize, ) -> Result<Vec<ProjectionImportFailureReceiptEntry>, MemoryError>
Query durable failed projection import receipts.
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn submit_shadow_policy_proposal(
&self,
proposal: ShadowPolicyProposalV1,
) -> Result<ShadowPolicyProposalV1, MemoryError>
pub async fn submit_shadow_policy_proposal( &self, proposal: ShadowPolicyProposalV1, ) -> Result<ShadowPolicyProposalV1, MemoryError>
Append a proposal to the shadow ledger. This method cannot write facts, authority state, active policy, or any runtime configuration.
pub async fn get_shadow_policy_proposal( &self, proposal_id: &str, principal: &str, ) -> Result<Option<ShadowPolicyProposalV1>, MemoryError>
pub async fn get_shadow_policy_promotion_receipt( &self, caller_idempotency_key: &str, principal: &str, ) -> Result<Option<PromotionDecisionReceiptV1>, MemoryError>
pub async fn list_shadow_policy_proposals( &self, principal: &str, policy_kind: Option<ShadowPolicyKindV1>, ) -> Result<Vec<ShadowPolicyProposalV1>, MemoryError>
Sourcepub async fn promote_shadow_policy(
&self,
permit: ShadowPolicyPromotionPermitV1,
caller_idempotency_key: impl Into<String>,
proposal_id: impl Into<String>,
evidence: PromotionEvidenceV1,
) -> Result<PromotionDecisionReceiptV1, MemoryError>
pub async fn promote_shadow_policy( &self, permit: ShadowPolicyPromotionPermitV1, caller_idempotency_key: impl Into<String>, proposal_id: impl Into<String>, evidence: PromotionEvidenceV1, ) -> Result<PromotionDecisionReceiptV1, MemoryError>
Gate and, if admitted, atomically version active policy and emit its receipt.
pub async fn get_active_shadow_policy( &self, principal: &str, policy_kind: ShadowPolicyKindV1, ) -> Result<Option<ActiveShadowPolicyV1>, MemoryError>
pub async fn rollback_shadow_policy( &self, permit: ShadowPolicyPromotionPermitV1, caller_idempotency_key: impl Into<String>, principal: impl Into<String>, policy_kind: ShadowPolicyKindV1, target_version: u64, ) -> Result<PromotionDecisionReceiptV1, MemoryError>
Source§impl MemoryStore
impl MemoryStore
Sourcepub async fn resolve_memory(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
mode: StateResolutionMode,
budget: usize,
) -> Result<ResolvedMemoryAnswerV1, MemoryError>
pub async fn resolve_memory( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, mode: StateResolutionMode, budget: usize, ) -> Result<ResolvedMemoryAnswerV1, MemoryError>
Resolve a query against the existing search/state/graph APIs and return a state-labeled answer with a non-optional resolution receipt.
Sourcepub async fn add_state_dependency_edge(
&self,
edge: StateDependencyEdgeV1,
weight: f64,
) -> Result<StoredGraphEdge, MemoryError>
pub async fn add_state_dependency_edge( &self, edge: StateDependencyEdgeV1, weight: f64, ) -> Result<StoredGraphEdge, MemoryError>
Persist typed state-dependency relationships through the existing graph store.
Source§impl MemoryStore
impl MemoryStore
Return the capability-gated, append-only authority mutation surface.
Sourcepub fn open(config: MemoryConfig) -> Result<Self, MemoryError>
pub fn open(config: MemoryConfig) -> Result<Self, MemoryError>
Open or create a memory store at the configured base directory.
Creates the directory if it doesn’t exist, opens/creates SQLite, runs migrations, and initializes the HNSW index.
When the candle-embedder feature is enabled, this defaults to
[CandleEmbedder] (in-process, pure-Rust, no Ollama required).
Otherwise it defaults to OllamaEmbedder.
Sourcepub fn open_with_embedder(
config: MemoryConfig,
embedder: Box<dyn Embedder>,
) -> Result<Self, MemoryError>
pub fn open_with_embedder( config: MemoryConfig, embedder: Box<dyn Embedder>, ) -> Result<Self, MemoryError>
Open with a custom embedder (for testing or non-Ollama providers).
Sourcepub async fn verify_integrity(
&self,
mode: VerifyMode,
) -> Result<IntegrityReport, MemoryError>
pub async fn verify_integrity( &self, mode: VerifyMode, ) -> Result<IntegrityReport, MemoryError>
Verify database integrity.
In Quick mode, checks table existence and row counts.
In Full mode, also verifies FTS consistency and runs SQLite integrity_check.
Sourcepub async fn reconcile(
&self,
action: ReconcileAction,
) -> Result<IntegrityReport, MemoryError>
pub async fn reconcile( &self, action: ReconcileAction, ) -> Result<IntegrityReport, MemoryError>
Reconcile detected integrity issues.
ReportOnly: no-op, just returns the integrity report.RebuildFts: rebuilds all FTS indexes from source data.ReEmbed: re-embeds authoritative rows and then verifies integrity.
Sourcepub fn config(&self) -> &MemoryConfig
pub fn config(&self) -> &MemoryConfig
Get the current configuration.
Sourcepub fn graph_view(&self) -> Arc<dyn GraphView>
pub fn graph_view(&self) -> Arc<dyn GraphView>
View the store as a derived graph over documents, chunks, facts, sessions, messages, episodes, namespaces, semantic similarity edges, and first-class stored graph edges.
Sourcepub async fn add_graph_edge(
&self,
source: &str,
target: &str,
edge_type: GraphEdgeType,
weight: f64,
metadata: Option<Value>,
) -> Result<StoredGraphEdge, MemoryError>
pub async fn add_graph_edge( &self, source: &str, target: &str, edge_type: GraphEdgeType, weight: f64, metadata: Option<Value>, ) -> Result<StoredGraphEdge, MemoryError>
Add a durable, typed graph edge between two nodes.
Nodes are identified by prefixed IDs (e.g. fact:<uuid>,
namespace:<name>, document:<id>). The edge type must be one of
GraphEdgeType::Semantic, Temporal, Causal, or Entity.
Insertion is idempotent on content digest — inserting the same edge twice returns the existing edge without creating a duplicate.
Returns the stored edge including its assigned ID and recorded_at timestamp.
Sourcepub async fn add_graph_edge_at(
&self,
source: &str,
target: &str,
edge_type: GraphEdgeType,
weight: f64,
metadata: Option<Value>,
valid_time: &str,
recorded_time: &str,
) -> Result<StoredGraphEdge, MemoryError>
pub async fn add_graph_edge_at( &self, source: &str, target: &str, edge_type: GraphEdgeType, weight: f64, metadata: Option<Value>, valid_time: &str, recorded_time: &str, ) -> Result<StoredGraphEdge, MemoryError>
Add a durable graph edge with explicit bitemporal timestamps.
Use this when importing or correcting historical relationships where domain validity and system record time differ from the current wall clock.
Sourcepub async fn consolidate_facts(
&self,
keep_id: &str,
supersede_id: &str,
merged_content: &str,
) -> Result<(), MemoryError>
pub async fn consolidate_facts( &self, keep_id: &str, supersede_id: &str, merged_content: &str, ) -> Result<(), MemoryError>
Atomically consolidate two facts into one.
Updates the kept fact with merged content and adds a supersession edge from the kept fact to the superseded fact, all in one SQLite transaction. No duplicate fact is created.
Sourcepub async fn list_graph_edges_for_node(
&self,
node_id: &str,
) -> Result<Vec<StoredGraphEdge>, MemoryError>
pub async fn list_graph_edges_for_node( &self, node_id: &str, ) -> Result<Vec<StoredGraphEdge>, MemoryError>
List all stored graph edges involving a given node (as source or target), excluding invalidated edges.
Sourcepub async fn list_graph_edges_for_node_as_of(
&self,
node_id: &str,
as_of_valid_time: &str,
as_of_recorded_time: &str,
) -> Result<Vec<StoredGraphEdge>, MemoryError>
pub async fn list_graph_edges_for_node_as_of( &self, node_id: &str, as_of_valid_time: &str, as_of_recorded_time: &str, ) -> Result<Vec<StoredGraphEdge>, MemoryError>
List graph edges involving a node as of explicit bitemporal cutoffs.
as_of_valid_time is domain/business time; as_of_recorded_time is
system knowledge time. This is the graph analogue of bitemporal as-of
fact queries: it can reconstruct what the relationship graph knew at a
prior recorded time, including edges invalidated later.
Sourcepub async fn list_all_graph_edges(
&self,
) -> Result<Vec<StoredGraphEdge>, MemoryError>
pub async fn list_all_graph_edges( &self, ) -> Result<Vec<StoredGraphEdge>, MemoryError>
List ALL stored graph edges, excluding invalidated ones.
Sourcepub async fn list_graph_edges_for_neighborhood(
&self,
seed_ids: Vec<String>,
max_hops: usize,
max_nodes: usize,
) -> Result<Vec<StoredGraphEdge>, MemoryError>
pub async fn list_graph_edges_for_neighborhood( &self, seed_ids: Vec<String>, max_hops: usize, max_nodes: usize, ) -> Result<Vec<StoredGraphEdge>, MemoryError>
List graph edges within N hops of the given seed node IDs.
Performs a BFS expansion from the seeds, loading only edges in
the local neighborhood. Much faster than list_all_graph_edges
when you only need the subgraph around search results.
seed_ids: starting node IDs (typically search result IDs)max_hops: BFS depth (1 = direct neighbors, 2 = neighbors of neighbors)max_nodes: cap on total nodes visited (prevents hub explosion)
Sourcepub async fn invalidate_graph_edge(
&self,
edge_id: &str,
reason: &str,
) -> Result<(), MemoryError>
pub async fn invalidate_graph_edge( &self, edge_id: &str, reason: &str, ) -> Result<(), MemoryError>
Invalidate a stored graph edge by ID. Append-only — the row is never deleted.
Sourcepub async fn count_graph_edges(&self) -> Result<usize, MemoryError>
pub async fn count_graph_edges(&self) -> Result<usize, MemoryError>
Count non-invalidated stored graph edges.
Sourcepub async fn search(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
) -> Result<Vec<SearchResult>, MemoryError>
pub async fn search( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, ) -> Result<Vec<SearchResult>, MemoryError>
Hybrid search across facts, document chunks, and searchable episodes.
Sourcepub async fn search_with_context(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
context: SearchContext,
) -> Result<SearchResponse, MemoryError>
pub async fn search_with_context( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, context: SearchContext, ) -> Result<SearchResponse, MemoryError>
Hybrid search with an explicit deterministic context and optional receipt.
Sourcepub async fn search_with_view(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
view: StateView,
) -> Result<Vec<SearchResult>, MemoryError>
pub async fn search_with_view( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, view: StateView, ) -> Result<Vec<SearchResult>, MemoryError>
Hybrid fact search under an explicit authority-state view.
Sourcepub async fn search_fts_only(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
) -> Result<Vec<SearchResult>, MemoryError>
pub async fn search_fts_only( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, ) -> Result<Vec<SearchResult>, MemoryError>
Full-text search only (no embeddings needed).
Sourcepub async fn search_fts_only_with_context(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
context: SearchContext,
) -> Result<SearchResponse, MemoryError>
pub async fn search_fts_only_with_context( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, context: SearchContext, ) -> Result<SearchResponse, MemoryError>
Full-text-only search with an explicit deterministic context and optional receipt.
Sourcepub async fn search_vector_only(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
) -> Result<Vec<SearchResult>, MemoryError>
pub async fn search_vector_only( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, ) -> Result<Vec<SearchResult>, MemoryError>
Vector similarity search only (no FTS).
Sourcepub async fn search_vector_only_with_context(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
context: SearchContext,
) -> Result<SearchResponse, MemoryError>
pub async fn search_vector_only_with_context( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, context: SearchContext, ) -> Result<SearchResponse, MemoryError>
Vector similarity search with an explicit deterministic context and optional receipt.
Sourcepub async fn search_explained(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
) -> Result<Vec<ExplainedResult>, MemoryError>
pub async fn search_explained( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, ) -> Result<Vec<ExplainedResult>, MemoryError>
Search with full score breakdown for each result.
Sourcepub async fn search_explained_with_context(
&self,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
context: SearchContext,
) -> Result<ExplainedSearchResponse, MemoryError>
pub async fn search_explained_with_context( &self, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, context: SearchContext, ) -> Result<ExplainedSearchResponse, MemoryError>
Search with full score breakdown under an explicit deterministic context.
Sourcepub async fn get_search_receipt(
&self,
receipt_id: &str,
) -> Result<Option<VectorSearchReceiptV1>, MemoryError>
pub async fn get_search_receipt( &self, receipt_id: &str, ) -> Result<Option<VectorSearchReceiptV1>, MemoryError>
Load a durable search receipt by receipt/request ID.
Sourcepub async fn search_replay_inputs_available(
&self,
receipt_id: &str,
) -> Result<bool, MemoryError>
pub async fn search_replay_inputs_available( &self, receipt_id: &str, ) -> Result<bool, MemoryError>
Return whether a durable receipt has opt-in inputs for complete replay.
Sourcepub async fn replay_search_from_stored_inputs(
&self,
receipt_id: &str,
) -> Result<SearchReplayReportV1, MemoryError>
pub async fn replay_search_from_stored_inputs( &self, receipt_id: &str, ) -> Result<SearchReplayReportV1, MemoryError>
Replay a durable receipt using its opt-in stored query and filters.
Sourcepub async fn replay_search_receipt(
&self,
receipt_id: &str,
query: &str,
top_k: Option<usize>,
namespaces: Option<&[&str]>,
source_types: Option<&[SearchSourceType]>,
) -> Result<SearchReplayReportV1, MemoryError>
pub async fn replay_search_receipt( &self, receipt_id: &str, query: &str, top_k: Option<usize>, namespaces: Option<&[&str]>, source_types: Option<&[SearchSourceType]>, ) -> Result<SearchReplayReportV1, MemoryError>
Replay a durable search receipt with caller-supplied query text and filters.
Receipts intentionally do not store query text or filter values. The caller supplies those inputs, and the stored receipt supplies the deterministic evaluation time and retrieval family for comparison.
Sourcepub async fn embedding_displacement(
&self,
text_a: &str,
text_b: &str,
) -> Result<EmbeddingDisplacement, MemoryError>
pub async fn embedding_displacement( &self, text_a: &str, text_b: &str, ) -> Result<EmbeddingDisplacement, MemoryError>
Compute embedding displacement between two texts.
Sourcepub fn embedding_displacement_from_vecs(
a: &[f32],
b: &[f32],
) -> Result<EmbeddingDisplacement, MemoryError>
pub fn embedding_displacement_from_vecs( a: &[f32], b: &[f32], ) -> Result<EmbeddingDisplacement, MemoryError>
Compute embedding displacement from pre-computed vectors.
Sourcepub fn chunk_text(&self, text: &str) -> Vec<TextChunk>
pub fn chunk_text(&self, text: &str) -> Vec<TextChunk>
Chunk text using the configured strategy and token counter.
Sourcepub async fn embed(&self, text: &str) -> Result<Vec<f32>, MemoryError>
pub async fn embed(&self, text: &str) -> Result<Vec<f32>, MemoryError>
Embed a single text via the configured provider.
Sourcepub async fn embed_batch(
&self,
texts: &[&str],
) -> Result<Vec<Vec<f32>>, MemoryError>
pub async fn embed_batch( &self, texts: &[&str], ) -> Result<Vec<Vec<f32>>, MemoryError>
Embed multiple texts in a batch.
Sourcepub async fn stats(&self) -> Result<MemoryStats, MemoryError>
pub async fn stats(&self) -> Result<MemoryStats, MemoryError>
Get database statistics.
Sourcepub async fn list_scope_domains(&self) -> Result<Vec<String>, MemoryError>
pub async fn list_scope_domains(&self) -> Result<Vec<String>, MemoryError>
Return distinct scope_domain values stored in document metadata.
Queries json_extract(metadata, '$.scope_domain') across all documents
and returns the unique non-null values. Used by the Recall app to populate
the scope picker dynamically instead of relying on a hardcoded list.
Sourcepub async fn embeddings_are_dirty(&self) -> Result<bool, MemoryError>
pub async fn embeddings_are_dirty(&self) -> Result<bool, MemoryError>
Check if embeddings need re-generation after a model change.
Sourcepub async fn reembed_all(&self) -> Result<usize, MemoryError>
pub async fn reembed_all(&self) -> Result<usize, MemoryError>
Re-embed all facts, chunks, messages, and episodes. Call after changing embedding models.
Sourcepub async fn vacuum(&self) -> Result<(), MemoryError>
pub async fn vacuum(&self) -> Result<(), MemoryError>
Vacuum the database (reclaim space after deletions).
Sourcepub async fn last_import_at(
&self,
namespace: &str,
) -> Result<Option<String>, MemoryError>
pub async fn last_import_at( &self, namespace: &str, ) -> Result<Option<String>, MemoryError>
Get the most recent successful import timestamp for a namespace.
Sourcepub async fn query_claim_versions(
&self,
query: ProjectionQuery,
) -> Result<Vec<ProjectionClaimVersion>, MemoryError>
pub async fn query_claim_versions( &self, query: ProjectionQuery, ) -> Result<Vec<ProjectionClaimVersion>, MemoryError>
Query imported claim projection rows through the supported public read surface.
Sourcepub async fn query_relation_versions(
&self,
query: ProjectionQuery,
) -> Result<Vec<ProjectionRelationVersion>, MemoryError>
pub async fn query_relation_versions( &self, query: ProjectionQuery, ) -> Result<Vec<ProjectionRelationVersion>, MemoryError>
Query imported relation projection rows through the supported public read surface.
Sourcepub async fn query_episodes(
&self,
query: ProjectionQuery,
) -> Result<Vec<ProjectionEpisode>, MemoryError>
pub async fn query_episodes( &self, query: ProjectionQuery, ) -> Result<Vec<ProjectionEpisode>, MemoryError>
Query imported episode projection rows through the supported public read surface.
Sourcepub async fn query_entity_aliases(
&self,
query: ProjectionQuery,
) -> Result<Vec<ProjectionEntityAlias>, MemoryError>
pub async fn query_entity_aliases( &self, query: ProjectionQuery, ) -> Result<Vec<ProjectionEntityAlias>, MemoryError>
Query imported entity-alias rows through the supported public read surface.
Sourcepub async fn query_evidence_refs(
&self,
query: ProjectionQuery,
) -> Result<Vec<ProjectionEvidenceRef>, MemoryError>
pub async fn query_evidence_refs( &self, query: ProjectionQuery, ) -> Result<Vec<ProjectionEvidenceRef>, MemoryError>
Query imported evidence-reference rows through the supported public read surface.
Sourcepub async fn query_claim_versions_governed(
&self,
query: ProjectionQuery,
request: GovernedAccessRequestV1,
) -> Result<GovernedProjectionResponseV1<ProjectionClaimVersion>, MemoryError>
pub async fn query_claim_versions_governed( &self, query: ProjectionQuery, request: GovernedAccessRequestV1, ) -> Result<GovernedProjectionResponseV1<ProjectionClaimVersion>, MemoryError>
Governed projection reads fail closed until imported rows have durable origin labels. The ungoverned projection methods above remain the explicit storage compatibility surface; no governed method delegates to them after authorization.
pub async fn query_relation_versions_governed( &self, query: ProjectionQuery, request: GovernedAccessRequestV1, ) -> Result<GovernedProjectionResponseV1<ProjectionRelationVersion>, MemoryError>
pub async fn query_episodes_governed( &self, query: ProjectionQuery, request: GovernedAccessRequestV1, ) -> Result<GovernedProjectionResponseV1<ProjectionEpisode>, MemoryError>
pub async fn query_entity_aliases_governed( &self, query: ProjectionQuery, request: GovernedAccessRequestV1, ) -> Result<GovernedProjectionResponseV1<ProjectionEntityAlias>, MemoryError>
pub async fn query_evidence_refs_governed( &self, query: ProjectionQuery, request: GovernedAccessRequestV1, ) -> Result<GovernedProjectionResponseV1<ProjectionEvidenceRef>, MemoryError>
Trait Implementations§
Source§impl Clone for MemoryStore
impl Clone for MemoryStore
Source§fn clone(&self) -> MemoryStore
fn clone(&self) -> MemoryStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more