kiromi-ai-memory 0.2.2

Local-first multi-tenant memory store engine: Markdown/text content on object storage, metadata in SQLite, plugin-shaped embedder/storage/metadata, hybrid text+vector search.
Documentation
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Plan 12: regeneration knobs and reports.
//!
//! Public option/report types for the regeneration primitives. The
//! consuming methods on [`crate::Memory`] are
//! `subjects_to_regenerate(scope, opts)` (shipped) and the deferred
//! `reindex(scope)`, `regenerate_embeddings(scope, embedder)`, and
//! `gc(opts)` (designed in Plan 12).

use std::time::Duration;

use crate::summarizer::SummaryStyle;

/// Caller-tunable knobs on [`crate::Memory::subjects_to_regenerate`].
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct RegenSubjectOpts {
    /// When `true`, every subject under scope is yielded regardless of
    /// the stale flag. Used for mass re-summarisation after a model
    /// upgrade. Default `false`.
    pub force: bool,
    /// Style filter — only yield subjects whose target style matches.
    pub style: SummaryStyle,
}

impl Default for RegenSubjectOpts {
    fn default() -> Self {
        Self {
            force: false,
            style: SummaryStyle::Compact,
        }
    }
}

impl RegenSubjectOpts {
    /// Set the force flag.
    #[must_use]
    pub fn with_force(mut self, force: bool) -> Self {
        self.force = force;
        self
    }

    /// Set the style filter.
    #[must_use]
    pub fn with_style(mut self, style: SummaryStyle) -> Self {
        self.style = style;
        self
    }
}

/// Report from a future `Memory::reindex(scope)` (deferred — see Plan 12).
#[non_exhaustive]
#[derive(Debug, Clone, Default)]
pub struct ReindexReport {
    /// Number of `partition_index` rows whose disk index was rebuilt.
    pub indices_rebuilt: u64,
    /// Number of memory rows whose embedding was re-shipped to a
    /// rebuilt leaf index.
    pub memories_indexed: u64,
    /// Number of child summaries shipped into a rebuilt internal/tenant
    /// index.
    pub child_summaries_indexed: u64,
    /// Wall-clock duration in millis.
    pub duration_ms: u64,
}

/// Report from a future `Memory::regenerate_embeddings(scope, embedder)`
/// (deferred — see Plan 12).
#[non_exhaustive]
#[derive(Debug, Clone, Default)]
pub struct RegenReport {
    /// Number of memories successfully re-embedded.
    pub processed: u64,
    /// Number of memories skipped (e.g. already at target embedder).
    pub skipped: u64,
    /// Number of memories that failed to re-embed.
    pub failed: u64,
    /// Wall-clock duration in millis.
    pub duration_ms: u64,
    /// First 32 errors in `(subject_id, message)` form.
    pub errors: Vec<(String, String)>,
}

/// Caller-tunable knobs on a future `Memory::gc(opts)` (deferred — see Plan 12).
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct GcOpts {
    /// Retention window. Orphan blobs younger than `retain_for` are
    /// preserved. Default 24 hours.
    pub retain_for: Duration,
    /// When `true`, returns the report without removing anything.
    pub dry_run: bool,
}

impl Default for GcOpts {
    fn default() -> Self {
        Self {
            retain_for: Duration::from_secs(24 * 3600),
            dry_run: false,
        }
    }
}

impl GcOpts {
    /// Set the retention window. Orphan blobs younger than `dur` are
    /// preserved.
    #[must_use]
    pub fn with_retain_for(mut self, dur: Duration) -> Self {
        self.retain_for = dur;
        self
    }

    /// Toggle dry-run mode.
    #[must_use]
    pub fn with_dry_run(mut self, dry: bool) -> Self {
        self.dry_run = dry;
        self
    }
}

/// Report from a future `Memory::gc(opts)` (deferred — see Plan 12).
#[non_exhaustive]
#[derive(Debug, Clone, Default)]
pub struct GcReport {
    /// Number of `data/` blobs reaped (or marked, if `dry_run`).
    pub data_blobs_removed: u64,
    /// Number of `metadata/<path>/summaries/` blobs reaped.
    pub summary_blobs_removed: u64,
    /// Number of orphan `metadata/snapshots/*.manifest.json` reaped.
    pub manifest_blobs_removed: u64,
    /// Total bytes freed.
    pub bytes_freed: u64,
}