Skip to main content

render_node

Function render_node 

Source
pub fn render_node(node: &Node) -> String
Expand description

Render a Node to a compact, deterministic text representation suitable for LLM consumption.

The format is YAML-like and stable across versions:

ntype: <ntype>
id: <uuid>
context: <context_sentence>
summary: <summary>
<prop_key>: <prop_value>
...
  • ntype and id are always present.
  • context is emitted iff node.context_sentence is Some. Sits BEFORE summary so an LLM reading the rendered node sees the chunk’s positional cue first (, Anthropic 2024 contextual-retrieval recipe).
  • summary is emitted iff node.summary is Some. Clipped at DEFAULT_RENDER_SUMMARY_CAP_CHARS (8192) chars by default, overridable via MNEM_RENDER_SUMMARY_CAP_CHARS. A 1 MiB summary on a single node would otherwise consume the entire token budget and starve every other item out of the result.
  • Scalar props (String, Integer, Float, Bool) are emitted in BTreeMap order (alphabetical). Non-scalar props (Link, Map, List, Bytes, Null) are skipped - an agent chasing a link should follow it with a separate mnem_get_node call.
  • Opaque content bytes are never rendered.

Determinism: since Node.props is a BTreeMap, iteration order is byte-stable and the rendered string is therefore also byte-stable.