1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! # gemini-memory-rs
//!
//! A contextual memory engine for Gemini Live voice sessions.
//!
//! The engine's organising principle is that **context is prepared
//! asynchronously and consumed synchronously**. Nothing expensive — model
//! calls, search, repository writes — ever happens on the path between the
//! model asking for memory and the memory arriving. By the time a
//! `recall_context` tool call lands, the answer is already sitting in state.
//!
//! ```text
//! user speech ─► input transcription ─► retrieval-state extraction
//! │
//! ▼
//! local BM25 search
//! │
//! ▼
//! immutable prepared snapshot ─► Gemini
//!
//! final transcript ─► observation extraction ─► session ledger
//! │
//! ┌───────────────────────────┤
//! ▼ ▼
//! session overlay post-session reconciliation
//! (usable now) │
//! ▼
//! canonical OKF markdown
//! ```
//!
//! ## Layout
//!
//! Each module is the design's correspondingly-named component:
//!
//! | Module | Responsibility |
//! |--------|----------------|
//! | [`core`] | Domain vocabulary, deterministic policy, event log |
//! | [`okf`] | Canonical Markdown memory records and the repository |
//! | [`bm25`] | Fielded lexical index, ranking, and search explanation |
//! | [`transcript`] | Partial/final transcript accumulation and debouncing |
//! | [`retrieval`] | Retrieval plans, fusion, budgeted context assembly |
//! | [`ingestion`] | Observation extraction, candidate ledger, session overlay |
//! | [`reconcile`] | Consolidation, conflict resolution, promotion, commit |
//! | [`runtime`] | Live-session wiring: state keys, control loop, tools |
//! | [`evals`] | Fixture-driven quality harness |
//!
//! ## Getting started
//!
//! ```no_run
//! use gemini_memory_rs::prelude::*;
//!
//! # async fn demo() -> Result<(), MemoryError> {
//! let engine = MemoryEngine::in_memory(UserId::new("usr_72ab"));
//!
//! // A finalized user turn: evidence in, context out.
//! let session = engine.begin_session(SessionId::new("ses_01"));
//! session.observe_final_transcript(TurnId(1), "I am pescatarian").await?;
//!
//! let snapshot = session.prepare(TurnId(2), "what should we eat tonight").await?;
//! for fact in snapshot.facts.iter() {
//! println!("{}", fact.statement);
//! }
//! # Ok(())
//! # }
//! ```
/// The types a typical application touches.