Ragex. NodeFormatter
(Ragex v0.38.0)
View Source
Renders knowledge-graph node identifiers as human-readable strings.
Graph nodes appear in several shapes depending on where they came from:
- a bare atom — a module name
{module, name, arity}— a function reference{:module, id}/{:function, module, name, arity}— tagged variants produced by some graph queries
This module is the single place that knows how to turn any of those into a
string. Previously three near-identical private copies existed (in the MCP
Resources and Tools handlers and in Ragex.RAG.ContextBuilder) and had
already drifted apart, so the same node could render differently depending on
which code path reached it.
Styles
Two rendering styles are supported, because the two audiences have different expectations:
:mcp(default) — the form MCP clients see. Modules are rendered withAtom.to_string/1, soMyApp.Foobecomes"Elixir.MyApp.Foo", matching the identifiers clients send back in requests.nilis inspected like any other unexpected value.:prompt— the form embedded in LLM prompts by the RAG pipeline. Modules are rendered withinspect/1, soMyApp.Foobecomes"MyApp.Foo"without theElixir.prefix, which reads better in prose.nilstaysnilso callers can use|| "Unknown"to substitute a default.
Examples
iex> Ragex.NodeFormatter.format_node_id(MyApp.Foo)
"Elixir.MyApp.Foo"
iex> Ragex.NodeFormatter.format_node_id({MyApp.Foo, :bar, 2})
"Elixir.MyApp.Foo.bar/2"
iex> Ragex.NodeFormatter.format_node_id({:function, MyApp.Foo, :bar, 2})
"Elixir.MyApp.Foo.bar/2"
iex> Ragex.NodeFormatter.format_node_id({MyApp.Foo, :bar, 2}, :prompt)
"MyApp.Foo.bar/2"
iex> Ragex.NodeFormatter.format_node_id(nil, :prompt)
nil
Summary
Functions
Formats a graph node identifier.