GenAI.VNext.Graph (GenAI Core v0.2.0)

A graph data structure for representing AI graphs, threads, conversations, uml, etc. Utility Class

Link to this section Summary

Functions

Attach a node to the graph linked to last inserted item.

Obtain node by handle.

Callback implementation for GenAI.Graph.NodeBehaviour.handle/1.

Callback implementation for GenAI.Graph.NodeBehaviour.id/1.

Obtain link by id.

Obtain link by handle.

Check if a node is a member of the graph.

Callback implementation for GenAI.Graph.NodeBehaviour.name/1.

Obtain node by id.

Link to this section Types

@type t() :: %GenAI.VNext.Graph{
  description: GenAI.Types.description(),
  finger_print: GenAI.Types.finger_print(),
  handle: GenAI.Types.node_handle(),
  head: GenAI.Types.Graph.graph_node_id() | nil,
  id: GenAI.Types.node_id(),
  inbound_links: GenAI.Types.link_map(),
  last_link: GenAI.Types.Graph.graph_link_id() | nil,
  last_node: GenAI.Types.Graph.graph_node_id() | nil,
  link_handles: %{
    required(GenAI.Types.handle()) => GenAI.Types.Graph.graph_link_id()
  },
  links: %{
    required(GenAI.Types.Graph.graph_link_id()) =>
      GenAI.Types.Graph.graph_link()
  },
  meta: nil | map() | keyword(),
  name: GenAI.Types.name(),
  node_handles: %{
    required(GenAI.Types.handle()) => GenAI.Types.Graph.graph_node_id()
  },
  nodes: %{
    required(GenAI.Types.Graph.graph_node_id()) =>
      GenAI.Types.Graph.graph_node()
  },
  outbound_links: GenAI.Types.link_map(),
  settings: term(),
  vsn: float()
}

Link to this section Functions

Link to this function

add_link(graph, graph_link, options \\ nil)

Add a link to the graph.

examples

Examples

iex> graph = GenAI.VNext.Graph.new()
...> node1 = GenAI.Graph.Node.new(id: UUID.uuid4())
...> node2 = GenAI.Graph.Node.new(id: UUID.uuid4())
...> graph = GenAI.VNext.Graph.add_node(graph, node1)
...> graph = GenAI.VNext.Graph.add_node(graph, node2)
...> link = GenAI.Graph.Link.new(node1.id, node2.id)
...> graph = GenAI.VNext.Graph.add_link(graph, link)
...> GenAI.VNext.Graph.link(graph, link.id)
{:ok, link}
Link to this function

add_node(graph, graph_node, options \\ nil)

Add a node to the graph.

examples

Examples

iex> graph = GenAI.VNext.Graph.new()
...> node = GenAI.Graph.Node.new(id: UUID.uuid4())
...> graph = GenAI.VNext.Graph.add_node(graph, node)
...> GenAI.VNext.Graph.member?(graph, node.id)
true
Link to this function

attach_node(graph, graph_node, options \\ nil)

Attach a node to the graph linked to last inserted item.

examples

Examples

iex> graph = GenAI.VNext.Graph.new()
...> node = GenAI.Graph.Node.new(id: UUID.uuid4())
...> graph = GenAI.VNext.Graph.attach_node(graph, node)
...> GenAI.VNext.Graph.member?(graph, node.id)
true
Link to this function

attempt_set_node(graph, node_id, graph_node, options)

Link to this function

by_handle(graph, handle)

Obtain node by handle.

examples

Examples

when-found

When Found

iex> graph = GenAI.VNext.Graph.new()
...> node = GenAI.Graph.Node.new(id: UUID.uuid4(), handle: :foo)
...> graph = GenAI.VNext.Graph.add_node(graph, node)
...> GenAI.VNext.Graph.by_handle(graph, :foo)
{:ok, node}

when-not-found

When Not Found

iex> graph = GenAI.VNext.Graph.new()
...> GenAI.VNext.Graph.by_handle(graph, :foo)
{:error, {:handle, :not_found}}
Link to this function

