Skip to content

11 — Knowledge graph

Gnosis

Subject–predicate–object triples appended to a Strand and indexed three ways. Pattern queries with wildcards, neighbor traversal, and provenance baked in. Build social graphs, ontologies, and reasoning surfaces that stay verifiable end-to-end.

A closer lookA relationship worth remembering.

Subject, predicate, and object form a triple. Connected triples create a knowledge graph, backed by an inspectable Strand history.

  1. 01Append a triple
  2. 02Connect the relationships
  3. 03Follow the provenance
01 — Concepts
01

Subject–predicate–object triples appended to a Strand.

02

Three-way indexing: by subject, by predicate, by object.

03

Pattern queries with wildcards across any position.

04

Neighbor traversal, multi-hop walks, provenance preserved per triple.

05

Social graphs, ontologies, reasoning — one substrate.

02 — Code

A handful of lines.

use gnosis::{Node, Triple, Pattern};

let node = Node::open(".weave/gnosis").await?;

// Append a fact.
node.add_triple(Triple::new(
    "did:weave:alice", "follows", "did:weave:bob",
)).await?;

// Pattern query — who does alice follow?
let pat = Pattern::new("did:weave:alice", "follows", Pattern::wildcard());
for t in node.query_pattern(&pat).await? {
    println!("{} → {}", t.predicate, t.object);
}

// Two-hop neighborhood.
let near = node.get_neighbors("did:weave:alice", /* depth */ 2).await?;