pub struct AgentDB { /* private fields */ }Expand description
The main AgentDB connection — your single-file AI database.
Implementations§
Source§impl AgentDB
impl AgentDB
Sourcepub fn open(path: &str) -> Result<Self>
pub fn open(path: &str) -> Result<Self>
Open or create an AgentDB database. Use ":memory:" for tests.
Sourcepub fn vectors(&self) -> VectorStore
pub fn vectors(&self) -> VectorStore
Access the vector store layer
Sourcepub fn memory(&self) -> MemoryGraph
pub fn memory(&self) -> MemoryGraph
Access the memory graph layer
Sourcepub fn fts(&self) -> FullTextStore
pub fn fts(&self) -> FullTextStore
Access the full-text search layer
Sourcepub fn conversations(&self) -> ConversationStore
pub fn conversations(&self) -> ConversationStore
Access the conversation / message-threading layer
Sourcepub fn workflows(&self) -> WorkflowStore
pub fn workflows(&self) -> WorkflowStore
Access the workflow persistence layer
Sourcepub fn traces(&self) -> TraceStore
pub fn traces(&self) -> TraceStore
Access the reasoning-trace layer
Sourcepub fn audit(&self) -> AuditStore
pub fn audit(&self) -> AuditStore
Access the immutable audit log
Sourcepub fn context(&self) -> ContextStore
pub fn context(&self) -> ContextStore
Access the token-budgeted context window manager
Sourcepub fn prompts(&self) -> PromptStore
pub fn prompts(&self) -> PromptStore
Access the versioned prompt template store
Sourcepub fn labels(&self) -> LabelStore
pub fn labels(&self) -> LabelStore
Access the data classification / privacy label store
Sourcepub fn tri_modal_query(&self, q: &TriModalQuery) -> Result<Vec<TriModalResult>>
pub fn tri_modal_query(&self, q: &TriModalQuery) -> Result<Vec<TriModalResult>>
Run a tri-modal graph + vector + FTS query
Sourcepub fn hybrid_query(&self, q: HybridQuery<'_>) -> Result<Vec<HybridResult>>
pub fn hybrid_query(&self, q: HybridQuery<'_>) -> Result<Vec<HybridResult>>
Run a hybrid graph + vector query
Sourcepub fn execute_params(&self, sql: &str, params: &[&dyn ToSql]) -> Result<usize>
pub fn execute_params(&self, sql: &str, params: &[&dyn ToSql]) -> Result<usize>
Execute a parameterized SQL statement
Sourcepub fn transaction<F, T>(&self, f: F) -> Result<T>
pub fn transaction<F, T>(&self, f: F) -> Result<T>
Run multiple operations atomically inside a single SQLite transaction.
The closure receives a rusqlite::Transaction and may perform any
number of reads or writes. If the closure returns Ok, the transaction
is committed; if it returns Err (or panics), the transaction is rolled
back automatically.
§Example
let db = AgentDB::open(":memory:").unwrap();
db.transaction(|tx| {
tx.execute("INSERT INTO _adb_nodes (id, kind, data, created_at, updated_at) VALUES ('x','tag','{}',0,0)", [])?;
tx.execute("INSERT INTO _adb_nodes (id, kind, data, created_at, updated_at) VALUES ('y','tag','{}',0,0)", [])?;
Ok(())
}).unwrap();Sourcepub fn execute_batch(&self, sql: &str) -> Result<()>
pub fn execute_batch(&self, sql: &str) -> Result<()>
Execute one or more semicolon-separated SQL statements as a single
atomic batch. This is a convenience wrapper around
execute_batch that wraps the
statements in an explicit transaction so partial execution is never
visible to other threads.
§Example
let db = AgentDB::open(":memory:").unwrap();
db.execute_batch(
"INSERT INTO _adb_nodes (id,kind,data,created_at,updated_at) VALUES ('a','t','{}',0,0);
INSERT INTO _adb_nodes (id,kind,data,created_at,updated_at) VALUES ('b','t','{}',0,0);"
).unwrap();Sourcepub fn query_json_params(
&self,
sql: &str,
params: &[&dyn ToSql],
) -> Result<Vec<Value>>
pub fn query_json_params( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<Vec<Value>>
Query with parameters and return rows as JSON values.
Use this for any query involving user-supplied values to prevent SQL injection.
§Example
let db = AgentDB::open(":memory:").unwrap();
let rows = db.query_json_params(
"SELECT * FROM _adb_nodes WHERE kind = ?1",
&[&"session" as &dyn rusqlite::ToSql],
).unwrap();