Run contextdb in under a minute.
Download the latest release for your platform from GitHub Releases:
# Linux x86_64
curl -fsSL https://github.com/context-graph-ai/contextdb/releases/latest/download/x86_64-unknown-linux-gnu.tar.gz | tar xz
# Linux ARM64
curl -fsSL https://github.com/context-graph-ai/contextdb/releases/latest/download/aarch64-unknown-linux-gnu.tar.gz | tar xz
# macOS Intel
curl -fsSL https://github.com/context-graph-ai/contextdb/releases/latest/download/x86_64-apple-darwin.tar.gz | tar xz
# macOS Apple Silicon
curl -fsSL https://github.com/context-graph-ai/contextdb/releases/latest/download/aarch64-apple-darwin.tar.gz | tar xzcargo install contextdb-cliRequires Rust stable (1.75+) and Git.
git clone https://github.com/context-graph-ai/contextdb.git
cd contextdb
cargo build --release -p contextdb-clicontextdb-cli :memory:Try the state machine — the feature that makes contextdb different from plain SQL:
CREATE TABLE decisions (
id UUID PRIMARY KEY,
status TEXT NOT NULL,
reasoning TEXT
) STATE MACHINE (status: draft -> [active, rejected], active -> [superseded]);
INSERT INTO decisions (id, status, reasoning)
VALUES ('550e8400-e29b-41d4-a716-446655440000', 'draft', 'initial assessment');
-- Valid transition: draft -> active
UPDATE decisions SET status = 'active'
WHERE id = '550e8400-e29b-41d4-a716-446655440000';
-- Invalid transition: active -> draft (rejected by the database)
UPDATE decisions SET status = 'draft'
WHERE id = '550e8400-e29b-41d4-a716-446655440000';
-- Error: invalid state transition: active -> draftThe database enforces the state machine. No application code needed.
Audit-frozen columns — declare IMMUTABLE on any column whose value must never be silently rewritten after the initial INSERT:
CREATE TABLE audit_decisions (
id UUID PRIMARY KEY,
decision_type TEXT NOT NULL IMMUTABLE,
description TEXT NOT NULL IMMUTABLE,
status TEXT NOT NULL DEFAULT 'active'
);
INSERT INTO audit_decisions (id, decision_type, description)
VALUES ('550e8400-e29b-41d4-a716-446655440001', 'sql-migration', 'adopt contextdb');
-- Mutable column: succeeds
UPDATE audit_decisions SET status = 'superseded'
WHERE id = '550e8400-e29b-41d4-a716-446655440001';
-- Flagged column: rejected with Error::ImmutableColumn
UPDATE audit_decisions SET decision_type = 'other'
WHERE id = '550e8400-e29b-41d4-a716-446655440001';
-- Error: column `decision_type` on table `audit_decisions` is immutableThe row stays at its original decision_type; the session continues. To record a correction, INSERT a new row and mark the original superseded.
contextdb is designed for agents holding tens of thousands of entities with
sub-100ms filtered retrieval. Indexes accelerate filtered scans so a
10,000-row table answers WHERE tag = 'x' in microseconds instead of
milliseconds.
CREATE TABLE observations (
id UUID PRIMARY KEY,
tag TEXT,
value INTEGER
);
CREATE INDEX idx_tag ON observations (tag);
INSERT INTO observations (id, tag, value)
VALUES ('650e8400-e29b-41d4-a716-446655440010', 'pay', 1);
SELECT value FROM observations WHERE tag = 'pay';.explain shows which plan ran — IndexScan for the filtered select above,
Scan for a query whose WHERE clause does not match a declared index.
Replace :memory: with a file path. Everything else works the same:
contextdb-cli ./my.dbSingle file. Crash-safe via redb. Reopen and your data is there.
contextdb is an embedded database — the CLI is for exploration. The primary interface is the Rust API:
use contextdb_engine::Database;
use contextdb_core::Value;
use std::collections::HashMap;
let db = Database::open(std::path::Path::new("./my.db"))?;
let params = HashMap::new();
db.execute(
"CREATE TABLE observations (
id UUID PRIMARY KEY,
data JSON,
embedding VECTOR(384)
) IMMUTABLE",
¶ms,
)?;
// Insert with parameters
let mut params = HashMap::new();
params.insert("id".into(), Value::Uuid(uuid::Uuid::new_v4()));
params.insert("data".into(), Value::Json(serde_json::json!({"type": "sensor"})));
params.insert("embedding".into(), Value::Vector(vec![0.1; 384]));
db.execute(
"INSERT INTO observations (id, data, embedding) VALUES ($id, $data, $embedding)",
¶ms,
)?;Add to your Cargo.toml:
[dependencies]
contextdb-engine = "0.3.4"
contextdb-core = "0.3.4"- Why contextdb? — the problems it solves and how it compares to alternatives
- Usage Scenarios — 16 problem-first walkthroughs with SQL
- Query Language — full SQL, graph, and vector reference
- CLI Reference — REPL commands, sync, scripting