Mnemosyne.Graph (mnemosyne v0.1.6)

Copy Markdown View Source

Core knowledge graph data structure.

Stores nodes indexed by ID, type, tag label, and subgoal description. Supports bidirectional linking between nodes and batch mutation via changesets.

Summary

Functions

Applies a changeset's additions and links to the graph.

Removes a node from the graph, cleans up link references, and rebuilds indexes.

Fetches a node by its ID, returning nil if not found.

Creates a typed bidirectional link between two nodes. No-op if either ID is missing.

Creates an empty graph.

Returns all nodes matching the given type atom.

Inserts a node into the graph, updating all secondary indexes.

Types

t()

@type t() :: %Mnemosyne.Graph{
  by_subgoal: %{required(String.t()) => MapSet.t()},
  by_tag: %{required(String.t()) => MapSet.t()},
  by_type: %{required(atom()) => MapSet.t()},
  nodes: %{required(String.t()) => struct()}
}

Functions

apply_changeset(graph, cs)

@spec apply_changeset(t(), Mnemosyne.Graph.Changeset.t()) :: t()

Applies a changeset's additions and links to the graph.

delete_node(graph, id)

@spec delete_node(t(), String.t()) :: t()

Removes a node from the graph, cleans up link references, and rebuilds indexes.

get_node(graph, id)

@spec get_node(t(), String.t()) :: struct() | nil

Fetches a node by its ID, returning nil if not found.

link(graph, id_a, id_b, type)

@spec link(t(), String.t(), String.t(), Mnemosyne.Graph.Edge.edge_type()) :: t()

Creates a typed bidirectional link between two nodes. No-op if either ID is missing.

new()

@spec new() :: t()

Creates an empty graph.

nodes_by_type(graph, type)

@spec nodes_by_type(t(), atom()) :: [struct()]

Returns all nodes matching the given type atom.

put_node(graph, node)

@spec put_node(
  t(),
  struct()
) :: t()

Inserts a node into the graph, updating all secondary indexes.