Leanpub Header

Skip to main content

Rusty Graphs - AI Ready Graphs for Rust Developers

Rusty Graphs - AI Ready Graphs for Rust Developers

Language models guess. Knowledge graphs know. Rusty Graph shows you how to build a local AI agent whose memory is a real knowledge graph — typed, validated, reasoned over, and queryable with SPARQL — all inside a single static Rust binary. No JVM. No Docker sidecar. No Python runtime bolted to the side. You will build Ares a research-assistant agent that observes papers, forms beliefs, makes promises to other agents, and tracks the provenance of every fact it holds. Chapter by chapter, Ares grows from an empty Cargo workspace into a full pipeline: > load → reason → validate → query → answer All of it in under a thousand lines of idiomatic Rust, using three crates that actually work today: `oxigraph`, `reasonable`, and `rudof_lib`. `grapfeo` You will learn how to

- Model a domain as RDF triples and load them into an embedded store. - Write RDFS and OWL 2 RL axioms that infer trust, identity, and inverse relationships — automatically. - Guard your graph with SHACL shapes that reject bad data at the boundary, not in production. - Query everything with SPARQL, from simple lookups to federated queries across named graphs. - Wire the graph into a hybrid RAG pipeline so your LLM answers are grounded in facts, not vibes. Who it is for

Rust developers building agents, assistants, or any system where the answer "the model said so" is not good enough. You should be comfortable with Cargo and traits. You do **not** need any prior semantic-web background — every concept is introduced through Ares before any formal definition appears. Why Rust, why now

Local agents are the next deployment target: a user's laptop, a Raspberry Pi, a WASM sandbox. Python cannot go there comfortably. Rust can. This book is the missing manual for the Rust side of the semantic web — the one that tells you exactly which crates work, where the ecosystem is thin, and how to ship anyway. Stop hoping your model tells the truth. Give it a graph that does.

Minimum price

$24.67

$45.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

Most agentic AI stacks live in Python. That is fine for a notebook and
painful for anything you want to ship next to a user. Local agents need
three things Python makes hard and Rust makes easy: a single static
binary, predictable memory, and an embedded database that rides inside
the process — no JVM, no Docker sidecar, no server to babysit.


Graphs are the other half of the story. A language model hallucinates
plausibly; a knowledge graph tells you what is *true* about your world —
the tickets, the documents, the promises between agents, the provenance
of every belief. Vector search tells you what is similar. A graph tells
you what is real.


This book teaches you to build that graph in Rust, end to end. You will
work through four pillars of the semantic web toolbox in the order a
working agent actually needs them:


- RDF — the data model: a graph of facts made of triples.
- RDFS and OWL — the schema and the reasoner.
- SHACL — the constraints that guard the boundary of your system.
- SPARQL — the query language that ties it all together.

- LPG. - property graphs


Everything happens inside a single Cargo workspace, driven by one
running example: Ares a research-assistant agent whose memory
graph observes papers, forms beliefs, makes promises to other agents,
and tracks the provenance of every claim. By the final chapter you
will have a working binary that loads its own schema, runs an OWL 2 RL
reasoner over its own data, validates the result against SHACL shapes,
and emits a JSON report — all in under a thousand lines of Rust.


What makes this book different


- Rust-native, not a Java port.Every example uses `oxigraph`,
`reasonable`, and `rudof_lib` — three maintained crates that cover
enough of the W3C stack to build a real agent memory. Where the
Rust ecosystem is thin, the book says so plainly and shows the
workaround. No hand-waving.
- One example, cumulative. Ares grows chapter by chapter. You
learn each new concept by adding one axiom to a schema you already
understand, not by re-reading a fresh `foo`/`bar` example every time.
- Agent-first framing.Every concept is introduced through the
problem it solves for a local agent: identity, trust, provenance,
validation, hybrid retrieval.
- Hybrid RAG, done right.The final chapter wires the graph into
a hybrid retrieval pipeline that combines vector search with
SPARQL-grounded answers — the architecture you actually want in
production.


Who this book is for


You write Rust. You have shipped at least one non-trivial Cargo
project. You have heard of RDF and SPARQL but never used them in
anger — or you have used them in Java or Python and want the same
power without the JVM. You are building something with the word
"agent" in its design document.


You do not need a background in description logic, linked data,
or the semantic web. Every term is defined in plain English the first
time it appears, and every concept is motivated by Ares before any
formal definition shows up.


What you will build


- A Cargo workspace with three library crates (`graph`, `reasoner`,
`validator`) and a binary (`ares`) that drives them.
- A Turtle schema for agents, observations, beliefs, promises, and
provenance.
- An OWL 2 RL ontology that infers trust transitivity, inverse
observations, and identity across DOI and arXiv URLs.
- A SHACL shape file that rejects malformed observations before they
reach the store.
- A full pipeline — load, reason, validate, report — with a `--strict`
flag for CI.
- A hybrid RAG layer that grounds LLM output against the graph.

