Runnable examples, integrations, and recipes for Minigraf.
This repository is a standalone Rust examples crate. Each scenario is runnable with
Cargo and uses the published minigraf crate.
Most scenarios below also have a link to the Minigraf time travel visualizer. The link replays the scenario's writes in your browser, so you can step through its transactions and see the facts over transaction time and valid time. The browser engine has no multi-statement write transactions, so where a scenario retracts an old value and asserts the new one in one atomic transaction, the visualizer shows two transactions.
- Rust 1.89 or newer (the minimum supported Rust version of
minigraf2.x). - Cargo with access to crates.io.
minigraf = "2.0"from crates.io. Cargo currently resolves this tominigraf v2.0.2.
Install and verify dependencies:
cargo testStores user preferences and project context in Minigraf, queries them back for an agent response, then corrects the preference: one write transaction retracts the old value and asserts the new one. The old value stays in transaction-time history.
Run:
cargo run --example agentic_memoryExpected output:
Agent memory: remembered Alice prefers concise technical answers.
Agent memory: retrieved Alice's current project, minigraf-examples.
Agent memory: wrote a correction with transaction history intact.
See this scenario in the time travel visualizer → Step back to tx 1 to see what the agent remembered before the update.
Save task changes while offline and query which ones need syncing. When task 1
syncs, retract "pending" and assert "synced" in one write transaction.
The earlier status stays in transaction history.
Run:
cargo run --example offline_first_mobileExpected output:
Offline mobile: stored two local task changes while disconnected.
Offline mobile: selected the pending changes for later sync.
Offline mobile: marked the synced task without losing local history.
See this scenario in the time travel visualizer →
Store the allowed transitions as Minigraf facts and start the order in :awaiting-payment.
A Datalog query checks which events the current state allows. The example accepts
payment and rejects shipping before payment. The state update uses retract and
transact in one atomic write transaction. Use :as-of 1 to read the earlier state.
Run:
cargo run --example state_machineExpected output:
State machine: accepted payment by querying transition facts as the guard.
State machine: rejected shipping from awaiting-payment before the transition.
State machine: replayed transaction history to explain the prior state.
See this scenario in the time travel visualizer →
Press → to watch the order move from :awaiting-payment to :paid: the retract (tx 2),
then the transact (tx 3).
Record a policy approval. Retract the old owner and assert the new owner in one write transaction, then query the current and earlier owners.
Run:
cargo run --example audit_logExpected output:
Audit log: recorded policy approval and superseding revision.
Audit log: queried the current policy owner.
Audit log: queried transaction-time history for the earlier owner.
See this scenario in the time travel visualizer →
The LangChain examples use the published language bindings directly:
- Python:
minigraf==1.1.1 - Node.js:
minigraf@1.1.1
Implements BaseChatMessageHistory from langchain-core with Minigraf-backed
message storage.
Install prerequisites:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r integrations/langchain-python/requirements.txtRun:
python integrations/langchain-python/minigraf_chat_history.pyExpected output:
Human: Remember that Minigraf stores agent memory.
AI: Got it. I will use Minigraf-backed chat history.
Add minigraf-algorithms to run graph algorithms on Minigraf data. This separate
crate includes breadth-first and depth-first traversal, shortest path, topological
sort, and connected components. The database crate does not include these algorithms.
Run:
cargo test -p minigraf-algorithmsImplements BaseChatMessageHistory from @langchain/core/chat_history with
Minigraf-backed message storage.
Install prerequisites:
cd integrations/langchain-js
npm installRun:
npm startExpected output:
Human: Remember that Minigraf stores agent memory.
AI: Got it. I will use Minigraf-backed chat history.
The GraphRAG example uses Minigraf entity UUIDs as ChromaDB document IDs. It uses the UUID returned by vector search to look up that entity's neighbors in Minigraf.
- Python:
minigraf==1.1.1,chromadb
Populates a six-node concept graph in Minigraf, indexes entity descriptions in an in-memory ChromaDB collection, retrieves the closest entity by semantic similarity, then traverses its graph neighbours.
Install prerequisites:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r integrations/graphrag-python/requirements.txtNote: ChromaDB downloads the all-MiniLM-L6-v2 embedding model (~80 MB) on first run.
Run:
python integrations/graphrag-python/graphrag_minigraf.pyExpected output:
Query: "storing time-varying relationships"
Match: temporal-data
Related: graph-db, knowledge-graph
MinigrafGraphStore implements LlamaIndex's SimpleGraphStore with Minigraf as the
backing store. Triplets map to Minigraf entity-attribute-value facts. Subjects and
predicates become keywords (:myapp, :depends-on), and objects become strings.
The example stores a Python project's dependencies, upgrades one of them, then
reads the current dependencies with get_rel_map and the earlier ones with :as-of <tx>.
- Python:
minigraf==1.1.1,llama-index-core
Subclasses SimpleGraphStore from llama_index.core.graph_stores with Minigraf-backed
triplet storage. Its query() method forwards Datalog to Minigraf.
Install prerequisites:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r integrations/llamaindex-python/requirements.txtRun:
python integrations/llamaindex-python/minigraf_graph_store.pyExpected output:
myapp depends-on: pydantic==2.0, requests==2.28
requests depends-on: urllib3==1.26
myapp at tx 3 depended-on: pydantic==1.10, requests==2.28
For an interactive version of the same idea, open the dependency upgrades sample in the time travel visualizer and step through the releases.
Temporal model: Each upsert_triplet call is one Minigraf transaction. After three
ingestion calls, SNAPSHOT_TX = 3. Retracting and re-asserting a dependency advances the
transaction counter. (query [:find ?o :as-of 3 :where [:myapp :depends-on ?o]]) returns
the dependency set as it existed after transaction 3 — before the upgrade.
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.