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
//! **FathomDB** — a local-first retrieval and graph-oriented data system for
//! application and agent workloads.
//!
//! This is the crate to depend on from Rust. It is a thin facade that
//! re-exports the public surface of the `fathomdb-engine` runtime, so you get
//! the supported API without depending on engine internals.
//!
//! FathomDB embeds SQLite (FTS5 + `sqlite-vec`) in your process — there is no
//! server and no sidecar. One `Engine` owns the writer thread, a reader pool,
//! the projection scheduler and (optionally) an in-process embedder.
//!
//! # Do you want this crate?
//!
//! - **Yes**, if you want hybrid retrieval — a vector branch and an FTS5 branch
//! fused by Reciprocal Rank Fusion — over data you also want to address by a
//! stable identity, traverse as a graph, and be able to *delete on request*.
//! - **No**, if you want a client for a remote database, or an approximate
//! nearest-neighbour index at very large scale: vector retrieval here is a
//! full scan, so latency grows with corpus size.
//!
//! Related crates: `fathomdb-cli` (the operator binary — `doctor` / `recover`),
//! `fathomdb-embedder-api` (the semver-stable embedder trait, versioned
//! independently), and `fathomdb-engine` (the runtime this crate re-exports;
//! prefer this facade).
//!
//! # Example
//!
//! ```no_run
//! use fathomdb::{Engine, PreparedWrite, SourceId};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let opened = Engine::open("./example.fdb")?;
//! let engine = opened.engine;
//!
//! engine.write(&[PreparedWrite::Node {
//! kind: "note".into(),
//! body: "the sky is blue".into(),
//! // Provenance is MANDATORY — see below.
//! source_id: SourceId::new("doc-42")?,
//! logical_id: Some("note:sky".into()),
//! state: Default::default(),
//! reason: None,
//! valid_from: None,
//! valid_until: None,
//! }])?;
//!
//! for hit in engine.search("sky")?.results {
//! // `hit.id` is a typed id-space carrier, not a row number.
//! println!("{:?} {} {}", hit.id.space, hit.id.value, hit.body);
//! }
//!
//! engine.close()?;
//! # Ok(())
//! # }
//! ```
//!
//! # Provenance is mandatory
//!
//! Every canonical node and edge carries a [`SourceId`]. This is a *type*
//! rather than a validation check on purpose: [`Engine::erase_source`] addresses
//! rows **by** their `source_id`, so a row written without one could never be
//! erased on request. [`SourceId::new`] is the only public constructor and
//! refuses an empty id and the engine's reserved `_`-prefixed namespace, which
//! makes an un-provenanced write a **compile error** rather than a runtime
//! surprise.
//!
//! Treat a `source_id` as a public identifier: it is echoed on every search hit
//! and recorded in a retention-exempt erasure-audit row, so keep personal data
//! out of it.
//!
//! # Deletion on request
//!
//! Three verbs, differing in what they address, all on the default surface:
//!
//! - [`Engine::transition`] — move a governed node between existence states
//! (promote, soft-delete, undelete).
//! - [`Engine::purge`] — irreversibly hard-erase one governed node, addressed by
//! its `logical_id`. Deleted-first and idempotent. There is no restore.
//! - [`Engine::erase_source`] — erase every row carrying one `source_id`,
//! including *anonymous* rows that have no `logical_id` and that
//! [`Engine::purge`] therefore cannot reach.
//!
//! # Feature flags
//!
//! - **default** — the *governed application surface*
//! (`dev/interfaces/rust.md` § Governed-surface contract): recovery-name-free
//! and raw-SQL-free at the **method** level. No method named `recover`,
//! `restore`, `repair`, `fix` or `rebuild` resolves.
//! - **`operator`** — un-gates the operator/recovery seam (`rebuild_*`,
//! `excise_source`, `dump_*`, `trace_source_ref`, `truncate_wal`,
//! `verify_embedder`, `check_integrity`, `safe_export`, `recompute_mean` and
//! their report types). `fathomdb-cli` enables it. Gating, not deletion:
//! engine behaviour is identical with the feature on. See AC-074
//! (`dev/acceptance.md`) and
//! `dev/design/slice-27-fix1-operator-gate-design.md`.
//!
//! # Stability
//!
//! Pre-1.0, so **beta**: the surface may change between micro releases. The
//! governed surface is pinned by
//! `src/conformance/governed-surface-allowlist.json` and any change to it is a
//! reviewed delta, but that is a change-control promise, not a semver one.
//! [`PreparedWrite`] and [`SearchFilter`] are `#[non_exhaustive]`.
// The 26 governed application-surface types (`dev/interfaces/rust.md` § 2a) —
// always present on the default facade.
//
// 17 original types + 7 new types from Slices 20 (G5/G6) and 35 (G4):
// Slice 20: ComparisonOp, NodeRecord, Predicate, ScalarValue, SearchExpandResult,
// SearchFilter, TraversalDirection
// + 2 new types from Slice 15 (G11 BYO-LLM ingest — fix-29):
// ExtractDocument, IngestWithExtractorReceipt
// + 3 new types from 0.8.8 Slice 5 (EXP-OBS explain sidecar):
// Explanation, QueryTrace, PerHitExplain
// + 1 new type from 0.8.20 Slice 5c (R-20-E3, erasure): SourceId — the
// provenance newtype that replaced `source_id: Option<String>` on
// `PreparedWrite`. It MUST be re-exported here: this crate re-exports
// `PreparedWrite` and `Engine::write` is public, so without the constructor a
// facade consumer could not perform a canonical write at all. Its presence is
// also what makes the un-provenanced write a COMPILE error for facade
// consumers rather than a runtime rejection (see `tests/ui/`).
// + 1 new type from 0.8.20 Slice 5d (R-20-E4, erasure): ExciseReport — the
// outcome of the net-new governed `Engine::erase_source` lifecycle verb. It
// MOVED here from the operator-gated block below: `erase_source` is governed
// surface (an SDK-only consumer must be able to erase anonymous content it
// wrote), so its return type cannot stay behind the CLI feature gate. The
// operator build is unaffected — it now gets the type from this block instead.
// + 2 new types from 0.8.20 Slice 10b (R-20-RV / R-20-NV): `ReadView` — the
// read-mode / validity selector every one of the five read verbs now takes —
// and `BoundaryCrossing`, the return shape of `Engine::crossed_boundary_since`.
// Threading `ReadView` as a parameter (rather than shipping five `*_with_view`
// sibling verbs) is what keeps this delta at TWO TYPES and ZERO new verbs.
// HITL-SIGNED 2026-07-29 (steward seq-157) — recorded in
// `src/conformance/governed-surface-allowlist.json`.
// + 1 new type from 0.8.20 Slice 20 / 0.8.22 Slice 21 F5 (R-20-DR):
// `DenseReadiness` — the `{unavailable, embedding, ready}` READ-METADATA
// flag the engine hangs off `ProjectionSpec.vector` (`read.projections`
// populates it; it is never a caller declaration). ZERO net-new commands;
// the vocabulary was HITL-signed in steward-ledger seq-246.
// + 4 new types from 0.8.22 Slice 22 C5: `ProjectionRuntimeStatus`,
// `ProjectionRuntimeStatusEntry`, `ProjectionRuntimeUnavailabilityReason`,
// and `ProjectionStatusDenseReadiness` — the pure status facade for the
// current projection runtime. Its command spelling is binding-specific;
// these types were HITL-signed in steward-ledger seq-247.
pub use ;
// The operator-seam report types (`dev/interfaces/rust.md` § 2b) — CLI-only,
// gated behind `operator`. The backing `Engine` methods are operator-gated in
// `fathomdb-engine`, so the default facade is recovery-clean at the method level.
//
// 0.8.20 Slice 5d keeps the count at 20 via two offsetting moves:
// - `ExciseReport` moved OUT (up to the always-present block): it is the
// return type of the governed `Engine::erase_source`, so it cannot sit
// behind the CLI feature gate.
// - `OrphanProvenanceReport` + `OrphanProvenanceSource` moved IN: the
// `doctor orphan-provenance` diagnostic is CLI-only with no SDK parity,
// the same posture as `dump-mutations` (Slice 34).
pub use ;
/// AC-074 method-level pin (Q5=BIND-RUST, Slice 27 fix-1): in a **default**
/// (operator-OFF) build the governed `fathomdb::Engine` exposes **no**
/// recovery-denylist-named method. Rust has no runtime method reflection, so the
/// guarantee is pinned by `compile_fail` doctests (the only mechanism that can
/// assert a method does *not* resolve). This module is
/// `#[cfg(not(feature = "operator"))]`, so feature-unified `--workspace` builds
/// (which turn `operator` ON via `fathomdb-cli`) correctly skip it.
///
/// `rebuild_projections` does not resolve on the default facade:
/// ```compile_fail
/// fn _no_rebuild_projections(e: &fathomdb::Engine) {
/// let _ = e.rebuild_projections();
/// }
/// ```
///
/// `rebuild_vec0` does not resolve on the default facade:
/// ```compile_fail
/// fn _no_rebuild_vec0(e: &fathomdb::Engine) {
/// let _ = e.rebuild_vec0();
/// }
/// ```
///
/// `excise_source` (operator seam) does not resolve on the default facade:
/// ```compile_fail
/// fn _no_excise(e: &fathomdb::Engine) {
/// let _ = e.excise_source("s");
/// }
/// ```
/// AC-074 no-raw-SQL release-surface pin: the shipped (release) facade exposes
/// no raw-SQL method. The **canonical** guarantee is the engine's
/// `Engine::execute_for_test` gate — `#[cfg(debug_assertions)] #[doc(hidden)]`,
/// so the symbol is absent from release builds (verified: it is not present in
/// `target/release/libfathomdb_engine.rlib`). This `#[cfg(not(debug_assertions))]`
/// module is the release-surface pin in the best-effort `no_recovery_surface.rs`
/// style; it is compiled out of debug builds, and a true no-debug-assertions doc
/// build runs the `compile_fail` below. (Plain `cargo test --release` may not
/// re-run rustdoc with debug-assertions off, so this is a documented pin backed
/// by the engine cfg-gate, not a load-bearing CI assertion.)
///
/// `execute_for_test` (raw SQL) does not resolve in a release build:
/// ```compile_fail
/// fn _no_raw_sql(e: &fathomdb::Engine) {
/// let _ = e.execute_for_test("SELECT 1");
/// }
/// ```