Author

About the Author

Volodymyr Pavlyshyn

Hey I am Volodymyr 

Seasoned Developer's Journey from COBOL to Web 3.0, SSI, Privacy First Edge AI, and Beyond

 As a seasoned developer with over 20 years of experience, I have worked with various programming languages, including some that are considered "dead," such as COBOL and Smalltalk. However, my passion for innovation and embracing cutting-edge technology has led me to focus on the emerging fields of Web 5.0, Self-Sovereign Identity (SSI),AI Agents, Knowledge Graphs, Agentiic memory systems, and the architecture of a decentralized world that empowers data democratization.

A firm believer in the potential of agent systems and the concept of a "soft" internet, I am dedicated to exploring and promoting these transformative ideas. In addition to writing, I also enjoy sharing my knowledge and insights through videoblogging. Most of my Medium posts serve as supplementary content to the videos on my YouTube channel, which you can explore here: https://www.youtube.com/c/VolodymyrPavlyshyn. 

Join me on this exciting journey as we delve into the future of technology and the possibilities it holds.

Contents

Table of Contents

About this book

  1. The story
  2. Three acts
  3. Why Rust
  4. Why graphs matter for AI agents
  5. Who this book is for
  6. What you will build
  7. How to read this book

Chapter 0 — Setup

  1. Meet the agents
  2. The workspace layout
  3. The workspace root Cargo.toml
  4. The toolchain
  5. The three library crates
  6. The binary: ares
  7. The first data files
  8. Verify the scaffold compiles
  9. What We Learned
  10. Exercise
  11. Next

Chapter 1 — RDF Foundations via Agent Memory

  1. The story so far
  2. The motivating problem
  3. The three pieces: triple, IRI, literal
  4. Turtle shorthand
  5. Extend data/data.ttl
  6. Named graphs: provenance without pain
  7. Grow the graph crate
  8. Write the chapter’s binary code
  9. Run it
  10. What We Learned
  11. Exercise
  12. Next

Chapter 2 — RDF Schema: Typing the Agent World

  1. The story so far
  2. The motivating problem
  3. RDFS in four triples
  4. Write schema.ttl
  5. Property paths: subclass hierarchies without a reasoner
  6. Write ch2.rs
  7. Run it
  8. What SPARQL cannot do
  9. What could go wrong
  10. What We Learned
  11. Exercise
  12. Next

Chapter 3 — OWL Reasoning with reasonable

  1. The story so far
  2. The motivating problem
  3. What OWL and OWL 2 RL mean
  4. Extend schema.ttl with OWL axioms
  5. Extend data.ttl
  6. Fill in the reasoner crate
  7. Write ch3.rs
  8. Run it
  9. What could go wrong
  10. What We Learned
  11. Exercise
  12. Next

Chapter 4 — Named Graphs and Quad Stores for Provenance

  1. The story so far
  2. The motivating problem
  3. Datasets and quads, formally
  4. Our graph layout
  5. The SPARQL GRAPH keyword
  6. SPARQL UPDATE
  7. Write ch4.rs
  8. Run it
  9. A word on string interpolation in SPARQL
  10. What We Learned
  11. Exercise
  12. Next

Chapter 4A — Advanced SPARQL for Agent Memory

  1. The running dataset
  2. The shape of a SPARQL query
  3. Querying one named graph
  4. Querying every named graph
  5. The default graph is not a named graph
  6. FROM and FROM NAMED
  7. OPTIONAL: missing facts without losing the row
  8. VALUES: small tables inside the query
  9. Aggregates and grouping
  10. Nested queries: subqueries as query boundaries
  11. EXISTS, NOT EXISTS, and MINUS
  12. Property paths
  13. Property-graph-shaped RDF
  14. Joining graph metadata with edge-like facts
  15. CONSTRUCT: returning a graph
  16. Building a report query
  17. Querying absence without lying to yourself
  18. Dates, datatypes, and casts
  19. Pagination and stable ordering
  20. Performance habits
  21. Rust integration notes
  22. A final worked query
  23. What We Learned
  24. Exercise
  25. Next

Chapter 4B - JSON-LD: Documents That Become Graphs

  1. JSON is syntax; JSON-LD adds meaning
  2. The three important JSON-LD keywords
  3. Compact, expanded, and flattened forms
  4. Documents and graphs at the same time
  5. Loading JSON-LD into Oxigraph
  6. Contexts are dependencies
  7. Verifiable Credentials as JSON-LD
  8. Querying credentials in named graphs
  9. Complex JSON-LD documents
  10. Arrays, lists, and sets
  11. Language and datatype values
  12. Querying across JSON-LD and Turtle
  13. JSON-LD, SHACL, and the boundary
  14. Design rules for JSON-LD in agent systems
  15. A full query pipeline
  16. What We Learned
  17. Exercise
  18. Next

