Skip to main content

AgentDB

Struct AgentDB 

Source
pub struct AgentDB { /* private fields */ }
Expand description

The main AgentDB connection — your single-file AI database.

Implementations§

Source§

impl AgentDB

Source

pub fn open(path: &str) -> Result<Self>

Open or create an AgentDB database. Use ":memory:" for tests.

Source

pub fn vectors(&self) -> VectorStore

Access the vector store layer

Source

pub fn memory(&self) -> MemoryGraph

Access the memory graph layer

Source

pub fn fts(&self) -> FullTextStore

Access the full-text search layer

Source

pub fn conversations(&self) -> ConversationStore

Access the conversation / message-threading layer

Source

pub fn workflows(&self) -> WorkflowStore

Access the workflow persistence layer

Source

pub fn traces(&self) -> TraceStore

Access the reasoning-trace layer

Source

pub fn hybrid_query(&self, q: HybridQuery<'_>) -> Result<Vec<HybridResult>>

Run a hybrid graph + vector query

Source

pub fn execute(&self, sql: &str) -> Result<usize>

Execute a raw SQL statement

Source

pub fn execute_params(&self, sql: &str, params: &[&dyn ToSql]) -> Result<usize>

Execute a parameterized SQL statement

Source

pub fn transaction<F, T>(&self, f: F) -> Result<T>
where F: FnOnce(&Transaction<'_>) -> 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();
Source

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();
Source

pub fn query_json(&self, sql: &str) -> Result<Vec<Value>>

Query and return rows as JSON values

Source

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();
Source

pub fn close(self) -> Result<()>

Flush dirty HNSW indexes and close gracefully.

After this returns, the subsequent Drop is a no-op (no double flush).

Source

pub fn stats(&self) -> Result<DbStats>

Return database-wide statistics (single-query implementation).

Trait Implementations§

Source§

impl Clone for AgentDB

Source§

fn clone(&self) -> AgentDB

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for AgentDB

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V