description(graph)

Callback implementation for GenAI.Graph.NodeBehaviour.description/1.

Link to this function

description(graph, default)

Callback implementation for GenAI.Graph.NodeBehaviour.description/2.

Link to this function

do_new(options \\ nil)

@spec do_new(keyword()) :: t()
Link to this function

do_node(graph, graph_node)

Link to this function

do_process_node(subject, link, container, session, context, options)

Callback implementation for GenAI.Graph.NodeBehaviour.handle/1.

Link to this function

handle(graph, default)

Callback implementation for GenAI.Graph.NodeBehaviour.handle/2.

Callback implementation for GenAI.Graph.NodeBehaviour.id/1.

Link to this function

inspect_custom_details(subject, opts)

See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_custom_details/2.

Link to this function

inspect_full_detail(subject, opts)

See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_full_detail/2.

Link to this function

inspect_high_detail(subject, opts)

See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_high_detail/2.

Link to this function

inspect_low_detail(subject, opts)

See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_low_detail/2.

Link to this function

inspect_medium_detail(subject, opts)

See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_medium_detail/2.

Link to this function

last_link(graph)

Link to this function

last_node(graph)

Link to this function

link(graph, graph_link)

Obtain link by id.

examples

Examples

when-found

When Found

iex> graph = GenAI.VNext.Graph.new()
...> node1 = GenAI.Graph.Node.new(id: UUID.uuid4())
...> node2 = GenAI.Graph.Node.new(id: UUID.uuid4())
...> graph = GenAI.VNext.Graph.add_node(graph, node1)
...> graph = GenAI.VNext.Graph.add_node(graph, node2)
...> link = GenAI.Graph.Link.new(node1.id, node2.id)
...> graph = GenAI.VNext.Graph.add_link(graph, link)
...> GenAI.VNext.Graph.link(graph, link.id)
{:ok, link}

when-not-found

When Not Found

iex> graph = GenAI.VNext.Graph.new()
...> GenAI.VNext.Graph.link(graph, UUID.uuid4())
{:error, {:link, :not_found}}
Link to this function

member?(graph, graph_node)

@spec member?(
  graph :: GenAI.Types.Graph.graph(),
  id :: GenAI.Types.Graph.graph_node_id()
) :: boolean()

Check if a node is a member of the graph.

examples

Examples

iex> graph = GenAI.VNext.Graph.new()
...> node = GenAI.Graph.Node.new(id: UUID.uuid4())
...> graph = GenAI.VNext.Graph.add_node(graph, node)
...> GenAI.VNext.Graph.member?(graph, node.id)
true

iex> graph = GenAI.VNext.Graph.new()
...> GenAI.VNext.Graph.member?(graph, UUID.uuid4())
false

Callback implementation for GenAI.Graph.NodeBehaviour.name/1.

Link to this function

name(graph, default)

Callback implementation for GenAI.Graph.NodeBehaviour.name/2.

Link to this function

new(options \\ nil)

Callback implementation for GenAI.Graph.NodeBehaviour.new/1.

Link to this function

node(graph, graph_node)

Obtain node by id.

examples

Examples

when-found

When Found

iex> graph = GenAI.VNext.Graph.new()
...> node = GenAI.Graph.Node.new(id: UUID.uuid4())
...> graph = GenAI.VNext.Graph.add_node(graph, node)
...> GenAI.VNext.Graph.node(graph, node.id)
{:ok, node}

when-not-found

When Not Found

iex> graph = GenAI.VNext.Graph.new()
...> GenAI.VNext.Graph.node(graph, UUID.uuid4())
{:error, {:node, :not_found}}
Link to this function

nodes(graph, options \\ nil)

Link to this function

nodes!(graph, options \\ nil)

Link to this function

process_node(subject, link, _, session, context, options)

Link to this function

setting(graph, setting, options, default \\ nil)

@spec setting(t(), atom(), keyword(), any()) :: any()