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
//! # sqlite-graphrag
//!
//! Local GraphRAG memory for LLMs in a single SQLite file — zero external
//! services required.
//!
//! `sqlite-graphrag` is a CLI-first library that persists memories, entities and
//! typed relationships inside a single SQLite database. It combines FTS5
//! full-text search with `sqlite-vec` KNN over locally-generated embeddings to
//! expose a hybrid retrieval ranker tailored for LLM agents.
//!
//! ## CLI usage
//!
//! Install and initialize once, then save and recall memories:
//!
//! ```bash
//! cargo install sqlite-graphrag
//! sqlite-graphrag init
//! sqlite-graphrag remember \
//! --name onboarding-note \
//! --type user \
//! --description "first memory" \
//! --body "hello graphrag"
//! sqlite-graphrag recall "graphrag" --k 5
//! ```
//!
//! ## Crate layout
//!
//! The public modules group the CLI, the SQLite storage layer and the
//! supporting primitives (embedder, chunking, graph, namespace detection,
//! output, paths and pragmas). The CLI binary wires them together through the
//! commands in [`commands`].
//!
//! ## Exit codes
//!
//! Errors returned from [`errors::AppError`] map to deterministic exit codes
//! suitable for orchestration by shell scripts and LLM agents. Consult the
//! README for the full contract.
use ;
/// Signals that a shutdown signal (SIGINT / SIGTERM / SIGHUP) has been received.
///
/// Set in `main` via `ctrlc::set_handler`. Long-running subcommands can
/// poll [`shutdown_requested`] to shut down gracefully before timeout.
pub static SHUTDOWN: AtomicBool = new;
/// Returns `true` if a shutdown signal has been received since the process started.
///
/// The value reflects the state of [`SHUTDOWN`]. Without a `ctrlc::set_handler` call,
/// the initial state is always `false`.
///
/// # Examples
///
/// ```
/// use sqlite_graphrag::shutdown_requested;
///
/// // Under normal startup conditions the signal has not been received.
/// assert!(!shutdown_requested());
/// ```
///
/// ```
/// use std::sync::atomic::Ordering;
/// use sqlite_graphrag::{SHUTDOWN, shutdown_requested};
///
/// // Simulate receiving a signal and verify that the function reflects the state.
/// SHUTDOWN.store(true, Ordering::SeqCst);
/// assert!(shutdown_requested());
/// // Restore to avoid contaminating other tests.
/// SHUTDOWN.store(false, Ordering::SeqCst);
/// ```
/// Token-aware chunking utilities for bodies that exceed the embedding window.
/// Hybrid entity extraction: regex pre-filter + candle BERT NER (graceful degradation).
/// `clap` definitions for the top-level `sqlite-graphrag` binary.
/// Subcommand handlers wired into the `clap` tree from [`cli`].
/// Compile-time constants: embedding dimensions, limits and thresholds.
/// Daemon IPC for persistent embedding model reuse across CLI invocations.
/// Local embedding generation backed by `fastembed`.
/// Library-wide error type and the mapping to process exit codes (see [`errors::AppError`]).
/// Graph traversal helpers over the entities and relationships tables.
/// Bilingual message layer for human-facing stderr progress (`--lang en|pt`, `SQLITE_GRAPHRAG_LANG`).
/// Counting semaphore via lock files to limit parallel invocations (see [`lock::acquire_cli_slot`]).
/// Memory guard: checks RAM availability before loading the ONNX model.
/// Namespace resolution with precedence between flag, environment and markers.
/// Centralized stdout/stderr emitters for CLI output formatting.
/// Dual-format argument parser: accepts Unix epoch and RFC 3339.
/// Filesystem paths for the project-local database and app support directories.
/// SQLite pragma helpers applied on every connection.
/// Persistence layer: memories, entities, chunks and version history.
/// Display time zone for `*_iso` fields (flag `--tz`, env `SQLITE_GRAPHRAG_DISPLAY_TZ`, fallback UTC).
/// Real tokenizer of the embedding model for accurate token counting and chunking.
pub use migrations;