agentdb/lib.rs
1//! # AgentDB
2//!
3//! A single-file embedded database for AI agents.
4//!
5//! **Eight layers, one file, zero servers:**
6//!
7//! | Layer | What it gives you |
8//! |---|---|
9//! | Relational SQL (SQLite) | Full SQL engine, ACID, WAL, user-defined tables |
10//! | HNSW Vector Search | ANN search, cosine/euclidean/dot, batch upsert |
11//! | Memory Graph (recursive CTE) | Typed nodes, weighted edges, recursive CTE traversal |
12//! | FTS5 Full-Text Search | FTS5 virtual tables, BM25 ranking, Porter stemmer |
13//! | Hybrid Graph + Vector Queries | Graph traversal + vector ANN with alpha blending |
14//! | Conversations | Threaded message history with role and metadata |
15//! | Workflow Persistence | Durable multi-step agent workflow state |
16//! | Reasoning Traces | Structured chain-of-thought and trace logging |
17//!
18//! ## Quick start
19//!
20//! ```rust,no_run
21//! use agentdb::{AgentDB, VectorEntry, SearchOptions, DistanceMetric};
22//! use serde_json::json;
23//!
24//! let db = AgentDB::open(":memory:").unwrap();
25//!
26//! // SQL
27//! db.execute("CREATE TABLE sessions (id TEXT PRIMARY KEY)").unwrap();
28//!
29//! // Vectors
30//! let col = db.vectors().collection("thoughts", 4).unwrap();
31//! col.upsert(VectorEntry {
32//! id: "t1".into(),
33//! vector: vec![0.9, 0.1, 0.0, 0.0],
34//! metadata: Some(json!({ "score": 9 })),
35//! }).unwrap();
36//!
37//! // Memory graph
38//! let graph = db.memory();
39//! graph.add_node("s1", "session", None).unwrap();
40//! graph.add_node("t1", "thought", None).unwrap();
41//! graph.add_edge("s1", "t1", "recalled", 0.9).unwrap();
42//!
43//! // Stats
44//! let stats = db.stats().unwrap();
45//! println!("nodes={} edges={}", stats.nodes, stats.edges);
46//! ```
47//!
48//! ## Feature flags
49//!
50//! | Flag | What it enables |
51//! |---|---|
52//! | `async` | Tokio async runtime wrappers |
53//! | `ffi` | C FFI flat API (`extern "C"` functions in `src/ffi.rs`) |
54//! | `python` | PyO3 Python bindings (enables `ffi`) |
55//! | `wasm` | WASM/wasm-bindgen target |
56
57pub mod conversations;
58pub mod db;
59pub mod error;
60pub mod filter;
61pub mod fts;
62pub mod hybrid;
63pub mod memory;
64pub mod schema;
65pub mod traces;
66pub mod vectors;
67pub mod workflows;
68
69#[cfg(feature = "async")]
70pub mod async_api;
71
72#[cfg(feature = "ffi")]
73pub mod ffi;
74
75#[cfg(feature = "wasm")]
76pub mod wasm;
77
78pub use conversations::{Conversation, ConversationStore, Message, MessageSearchResult};
79pub use db::{AgentDB, DbStats};
80pub use error::{AgentDbError, Result};
81pub use filter::matches as filter_matches;
82pub use fts::{FtsResult, FullTextStore};
83pub use hybrid::{HybridQuery, HybridResult, HybridStore};
84pub use memory::{Edge, MemoryGraph, Node, TraversalOptions, TraversalResult};
85pub use traces::{Trace, TraceStore};
86pub use vectors::{
87 BatchEntry, Collection, DistanceMetric, SearchOptions, SearchResult, VectorEntry, VectorStore,
88};
89pub use workflows::{Workflow, WorkflowStep, WorkflowStore};
90
91#[cfg(feature = "async")]
92pub use async_api::{
93 AsyncAgentDB, AsyncCollection, AsyncConversationStore, AsyncFullTextStore, AsyncMemoryGraph,
94 AsyncTraceStore, AsyncVectorStore, AsyncWorkflowStore,
95};