Skip to main content

kiromi_ai_memory/
lib.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//! `kiromi-ai-memory` — engine for the kiromi-ai-memory memory store.
3//!
4//! This crate exposes the public API consumers (CLI, FFI, future server) wrap.
5//! See `docs/superpowers/specs/` for the design spec.
6// Plan 18: relaxed from `forbid` to `deny` so the `sqlite-vec` extension
7// auto-load (one tiny `unsafe` block in `metadata::sqlite::ensure_sqlite_vec_loaded`)
8// can be opted-in with a localised `#[allow(unsafe_code)]`. The rest of the
9// crate stays unsafe-free; CI greps for additional `unsafe_code` allowances.
10#![deny(unsafe_code)]
11#![warn(missing_docs)]
12#![cfg_attr(
13    test,
14    allow(
15        clippy::unwrap_used,
16        clippy::expect_used,
17        clippy::panic,
18        clippy::missing_panics_doc
19    )
20)]
21
22pub mod anchor;
23pub mod attribute;
24pub mod audit;
25pub mod builder;
26pub mod canonical_keys;
27pub mod capabilities;
28pub mod codec;
29pub mod content;
30pub mod context;
31pub mod embedder;
32pub mod error;
33pub mod event;
34pub mod evolve;
35pub mod graph;
36pub mod handle;
37pub mod index;
38pub mod link;
39pub mod memory;
40pub mod metadata;
41pub mod migrate;
42pub mod ops;
43pub mod opts;
44pub mod partition;
45pub mod query;
46pub mod regen;
47mod regen_ops;
48pub mod reranker;
49pub mod search;
50pub mod snapshot;
51pub mod storage;
52pub mod summarizer;
53pub mod summary;
54pub mod tenancy;
55pub mod tenant;
56pub mod util;
57
58pub use crate::attribute::{AttributeValue, kind_str as attribute_kind_str};
59pub use crate::builder::Builder;
60pub use crate::capabilities::{
61    EmbedderCapabilities, MetadataCapabilities, Plugin as CapabilityPlugin, StorageCapabilities,
62};
63pub use crate::codec::Codec;
64pub use crate::content::{Content, ContentHash, ContentKind};
65pub use crate::context::{ContextBlock, ContextDiff, ContextKind, ContextOpts, ContextOrdering};
66pub use crate::embedder::{CALLER_PROVIDED_EMBEDDER_ID, EmbedRole, Embedder, EmbedderRegistry};
67pub use crate::error::{Error, Result};
68pub use crate::event::{DEFAULT_EVENT_CAPACITY, MemoryEvent};
69pub use crate::evolve::{
70    EvolutionApplied, EvolutionOps, EvolutionReport, MemoryAttributeOp, SummaryAttributeOp,
71};
72pub use crate::graph::{EdgeKind, EdgeKindTag, Graph, GraphEdge, GraphNode, NodeRef, TraverseOpts};
73pub use crate::handle::{Memory, MemoryView};
74pub use crate::link::{Edge, Link, LinkKind};
75pub use crate::memory::{MemoryId, MemoryKind, MemoryRecord, MemoryRecordWire, MemoryRef};
76pub use crate::metadata::{MetadataStore, PartitionInfo, SnapshotRow, SqliteMetadata};
77pub use crate::migrate::{MigrationOpts, MigrationReport, SchemeMapper};
78pub use crate::ops::{BackupReport, CheckpointReport, VacuumOpts, VacuumReport};
79pub use crate::opts::{AppendOpts, AttachSummaryOpts, DeleteOpts, LinksOpts, ListOpts, Page};
80pub use crate::partition::{PartitionPath, PartitionScheme, Partitions};
81pub use crate::query::{Query, QueryMode, SearchHit};
82pub use crate::regen::{GcOpts, GcReport, RegenReport, RegenSubjectOpts, ReindexReport};
83pub use crate::reranker::Reranker;
84pub use crate::snapshot::{
85    RestoreOpts, RestoreReport, SnapshotAttribute, SnapshotId, SnapshotManifest, SnapshotOpts,
86    SnapshotRef,
87};
88pub use crate::storage::{InMemoryBackend, LocalFsBackend, Storage};
89pub use crate::summarizer::{
90    SummarizeOpts, Summarizer, SummarizerCapabilities, SummarizerRegistry, SummaryStyle,
91};
92pub use crate::summary::content::{
93    DataPointRef, PartitionRef, SummaryBlock, SummaryContent, SummaryInputRange,
94};
95pub use crate::summary::{Scope, StaleKind, SummaryId, SummaryRecord, SummaryRef, SummarySubject};
96pub use crate::tenant::TenantId;
97
98/// Crate version — written into audit log entries.
99pub const VERSION: &str = env!("CARGO_PKG_VERSION");
100
101#[cfg(test)]
102mod sync_send_asserts {
103    //! Plan 14 phase C.2 — compile-time guards that every cross-thread public
104    //! type stays `Send + Sync` and that the public traits stay object-safe.
105    //!
106    //! If any of these fail to compile, the public surface has regressed —
107    //! diagnose the offending field/payload before adjusting the assert.
108
109    use static_assertions::assert_impl_all;
110
111    use super::*;
112
113    // Engine handles cross thread boundaries (every async runtime usage).
114    assert_impl_all!(Memory: Send, Sync, Clone);
115    assert_impl_all!(MemoryView: Send, Sync);
116
117    // Records returned by reads.
118    assert_impl_all!(MemoryRecord: Send, Sync, Unpin);
119    assert_impl_all!(MemoryRef: Send, Sync, Unpin);
120    assert_impl_all!(MemoryId: Send, Sync, Unpin, Copy);
121
122    // Options consumed by writes / queries.
123    assert_impl_all!(AppendOpts: Send, Sync, Unpin);
124    assert_impl_all!(ListOpts: Send, Sync, Unpin);
125    assert_impl_all!(DeleteOpts: Send, Sync, Unpin);
126    assert_impl_all!(Query: Send, Sync, Unpin);
127    assert_impl_all!(snapshot::SnapshotOpts: Send, Sync);
128    assert_impl_all!(snapshot::RestoreOpts: Send, Sync);
129
130    // Push-side events: cloned across subscriber tasks.
131    assert_impl_all!(MemoryEvent: Send, Sync, Clone);
132
133    // Snapshots / regen / migration reports.
134    assert_impl_all!(snapshot::SnapshotManifest: Send, Sync);
135    assert_impl_all!(snapshot::SnapshotRef: Send, Sync);
136    assert_impl_all!(regen::RegenReport: Send, Sync);
137    assert_impl_all!(regen::ReindexReport: Send, Sync);
138    assert_impl_all!(regen::GcReport: Send, Sync);
139    assert_impl_all!(migrate::MigrationReport: Send, Sync);
140
141    // Summary surface (Plan 9 + Plan 11).
142    assert_impl_all!(SummaryRecord: Send, Sync);
143    assert_impl_all!(SummaryRef: Send, Sync);
144    assert_impl_all!(summary::SummarySubject: Send, Sync);
145    assert_impl_all!(summary::content::SummaryContent: Send, Sync);
146
147    // Attribute payload (Plan 11).
148    assert_impl_all!(attribute::AttributeValue: Send, Sync);
149
150    // Errors must round-trip across thread boundaries.
151    assert_impl_all!(Error: Send, Sync);
152
153    // Public traits must stay object-safe (engine internals already use
154    // `dyn Storage`, `dyn MetadataStore`, etc., but compile-fail here pins
155    // it from the public side too).
156    fn _assert_object_safe(
157        _s: &dyn storage::Storage,
158        _m: &dyn metadata::MetadataStore,
159        _e: &dyn embedder::Embedder,
160        _sm: &dyn summarizer::Summarizer,
161        _r: &dyn reranker::Reranker,
162        _c: &dyn codec::Codec,
163    ) {
164    }
165}