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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//! Gradatum index abstraction trait.
//!
//! ## Design
//!
//! `Index` is a **supertrait facade** composing the three granular traits:
//! - [`DocumentStore`] — CRUD notes
//! - [`IndexStore`] — FTS, overrides, checksums, composite scoring
//! - [`VectorStore`] — embeddings + cosine semantic search
//!
//! The `Index` trait lives in `gradatum-core` (not `gradatum-index`) so that
//! consumer crates (`gradatum-vault`, `gradatum-curator`) import the abstract trait,
//! not the concrete `SqliteIndex` implementation (in `gradatum-index`).
//!
//! Benefit: `gradatum-vault` does not depend on `gradatum-index` → no cycle.
//!
//! ## Backward compatibility
//!
//! `Index as _` remains functional for existing call sites. To access granular methods
//! (e.g. `list_file_checksums`), also import the relevant sub-trait
//! (`IndexStore as _`, `DocumentStore as _`, `VectorStore as _`).
//!
//! ## FileChecksumEntry
//!
//! Entry in the `file_checksums` table — per-file drift detection.
//! Detects files modified outside Gradatum without re-hashing the entire vault.
//! Strategy: (1) fast mtime + size check, (2) 4 KB partial hash, (3) full hash.
//!
//! ## Generic overrides
//!
//! `upsert_override_raw` / `get_override_raw` store any override payload as TOML
//! in the generic `note_overrides` table.
//! The schema is identified by (`override_type`, `schema_version`) and validated via
//! `gradatum-core::schema_registry`.
//!
//! ## Methods remaining concrete on `SqliteIndex` only
//!
//! The following `SqliteIndex` methods are NOT promoted to a trait at this version:
//! - `search_fts_with_snippet`: returns `SearchHitRaw` (a type in `gradatum-index`) —
//! promotion deferred pending a stable public type.
//! - Admin/lifecycle methods (`downgrade_note`, `patch_note_status`, `list_notes`, etc.):
//! operational semantics, no trait-based consumer planned at this time.
//! - Seed/bench methods: test/perf utilities, outside the public contract.
use ;
use crateDocumentStore;
use crateIndexStore;
use crateVectorStore;
/// Legacy facade — combination of the three storage traits.
///
/// Retained for compatibility with existing call sites.
/// New consumers SHOULD depend on the granular traits
/// (`DocumentStore` / `IndexStore` / `VectorStore`) — more precise and forwards-compatible.
///
/// ## Blanket impl
///
/// Any type implementing the three sub-traits automatically implements `Index`.
/// No manual `impl Index for T` is needed.
/// Blanket impl: any type implementing the three sub-traits becomes an `Index`.
// ── TemporalIndex ────────────────────────────────────────────────────────────
/// Source of the temporal anchor in the `temporal_index` table.
///
/// Stored as a `&'static str` in the DB (`anchor_src` column) for readability.
/// Resolution priority (descending): `OccurredAt > EventDate > ValidFrom > Created`.
///
/// Fallback: `Created` is always available (`notes.created` is NOT NULL).
/// Entry in the `temporal_index` table — temporal anchor for a note.
///
/// ## Design
///
/// Derived table — all data is computable from `notes` + frontmatter.
///
/// ## Logical reference (no FK cascade)
///
/// `note_id` is a logical reference, NOT a FOREIGN KEY.
/// Deletion must be explicit via `DELETE FROM temporal_index WHERE note_id = ?`
/// in `delete_note_from_index` — do not rely on ON DELETE CASCADE.
///
/// ## Temporal anchor (descending priority)
///
/// 1. `occurred_at` in `frontmatter.extra`
/// 2. `event-date` in `frontmatter.extra`
/// 3. `valid_from` in `frontmatter.extra`
/// 4. `notes.created` (universal fallback)
///
/// ## `valid_until_ms`
///
/// Reserved for temporal windowing in a future release. `None` in the current version.
/// Per-file drift detection entry.
///
/// Stored in the `file_checksums` table. Detects files modified outside Gradatum
/// by checking (mtime + size) before re-hashing the entire file.
/// File category tracked in `file_checksums`.
/// Full note record returned by [`DocumentStore::get_note`].
///
/// Portable struct defined in `gradatum-core` to allow use via the `DocumentStore` trait
/// without a dependency on `gradatum-index`.