Minigraf is an embedded graph database written in Rust. It stores a graph and its history in a local .graph file, and you query it with Datalog.
Try it in your browser — no install needed →
Open the visualizer → Change the selected transaction or valid time to see the graph change.
Minigraf is a single-file embedded graph database that lets you:
- ✅ Query relationships with Datalog - Follow relationships across multiple hops with recursive rules
- ✅ Query both timelines - Filter by when a fact applied (valid time) and when it was recorded (transaction time)
- ✅ Window functions -
sum/count/min/max/avg/rank/row-number :over (partition-by … :order-by …)in:findclauses - ✅ Prepared statements - Parse a query with
$slotparameters once, then run it with different values - ✅ Run inside your application - See supported platforms
- ✅ Zero configuration - Open a local database with
Minigraf::open("data.graph"); no database server or config file is needed
Status: See ROADMAP.md for planned work and current direction.
In v2, the ordinary aggregates are count, count-distinct, sum, sum-distinct, min and max. Average is available only as a window function, for example (avg ?score :over (:order-by ?score)) (#777).
With Datalog, you can describe how to follow a link once and let a recursive rule repeat that step. In the Quick Start, the two reachable rules find friends by following one or more :friend links.
A fact can link two entities, as in [:alice :friend :bob], or store a value on one entity, as in [:alice :person/name "Alice"]. The Quick Start below inserts both facts with transact. Queries can match either kind of fact and filter the results by valid time or transaction time.
[dependencies]
minigraf = "2.0.12"Or via cargo:
cargo add minigrafRequires Rust 1.89 or newer (the minimum supported Rust version, set in Cargo.toml).
Bugs present in the current release, with affected versions, workarounds and fix versions, are listed in the pinned Known issues in the current release issue. The most important one on v2.x:
- Two values of the same attribute for one entity written in a single
transact(or retracted in a singleretract) can read back as one value (#371). Write or retract each value of a multi-valued attribute in its own call. The fix changes the file format and ships in v3.0.0.
v2.x gets all bug fixes, including data-integrity and security fixes, but no new features, until 12 months after v3.0.0 final ships. Prereleases do not start that clock. See the support policy.
use minigraf::{Minigraf, OpenOptions};
// Open or create a file-backed database
let db = OpenOptions::new().path("myapp.graph").open()?;
// Add facts
db.execute(r#"(transact [[:alice :person/name "Alice"]
[:alice :person/age 30]
[:alice :friend :bob]
[:bob :person/name "Bob"]])"#)?;
// Query with Datalog
let results = db.execute(r#"
(query [:find ?friend-name
:where [:alice :friend ?friend]
[?friend :person/name ?friend-name]])
"#)?;
// Explicit transaction — all-or-nothing
let mut tx = db.begin_write()?;
tx.execute(r#"(transact [[:alice :person/age 31]])"#)?;
tx.commit()?;
// Time travel — query as of past transaction counter
db.execute("(query [:find ?age :as-of 1 :where [:alice :person/age ?age]])")?;
// Recursive rule — register each clause with a separate execute() call
db.execute("(rule [(reachable ?a ?b) [?a :friend ?b]])")?;
db.execute("(rule [(reachable ?a ?b) [?a :friend ?m] (reachable ?m ?b)])")?;
db.execute("(query [:find ?friend :where (reachable :alice ?friend)])")?;
// Prepared statement — parse + plan once, execute many times
use minigraf::{BindValue, EntityId};
// Keywords map to UUIDv5 IDs in the OID namespace, including the leading colon.
let alice_id = EntityId::new_v5(&EntityId::NAMESPACE_OID, b":alice");
let bob_id = EntityId::new_v5(&EntityId::NAMESPACE_OID, b":bob");
let pq = db.prepare("(query [:find ?name :as-of $tx :where [$entity :person/name ?name]])")?;
let r1 = pq.execute(&[("tx", BindValue::TxCount(1)), ("entity", BindValue::Entity(alice_id))])?;
let r2 = pq.execute(&[("tx", BindValue::TxCount(2)), ("entity", BindValue::Entity(bob_id))])?;cargo run # interactive Datalog REPL
cargo test # 1335 tests (1326 passing, 9 ignored)
cargo run < demos/demo_recursive.txt # recursive rules demoSee a working implementation of temporal reasoning with Minigraf at github.com/project-minigraf/temporal_reasoning — an AI agent that uses Minigraf's bi-temporal model to store, correct, and audit beliefs.
The time travel visualizer runs Minigraf in your browser and draws its history. Step through transactions, move the valid-time cursor, and see each fact version on a bitemporal map. It opens .graph files too. For example, see a salary that was recorded wrong and then corrected.
See the Datalog Reference for the complete syntax.
Here is how Minigraf compares with a few other databases:
| Feature | Minigraf | XTDB | Cozo | Neo4j | SQLite |
|---|---|---|---|---|---|
| Query Language | Datalog | Datalog | Datalog | Cypher | SQL |
| Single File | ✅ Yes | ❌ No | ❌ No | ❌ No | ✅ Yes |
| Bi-temporal | ✅ Yes | ✅ Yes | ❌ No | ❌ No | |
| Embedded | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes |
| Rust | ✅ Yes | ❌ Clojure | ✅ Yes | ❌ Java | ❌ C |
| WebAssembly support | ✅ Yes (browser + WASI) | ❌ No | ❌ No | ✅ Yes |
| Platform | Tier | Package | Install |
|---|---|---|---|
| Rust (native) | 1 | minigraf on crates.io |
cargo add minigraf |
| Python | 1 | minigraf on PyPI |
pip install minigraf |
| Browser WASM | 2 (experimental) | @minigraf/browser on npm |
npm install @minigraf/browser |
| WASI | 2 (experimental) | @minigraf/wasi on npm |
npm install @minigraf/wasi |
| Node.js | 2 (experimental) | minigraf on npm |
npm install minigraf |
| Java/JVM | 2 (experimental) | io.github.project-minigraf:minigraf-jvm on Maven Central |
see docs |
| Android | 2 (experimental) | io.github.project-minigraf:minigraf-android (.aar) on Maven Central |
see docs |
| iOS / macOS | 2 (experimental) | .xcframework via Swift Package Manager (minigraf-swift) |
see docs |
| C / FFI | 2 (experimental) | header + tarball on minigraf-c releases | see docs |
All bindings, including Tier 2, publish for each core release. Their versions match the core version, using each package registry’s version spelling for prereleases. A binding that cannot publish blocks the release. Tier 1 bindings are fully tested. Tier 2 bindings are experimental, built and smoke-tested in their own repos. A binding moves to Tier 1 when real users need it. Tier 1 operating systems and filesystems are Linux (ext4, xfs), macOS (APFS) and Windows (NTFS) on local disk; NFSv4 is supported with caveats, and NFSv3 nolock is unsupported for multiple writers. Details: support tiers.
| Language | Package | Repo |
|---|---|---|
| Python | minigraf on PyPI |
minigraf-python |
| Node.js | minigraf on npm |
minigraf-node |
| Browser WASM | @minigraf/browser on npm |
minigraf-wasm |
| WASI | @minigraf/wasi on npm |
minigraf-wasm |
| Java | io.github.project-minigraf:minigraf-jvm on Maven Central |
minigraf-java |
| Android | io.github.project-minigraf:minigraf-android on Maven Central |
minigraf-android |
| iOS/macOS | Swift bindings | minigraf-swift |
| C | C bindings | minigraf-c |
See the Comparison page for detailed analysis including temporal vs. time-series databases.
Record the facts an agent uses to make a decision. If a fact is corrected later, query by transaction time to see what the database had recorded when the agent made the decision. Use valid time to choose the time those facts describe.
If you use a vector store to find similar items, use Minigraf to store facts about those items and query how they are connected.
See it in the visualizer: what an agent believed when it made a recommendation, and the correction that followed (press → to step forward).
Offline-first storage with retroactive corrections — the bi-temporal model lets you correct a mis-entered value while preserving the original record (see a correction in the visualizer). Native Kotlin and Swift bindings ship as an Android .aar (Maven Central) and an iOS .xcframework (Swift Package Manager) via UniFFI. No Rust required.
// Android (Kotlin)
val db = MiniGrafDb.open(context.filesDir.absolutePath + "/myapp.graph")
db.execute("""(transact [[:alice :person/name "Alice"] [:alice :person/age 30]])""")
val json = db.execute("(query [:find ?name :where [?e :person/name ?name]])")// iOS (Swift)
let db = try MiniGrafDb.open(path: docsURL.appendingPathComponent("myapp.graph").path)
try db.execute(datalog: #"(transact [[:alice :person/name "Alice"] [:alice :person/age 30]])"#)
let json = try db.execute(datalog: "(query [:find ?name :where [?e :person/name ?name]])")See the Mobile Integration section for full setup and usage docs (Gradle config, SPM integration, error handling, threading).
From v2.0.12 (#894): after an IndexedDB flush fails, later
writes, checkpoints and imports reject with STG-046. Discard the handle and
reopen to recover the successful prefix before the failure. Queries, rules and
export remain usable; export includes rejected work still held in memory and
does not acknowledge durability. See the changelog
and error reference.
Published as @minigraf/browser on npm (IndexedDB-backed, wasm-pack). WASI build (wasm32-wasip1) available as @minigraf/wasi on npm and as a GitHub Releases artifact (Wasmtime / Wasmer). See the Use Cases. The playground and the time travel visualizer are both built on @minigraf/browser.
Language bindings ship as minigraf on PyPI, minigraf on npm (Node.js native addon), io.github.project-minigraf:minigraf-jvm on Maven Central, and a C header + prebuilt shared library on GitHub Releases. See the Use Cases.
Minigraf runs as:
- ✅ An embedded library
- ✅ A standalone binary (interactive REPL)
- ✅ Browser WASM —
@minigraf/browser(IndexedDB-backed,wasm-pack) - ✅ Server-side WASM —
wasm32-wasip1/ WASI (Wasmtime, Wasmer, Cloudflare Workers) - ✅ Android, iOS, Python, Node.js, Java, C — via UniFFI / napi-rs / cbindgen
Minigraf will not be (by design):
- Distributed — no clustering, no sharding, no replication; each agent instance owns its own
.graphfile - Client-server — no network protocol in core
- Billion-node scale — optimised for <1M nodes (like SQLite)
- A time-series database — Minigraf is a temporal database; see Comparison
See ROADMAP.md for planned work and current direction.
See BENCHMARKS.md for the current reproducible local snapshot and benchmark commands. | Point query at 1M facts | 4.3–4.5 s (selective B+tree lookup for bounded patterns; O(N) for full-attribute scans) | | Open time at 1M facts | 1.31 s (2.4× faster than v5 — indexes no longer loaded into RAM) | | Peak heap at 1M facts | 1.05 GB (~21% less than v5 — indexes paged in on demand) |
File-backed databases enforce a maximum fact size of 4 080 serialised bytes per fact. In-memory databases have no limit.
Durability tuning: every write is fsync'd immediately by default (SyncMode::Full). Bulk loaders/migrations that can safely re-run from a checkpoint watermark on failure can trade that for throughput with OpenOptions::new().synchronous(SyncMode::Normal) — checkpoint() still fsyncs unconditionally in both modes. See the Performance Tuning for the full tradeoff and the write-batching pattern that pairs with it.
This is a solo-maintained project with a long-term vision. Read PHILOSOPHY.md and ROADMAP.md before proposing features.
See CONTRIBUTING.md for development setup, code standards, and the PR process.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.