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