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 audit;
58pub mod context;
59pub mod conversations;
60pub mod db;
61pub mod error;
62pub mod filter;
63pub mod fts;
64pub mod hybrid;
65pub mod labels;
66pub mod memory;
67pub mod prompts;
68pub mod schema;
69pub mod tools;
70pub mod traces;
71pub mod vectors;
72pub mod workflows;
73
74pub mod mcp;
75pub mod sync;
76
77#[cfg(feature = "async")]
78pub mod async_api;
79
80#[cfg(feature = "ffi")]
81pub mod ffi;
82
83#[cfg(feature = "wasm")]
84pub mod wasm;
85
86#[cfg(feature = "wasm")]
87pub mod wasm_opfs;
88
89pub use audit::{AuditEntry, AuditStore};
90pub use context::{ContextEntry, ContextStore};
91pub use conversations::{Conversation, ConversationStore, Message, MessageSearchResult};
92pub use db::{AgentDB, DbStats};
93pub use error::{AgentDbError, Result};
94pub use filter::matches as filter_matches;
95pub use fts::{FtsResult, FullTextStore};
96pub use hybrid::{HybridQuery, HybridResult, HybridStore, TriModalQuery, TriModalResult};
97pub use labels::{DataLabel, LabelStore};
98pub use memory::{Edge, MemoryGraph, Node, TraversalOptions, TraversalResult};
99pub use prompts::{PromptStore, PromptTemplate};
100pub use tools::{Tool, ToolCall, ToolStore};
101pub use traces::{Trace, TraceStore};
102pub use vectors::{
103 BatchEntry, Collection, DistanceMetric, SearchOptions, SearchResult, VectorEntry, VectorStore,
104};
105pub use workflows::{Workflow, WorkflowStep, WorkflowStore};
106
107#[cfg(feature = "async")]
108pub use async_api::{
109 AsyncAgentDB, AsyncAuditStore, AsyncCollection, AsyncContextStore, AsyncConversationStore,
110 AsyncFullTextStore, AsyncLabelStore, AsyncMemoryGraph, AsyncPromptStore, AsyncToolStore,
111 AsyncTraceStore, AsyncVectorStore, AsyncWorkflowStore,
112};