Skip to main content

Module index_set

Module index_set 

Source
Expand description

Index objects (Phase 2 secondary indexes).

An IndexSet lives alongside a Commit and carries pointers to helper Prolly trees that make common agent queries fast:

  • nodes_by_label - for each node label, a Prolly tree keyed by NodeId (16 bytes) whose values are node CIDs. Turns “all Person nodes” from O(n) into a label-scoped cursor iteration.
  • nodes_by_prop - for each (label, prop_name), a Prolly tree keyed by blake3(canonical_ipld(value))[..16] whose values are node CIDs. Turns “node where name=‘Alice’” into O(log n) point lookup. Single-valued: duplicate (label, prop, value) tuples collide at the key level; last-write-wins (use the resolve_or_create_node helper on Transaction to avoid creating duplicates).
  • outgoing - Prolly tree keyed by source NodeId whose values are CIDs of AdjacencyBucket objects - a small sorted list of (edge_label, edge_cid) pairs for that node. Turns “outgoing edges of X” into O(log n) + one bucket read. Previously named adjacency; the on-wire field alias adjacency is still accepted on decode for repos written before the incoming-index addition.
  • incoming - Prolly tree keyed by destination NodeId whose values are CIDs of IncomingAdjacencyBucket objects - a small sorted list of (etype, src, edge_cid) triples for that node. Turns “who points at X” into O(log n) + one bucket read. Added alongside the incoming-index feature; mandates IndexSet rebuild on format-bump commits.

All indexes are derived from the node + edge Prolly trees owned by the Commit. They are entirely optional; a commit with indexes = None still functions (queries fall back to full scan).

Structs§

AdjacencyBucket
Per-source-node bucket of outgoing edges. Stored as a standalone object so the adjacency Prolly tree can cheaply reference a list without inlining it into every leaf.
AdjacencyEntry
One outgoing-edge record inside an AdjacencyBucket.
IncomingAdjacencyBucket
Per-destination-node bucket of incoming edges. Stored as a standalone object so the incoming-adjacency Prolly tree can cheaply reference a list without inlining it into every leaf.
IncomingAdjacencyEntry
One incoming-edge record inside an IncomingAdjacencyBucket.
IndexSet
Top-level secondary-index aggregator (SPEC §4.8, added in mnem/0.2, extended with incoming in mnem/0.3).