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
//! Process-global registration of the statically-linked `sqlite-vec` (`vec0`)
//! extension as a SQLite auto-extension. Once registered, every rusqlite
//! `Connection` opened afterwards has `vec0` available.
//!
//! This lives outside `src/librarian/` (which is `cfg(feature = "librarian")`)
//! so the always-compiled retrieval code store can register it too. `vec0` is
//! **statically linked** into the binary — no runtime DLL, so nothing for an
//! EDR like CrowdStrike to quarantine (unlike the `onnxruntime.dll` of WIN-22).
//! That static-linking is what makes the daemon-free "lite" stack viable on a
//! locked-down VDI; see `docs/plans/2026-06-16-two-stack-retrieval-lite.md`.
//!
//! A single shared `Once` guarantees one registration regardless of which
//! subsystem (librarian catalog, retrieval code store, memory store) touches
//! sqlite-vec first — registering the same auto-extension twice would run the
//! `vec0` init on every connection twice.
use Once;
// Compile-time pin on the upstream signature: if sqlite-vec ever changes the
// `sqlite3_vec_init` ABI, this fails to compile instead of mis-registering.
const _UPSTREAM_SQLITE_VEC_INIT_SIG: unsafe extern "C" fn = sqlite3_vec_init;
static INIT: Once = new;
/// Register `vec0` as a global SQLite auto-extension (idempotent, Once-guarded).
/// Call before opening any `Connection` that uses `vec0` virtual tables.
/// Map a project id to a filesystem-safe DB file stem (shared by the sqlite-vec
/// code + memory stores so a project always resolves to the same file).
/// Little-endian f32 blob for a `vec0` embedding column / `vec_f32()` argument.