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
Add a link to the graph.
Add a node to the graph.
Attach a node to the graph linked to last inserted item.
Obtain node by handle.
Callback implementation for GenAI.Graph.NodeBehaviour.description/1
.
Callback implementation for GenAI.Graph.NodeBehaviour.description/2
.
Callback implementation for GenAI.Graph.NodeBehaviour.handle/1
.
Callback implementation for GenAI.Graph.NodeBehaviour.handle/2
.
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
.
Callback implementation for GenAI.Graph.NodeBehaviour.name/2
.
Callback implementation for GenAI.Graph.NodeBehaviour.new/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
add_link(graph, graph_link, options \\ nil)
@spec add_link( graph :: GenAI.Types.Graph.graph(), link :: GenAI.Types.Graph.graph_link(), options :: map() ) :: GenAI.Types.result(GenAI.Types.Graph.graph(), GenAI.Types.details())
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}
add_node(graph, graph_node, options \\ nil)
@spec add_node( graph :: GenAI.Types.Graph.graph(), node :: GenAI.Types.Graph.graph_node(), options :: map() ) :: GenAI.Types.result(GenAI.Types.Graph.graph(), GenAI.Types.details())
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
attach_node(graph, graph_node, options \\ nil)
@spec attach_node( graph :: GenAI.Types.Graph.graph(), node :: GenAI.Types.Graph.graph_node(), options :: map() ) :: GenAI.Types.result(GenAI.Types.Graph.graph(), GenAI.Types.details())
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
attempt_set_node(graph, node_id, graph_node, options)
@spec attempt_set_node( GenAI.Types.Graph.graph(), GenAI.Types.Graph.graph_node_id(), GenAI.Types.Graph.graph_node(), keyword() ) :: GenAI.Types.Graph.graph()
by_handle(graph, handle)
@spec by_handle(graph :: GenAI.Types.Graph.graph(), handle :: GenAI.Types.handle()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
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}}
description(graph)
Callback implementation for GenAI.Graph.NodeBehaviour.description/1
.
description(graph, default)
Callback implementation for GenAI.Graph.NodeBehaviour.description/2
.
do_new(options \\ nil)
do_node(graph, graph_node)
do_process_node(subject, link, container, session, context, options)
handle(graph)
Callback implementation for GenAI.Graph.NodeBehaviour.handle/1
.
handle(graph, default)
Callback implementation for GenAI.Graph.NodeBehaviour.handle/2
.
head(graph)
@spec head(GenAI.Types.Graph.graph()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
id(graph)
Callback implementation for GenAI.Graph.NodeBehaviour.id/1
.
inspect_custom_details(subject, opts)
See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_custom_details/2
.
inspect_full_detail(subject, opts)
See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_full_detail/2
.
inspect_high_detail(subject, opts)
See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_high_detail/2
.
inspect_low_detail(subject, opts)
See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_low_detail/2
.
inspect_medium_detail(subject, opts)
See GenAI.Graph.NodeProtocol.DefaultProvider.inspect_medium_detail/2
.
last_link(graph)
@spec last_link(GenAI.Types.Graph.graph()) :: GenAI.Types.result(GenAI.Types.Graph.graph_link(), GenAI.Types.details())
last_node(graph)
@spec last_node(GenAI.Types.Graph.graph()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
link(graph, graph_link)
@spec link( graph :: GenAI.Types.Graph.graph(), id :: GenAI.Types.Graph.graph_link_id() ) :: GenAI.Types.result(GenAI.Types.Graph.graph_link(), GenAI.Types.details())
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_by_handle(graph, handle)
@spec link_by_handle( graph :: GenAI.Types.Graph.graph(), handle :: GenAI.Types.handle() ) :: GenAI.Types.result(GenAI.Types.Graph.graph_link(), GenAI.Types.details())
Obtain link by handle.
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, handle: :bar)
...> graph = GenAI.VNext.Graph.add_link(graph, link)
...> GenAI.VNext.Graph.link_by_handle(graph, :bar)
{:ok, link}
when-not-found
When Not Found
iex> graph = GenAI.VNext.Graph.new()
...> GenAI.VNext.Graph.link_by_handle(graph, :bar)
{:error, {:handle, :not_found}}
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
name(graph)
Callback implementation for GenAI.Graph.NodeBehaviour.name/1
.
name(graph, default)
Callback implementation for GenAI.Graph.NodeBehaviour.name/2
.
new(options \\ nil)
Callback implementation for GenAI.Graph.NodeBehaviour.new/1
.
node(graph, graph_node)
@spec node( graph :: GenAI.Types.Graph.graph(), id :: GenAI.Types.Graph.graph_node_id() ) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
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}}
nodes(graph, options \\ nil)
@spec nodes( GenAI.Types.Graph.graph(), keyword() ) :: {:ok, [GenAI.Types.Graph.graph_node()]}
nodes!(graph, options \\ nil)
@spec nodes!( GenAI.Types.Graph.graph(), keyword() ) :: [GenAI.Types.Graph.graph_node()]