OriginChainDB docs
examples · graph

Graph examples

← All examples

OriginChainDB exposes graph traversal and the graph algorithms built on top of it, all over the same declared relations. The traversals - neighbors, reverse, bfs, path and dijkstra - read an adjacency index laid down at write time rather than computed per query. The algorithms above them cover ranked paths, community detection, centrality and node embeddings.

17 work today. Each example below is its own page, with the request, the response shape, side-by-side cURL / Python / TypeScript / Go, and the mistakes that produce a 404 or an empty result.

prerequisite

Every endpoint below requires a [[relations]] block on the schema - the relation must be declared before any traversal can resolve. See schemas/reference#relations for the shape. Without a matching relation the call is refused rather than quietly returning an empty result.

1
neighbors - one-hop forward adjacency
works today

Direct adjacency-list lookup. The fastest graph query on the substrate - one hop, one read.

2
reverse - one-hop inbound adjacency
works today

Who points at this row? The mirror of neighbors. Requires bidirectional=true on the relation (default).

3
bfs - depth-bounded multi-hop
works today

Every node reachable within max_depth hops, with the depth at which each was found.

4
path - reachability check
works today

Is X connected to Y at all? Returns a boolean. Short-circuits on the first match.

5
dijkstra - weighted shortest path
works today

Single shortest-path cost between two nodes under a caller-supplied edge-weight map.

6
all_simple_paths - every node-disjoint path
works today

Every distinct path from src to dst. Hard-capped at max_paths to avoid exponential blowup.

7
pagerank - over a caller-supplied node set
works today

PageRank scores over a subgraph you scope explicitly via the nodes= parameter.

8
triangles - every closed triple in a relation
works today

Every closed triple in the relation, walked as undirected. One row per triangle, keys in canonical order.

9
components - split the graph into islands
works today

Union-find over the whole node universe. One entry per node carrying the id of the island it landed in.

10
louvain - modularity community detection
works today

The dense groups inside a connected graph, as deterministic integer ids in a communities envelope.

11
label_propagation - fast seeded communities
works today

Near-linear community detection. Order-sensitive, so pass a seed when you need to reproduce a run.

12
betweenness - the bridges in a network
works today

Which nodes sit on the most shortest paths. Exact by default, with an opt-in sampled mode for big graphs.

13
eigenvector_centrality - influence by association
works today

Influence weighted by the influence of your neighbours. No node universe to supply, unlike pagerank.

14
k-shortest - the top K routes, cheapest first
works today

Yen's ranked alternatives between two nodes. Note the source and target parameter names, not src and dst.

15
random-walk - seeded and node2vec-biased walks
works today

A deterministic walk from a start node, with optional p and q bias. The seed is a required parameter.

16
node2vec - train embeddings, then query them
works today

Learn a vector per node from biased walks, persist it, then ask for the nodes most similar to any node.

17
graphsage - embeddings that use your columns
works today

Embeddings that combine the graph with a numeric feature column on each row. Train, persist, then query.