8000 GitHub - project-minigraf/minigraf-examples: Examples, integrations, and cookbooks for Minigraf — part of the Minigraf ecosystem · GitHub
[go: up one dir, main page]

Skip to content

About

Examples, integrations, and cookbooks for Minigraf — part of the Minigraf ecosystem

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

minigraf-examples

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.

Prerequisites

  • Rust 1.89 or newer (the minimum supported Rust version of minigraf 2.x).
  • Cargo with access to crates.io.
  • minigraf = "2.0" from crates.io. Cargo currently resolves this to minigraf v2.0.2.

Install and verify dependencies:

cargo test

Scenarios

Agentic Memory

Stores 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_memory

Expected 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.

Offline-First Mobile

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_mobile

Expected 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 →

State Machine

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_machine

Expected 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).

Audit Log

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_log

Expected 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 →

LangChain Integrations

The LangChain examples use the published language bindings directly:

  • Python: minigraf==1.1.1
  • Node.js: minigraf@1.1.1

Python LangChain

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.txt

Run:

python integrations/langchain-python/minigraf_chat_history.py

Expected output:

Human: Remember that Minigraf stores agent memory.
AI: Got it. I will use Minigraf-backed chat history.

Optional Crates

minigraf-algorithms

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-algorithms

LangChain.js

Implements BaseChatMessageHistory from @langchain/core/chat_history with Minigraf-backed message storage.

Install prerequisites:

cd integrations/langchain-js
npm install

Run:

npm start

Expected output:

Human: Remember that Minigraf stores agent memory.
AI: Got it. I will use Minigraf-backed chat history.

GraphRAG Integration

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

Python GraphRAG

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.txt

Note: ChromaDB downloads the all-MiniLM-L6-v2 embedding model (~80 MB) on first run.

Run:

python integrations/graphrag-python/graphrag_minigraf.py

Expected output:

Query: "storing time-varying relationships"
Match: temporal-data
Related: graph-db, knowledge-graph

LlamaIndex Integration

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

Python LlamaIndex

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.txt

Run:

python integrations/llamaindex-python/minigraf_graph_store.py

Expected 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.

License

Licensed under either of:

at your option.

Contribution

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.

About

Examples, integrations, and cookbooks for Minigraf — part of the Minigraf ecosystem

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0