Chapter 5 — SHACL: Constraining the Agent Knowledge Graph

  1. The story so far
  2. The motivating problem
  3. SHACL in one paragraph
  4. Write shapes.ttl
  5. Fill in the validator crate
  6. Deliberately broken data
  7. Write ch5.rs
  8. Run it
  9. Decision point: ShEx or SHACL?
  10. What could go wrong
  11. What We Learned
  12. Exercise
  13. Next

Chapter 6 — SHACL-SPARQL: Constraints That Reason

  1. The story so far
  2. The motivating problem
  3. What a sh:sparql shape looks like
  4. The rudof_lib 0.2 gap
  5. The data we will violate
  6. Write ch6.rs
  7. Run it
  8. Performance note
  9. What could go wrong
  10. What We Learned
  11. Exercise
  12. Next

Chapter 7 — Putting It All Together: The Full Pipeline

  1. The story so far
  2. The pipeline, in six steps
  3. A typed report
  4. Add serde to the binary
  5. Write ch7.rs
  6. Run it
  7. CI integration
  8. Limitations you should know about
  9. What We Learned
  10. Exercise
  11. The question the pipeline cannot answer
  12. Next

Chapter 8 — Shape Languages and the Road Ahead

  1. Act II is complete
  2. Why compare ShEx and SHACL
  3. A concrete disagreement
  4. Extend the workspace
  5. The ShEx version
  6. Extend the validator crate
  7. Write ch8.rs
  8. Run it
  9. A decision guide
  10. What We Learned
  11. Exercise
  12. What happens next: Act III

Chapter 9 — A Second Engine: oxilite, RDF on SQLite

  1. The story so far
  2. The motivating problem
  3. What oxilite is, in one page
  4. Installing oxilite
  5. Opening a store
  6. Loading the same Turtle files
  7. The Chapter 1 query, unchanged
  8. What did that compile to?
  9. The data is in the file
  10. Reasoning, two ways
  11. Things to know before you switch
  12. Why a trait, and why now
  13. What to keep from this chapter

Chapter 10 — Validation Inside the Store

  1. The story so far
  2. How it works
  3. Running the Chapter 5 shapes
  4. Reason, then validate
  5. ShEx over the same store
  6. Validate before you commit
  7. Shapes as a write guard for Cypher
  8. Normalizing the reports
  9. Performance note, with a warning
  10. Decision point: where does validation run?
  11. What to keep from this chapter

Chapter 11 — The Same Graph as a Labelled Property Graph

  1. The story so far
  2. LPG in one page
  3. Road 1: Cypher over the RDF you already have
  4. Road 2: a native property graph in LadybugDB
  5. Where provenance goes
  6. Decision point: RDF, LPG, or both?
  7. What to keep from this chapter

Chapter 12 — Hybrid Search, Vectors, and GraphRAG

  1. The story so far
  2. The retrieval problem, concretely
  3. Vectors are a column type
  4. Exact vector search, no index
  5. HNSW, from the vector extension
  6. BM25, from the fts extension
  7. Fusion: why you can’t just add the scores
  8. GraphRAG: let the graph vote
  9. MMR: diversity for the context window
  10. Wiring it into the agent loop
  11. Ranking notes, and what to distrust
  12. What to keep from this chapter
  13. What to keep from this book
  14. Full circle

Appendix A — SPARQL Reference for the Examples

  1. Act I — Build the Memory
  2. Act II — Defend the Memory

Appendix B — Full Turtle and Shapes Files

  1. data/schema.ttl
  2. data/data.ttl
  3. data/observations-calliope.ttl
  4. data/shapes.ttl
  5. data/shapes-closed.ttl
  6. data/shapes-sparql.ttl
  7. data/observations.shex
  8. Fixtures
  9. Reproducing the book’s output

Appendix C — Cargo Workspace

  1. Layout
  2. code/Cargo.toml
  3. code/rust-toolchain.toml
  4. code/graph/Cargo.toml
  5. code/reasoner/Cargo.toml
  6. code/validator/Cargo.toml
  7. code/ares/Cargo.toml
  8. The opt-in example crates
  9. Pinned dependency versions
  10. Building and running
  11. A note on utility functions
  12. The full picture

Appendix D — Exercise Solutions

  1. Chapter 0 — Add a critique agent
  2. Chapter 1 — Add Hermes’s observation
  3. Chapter 2 — Add a TrustedAgent subclass
  4. Chapter 3 — The FunctionalProperty trap
  5. Chapter 4 — Count quads per named graph
  6. Chapter 4A — Advanced SPARQL report query
  7. Chapter 4B — JSON-LD credential query
  8. Chapter 5 — Closed shapes
  9. Chapter 6 — Flag observations from cyclic agents
  10. Chapter 7 — Add custom checks to the pipeline
  11. Chapter 8 — Closed shapes vs markedConfident

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub