khive_pack_memory/lib.rs
1//! Memory pack — `memory.remember` and `memory.recall` verbs with decay-aware ranking.
2
3pub(crate) mod ann;
4pub mod config;
5pub mod handlers;
6mod pack;
7pub(crate) mod query_cache;
8pub mod recall_feedback;
9pub mod rerank;
10pub mod scoring;
11#[doc(hidden)]
12pub mod text_gather;
13pub mod tunable;
14
15pub use pack::MemoryPack;
16
17/// Bump the durable memory-ANN corpus epoch (#812 review REQUEST CHANGES
18/// HIGH). `kkernel reindex` mutates note vectors and deletes the persisted
19/// Vamana snapshot directly, out of process from any running khive daemon —
20/// its in-memory write-generation counter (`ann::bump_generation`) is simply
21/// unreachable from a separate process. Call this after invalidating the
22/// snapshot so a warm daemon sharing the same database file has a durable
23/// signal to observe on its next amortized freshness check
24/// (`ann::maybe_check_durable_epoch`, sampled from the recall path) and
25/// schedules a rebuild instead of serving pre-reindex vectors indefinitely.
26pub async fn bump_memory_ann_epoch(
27 rt: &khive_runtime::KhiveRuntime,
28) -> Result<u64, khive_runtime::RuntimeError> {
29 ann::bump_durable_epoch(rt).await
30}
31
32/// Ensure the `memory_ann_epoch` table exists on `rt` (idempotent, #812
33/// review REQUEST CHANGES MEDIUM — pack schema contract). Declared via
34/// `MemoryPack::SCHEMA_PLAN` for daemon boot (`server.rs`/`serve.rs` apply
35/// every loaded pack's schema plan up front), but `kkernel reindex` runs
36/// directly against a raw `KhiveRuntime` without ever booting a pack
37/// registry — it calls this explicitly, once, before its first
38/// `bump_memory_ann_epoch`, so a reindex against a brand-new database (no
39/// daemon ever started) doesn't fail before this table exists.
40pub async fn ensure_ann_epoch_schema(
41 rt: &khive_runtime::KhiveRuntime,
42) -> Result<(), khive_runtime::RuntimeError> {
43 ann::ensure_epoch_schema(rt).await
44}