Skip to main content

Crate agentdb

Crate agentdb 

Source
Expand description

§AgentDB

A single-file embedded database for AI agents.

Eight layers, one file, zero servers:

LayerWhat it gives you
Relational SQL (SQLite)Full SQL engine, ACID, WAL, user-defined tables
HNSW Vector SearchANN search, cosine/euclidean/dot, batch upsert
Memory Graph (recursive CTE)Typed nodes, weighted edges, recursive CTE traversal
FTS5 Full-Text SearchFTS5 virtual tables, BM25 ranking, Porter stemmer
Hybrid Graph + Vector QueriesGraph traversal + vector ANN with alpha blending
ConversationsThreaded message history with role and metadata
Workflow PersistenceDurable multi-step agent workflow state
Reasoning TracesStructured chain-of-thought and trace logging

§Quick start

use agentdb::{AgentDB, VectorEntry, SearchOptions, DistanceMetric};
use serde_json::json;

let db = AgentDB::open(":memory:").unwrap();

// SQL
db.execute("CREATE TABLE sessions (id TEXT PRIMARY KEY)").unwrap();

// Vectors
let col = db.vectors().collection("thoughts", 4).unwrap();
col.upsert(VectorEntry {
    id: "t1".into(),
    vector: vec![0.9, 0.1, 0.0, 0.0],
    metadata: Some(json!({ "score": 9 })),
}).unwrap();

// Memory graph
let graph = db.memory();
graph.add_node("s1", "session", None).unwrap();
graph.add_node("t1", "thought", None).unwrap();
graph.add_edge("s1", "t1", "recalled", 0.9).unwrap();

// Stats
let stats = db.stats().unwrap();
println!("nodes={} edges={}", stats.nodes, stats.edges);

§Feature flags

FlagWhat it enables
asyncTokio async runtime wrappers
ffiC FFI flat API (extern "C" functions in src/ffi.rs)
pythonPyO3 Python bindings (enables ffi)
wasmWASM/wasm-bindgen target

Re-exports§

pub use audit::AuditEntry;
pub use audit::AuditStore;
pub use context::ContextEntry;
pub use context::ContextStore;
pub use conversations::Conversation;
pub use conversations::ConversationStore;
pub use conversations::Message;
pub use conversations::MessageSearchResult;
pub use db::AgentDB;
pub use db::DbStats;
pub use error::AgentDbError;
pub use error::Result;
pub use filter::matches as filter_matches;
pub use fts::FtsResult;
pub use fts::FullTextStore;
pub use hybrid::HybridQuery;
pub use hybrid::HybridResult;
pub use hybrid::HybridStore;
pub use hybrid::TriModalQuery;
pub use hybrid::TriModalResult;
pub use labels::DataLabel;
pub use labels::LabelStore;
pub use memory::Edge;
pub use memory::MemoryGraph;
pub use memory::Node;
pub use memory::TraversalOptions;
pub use memory::TraversalResult;
pub use prompts::PromptStore;
pub use prompts::PromptTemplate;
pub use tools::Tool;
pub use tools::ToolCall;
pub use tools::ToolStore;
pub use traces::Trace;
pub use traces::TraceStore;
pub use vectors::BatchEntry;
pub use vectors::Collection;
pub use vectors::DistanceMetric;
pub use vectors::SearchOptions;
pub use vectors::SearchResult;
pub use vectors::VectorEntry;
pub use vectors::VectorStore;
pub use workflows::Workflow;
pub use workflows::WorkflowStep;
pub use workflows::WorkflowStore;

Modules§

audit
context
conversations
db
error
filter
fts
hybrid
labels
mcp
MCP (Model Context Protocol) Server Interface
memory
prompts
schema
sync
Sync Module
tools
traces
vectors
workflows