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
//! # PulseDB
//!
//! Distributed database for agentic AI systems - collective memory for multi-agent coordination.
//!
//! PulseDB provides persistent storage for AI agent experiences, enabling semantic
//! search, context retrieval, and knowledge sharing between agents. Supports native
//! sync between instances for multi-device and client-server deployments.
//!
//! ## Quick Start
//!
//! ```rust
//! # fn main() -> pulsedb::Result<()> {
//! # let dir = tempfile::tempdir().unwrap();
//! use pulsedb::{PulseDB, Config, NewExperience};
//!
//! // Open or create a database
//! let db = PulseDB::open(dir.path().join("test.db"), Config::default())?;
//!
//! // Create a collective (isolated namespace)
//! let collective = db.create_collective("my-project")?;
//!
//! // Record an experience
//! db.record_experience(NewExperience {
//! collective_id: collective,
//! content: "Always validate user input before processing".to_string(),
//! importance: 0.8,
//! embedding: Some(vec![0.1f32; 384]),
//! ..Default::default()
//! })?;
//!
//! // Search for relevant experiences
//! let query_embedding = vec![0.1f32; 384];
//! let results = db.search_similar(collective, &query_embedding, 10)?;
//!
//! // Clean up
//! db.close()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Key Concepts
//!
//! ### Collective
//!
//! A **collective** is an isolated namespace for experiences, typically one per project.
//! Each collective has its own vector index and can have different embedding dimensions.
//!
//! ### Experience
//!
//! An **experience** is a unit of learned knowledge. It contains:
//! - Content (text description of the experience)
//! - Embedding (vector representation for semantic search)
//! - Metadata (type, importance, confidence, tags)
//!
//! ### Embedding Providers
//!
//! PulseDB supports two modes for embeddings:
//!
//! - **External** (default): You provide pre-computed embeddings from your own service
//! (OpenAI, Cohere, etc.)
//! - **Builtin**: PulseDB generates embeddings using a bundled ONNX model
//! (requires `builtin-embeddings` feature)
//!
//! ## Distributed Sync
//!
//! With the `sync` feature, PulseDB instances can synchronize data across a
//! network. See the `sync` module for full documentation (enable the `sync`
//! feature to build it).
//!
//! Key components:
//! - `SyncManager` — Orchestrates sync lifecycle (start/stop/sync_once)
//! - `SyncTransport` — Pluggable transport trait (HTTP, in-memory, custom)
//! - `SyncServer` — Server-side handler for Axum consumers (`sync-http`)
//! - `PulseDB::compact_wal()` — WAL compaction for disk space reclamation
//!
//! ## Thread Safety
//!
//! `PulseDB` is `Send + Sync` and can be shared across threads using `Arc`.
//! The database uses MVCC for concurrent reads with exclusive write locking.
//!
//! ## Feature Flags
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `builtin-embeddings` | Bundles ONNX runtime with all-MiniLM-L6-v2 for local embedding generation. Without this feature, you must supply pre-computed embeddings. |
//! | `sync` | Core sync protocol: types, transport trait, in-memory transport, echo prevention guard. |
//! | `sync-http` | HTTP sync transport via reqwest (implies `sync`). |
//! | `sync-websocket` | WebSocket sync transport via tokio-tungstenite (implies `sync`). |
// ============================================================================
// Module declarations
// ============================================================================
// Domain modules
/// SubstrateProvider async trait for agent framework integration.
/// Native sync protocol for distributed PulseDB instances.
///
/// Requires the `sync` feature flag. Provides types, transport trait,
/// and echo prevention for synchronizing data between PulseDB instances.
/// Vector index module for HNSW-based approximate nearest neighbor search.
/// Test-only migration fault-injection seam (VS-4.0.4 / #46).
///
/// Compiled ONLY under `--features fault-injection`; never present in default or
/// release builds. Lets crash-recovery tests arm a simulated crash at a specific
/// on-open migration boundary. Changes no migration behavior.
// ============================================================================
// Public API re-exports
// ============================================================================
// Main database interface
pub use PulseDB;
// Configuration
pub use ;
// Error handling
pub use ;
// Core types
pub use ;
// Domain types
pub use ;
pub use ;
// Relations
pub use ;
// Insights
pub use ;
// Activities
pub use ;
// Search & Context
pub use ;
// Watch (real-time notifications + cross-process change detection)
pub use ;
// Substrate (async agent framework integration)
pub use ;
// Storage (for advanced users)
pub use DatabaseMetadata;
// ============================================================================
// Prelude module for convenient imports
// ============================================================================
/// Convenient imports for common PulseDB usage.
///
/// ```rust
/// use pulsedb::prelude::*;
/// ```