← First Pair Library

18 Rust Examples

The Rust examples are the reference implementation. They show the system from the operator and platform-engineering side: load real data, materialize typed tables, generate semantic metadata, enforce rights, run agents, and emit audit evidence.

18.1 Build a Four-Layer Semantic Bundle

The smallest useful Rust run builds the original AI Navigator bundle:

cargo run -- navigator \
  --dataset-name "Hazard vocabulary" \
  --description "Controlled vocabulary with multilingual technical terms" \
  --landing-page "https://querygraph.ai/datasets/hazards" \
  --data-url "https://querygraph.ai/datasets/hazards.csv" \
  --creator "QueryGraph" \
  --agent-name "AI Navigator"

That command produces a JSON-LD bundle with:

This is the seed pattern for every richer workflow. A dataset should always enter the agent world with shape, publication metadata, identity, and policy.

18.2 Load and Verify the Sail Warehouse

The lakehouse loader is the Rust example that proves Querygraph can handle more than toy JSON:

cargo run -- lakehouse-load \
  --root .querygraph/lakehouse \
  --schema qg_lakehouse

cargo run -- lakehouse-verify \
  --report .querygraph/lakehouse/manifest/load-report.json

cargo run -- lakehouse-validate \
  --report .querygraph/lakehouse/manifest/load-report.json

The loader downloads Dataverse and CODATA assets, prepares parseable files, infers column types, writes Sail tables, emits Croissant/CDIF sidecars, and records row counts in a manifest. The verifier checks that the executable data matches the report. The validator checks that the semantic sidecars and audit shapes are still usable.

18.3 Run the Supervised Agent Story

The readable story:

cargo run -- qglake-story

The machine report:

cargo run -- qglake-story --json

The Rust story is intentionally elaborate. It creates a supervisor, specialist agents, restricted broker, synthesis agent, TypeDID requests and responses, RBAC and ODRL receipts, Semantic Croissant and CDIF projections, an OpenLineage event, and a DID attestation. It demonstrates the product rule: aggregate signed summaries without collapsing raw-data boundaries.

18.4 Run the Live Sail, TypeDID, OpenLineage, and Ollama Path

With Sail running:

sail spark server --port 50051

Run the live end-to-end path:

cargo run -- dataverse-e2e \
  --live-sail \
  --sail-endpoint http://127.0.0.1:50051 \
  --openlineage-file .querygraph/openlineage/events.jsonl \
  --did-ledger-file .querygraph/did-ledger/attestations.jsonl

When Ollama is available, the same path can wrap model inference through TypeDID. The important property is the order: semantic target first, policy decision second, typed capability third, model call fourth, lineage fifth.

18.5 Rust as the Contract

The Rust examples define the contract that other languages should preserve. Python may be more comfortable for notebooks and agent composition, but it should not silently change CDIF shape, policy semantics, payload hashes, or lineage meaning. That is why qg-python includes an equivalence test against the Rust navigator command.