pub struct Node {
pub id: NodeId,
pub ntype: String,
pub summary: Option<String>,
pub props: BTreeMap<String, Ipld>,
pub content: Option<Bytes>,
pub context_sentence: Option<String>,
pub extra: BTreeMap<String, Ipld>,
}Expand description
A graph vertex.
See SPEC §4.1 and the module docs. Construct via Node::new
and add properties with the with_* fluent helpers.
Sparse embeddings live in the per-commit sidecar (Commit.sparse
Prolly tree, keyed by NodeCid) rather than inline on Node. This
keeps sparse bytes out of the canonical Node hash so vocabulary
differences or encoder-version changes cannot perturb NodeCid.
Legacy DAG-CBOR carrying an explicit sparse_embed map round-trips
losslessly through the extra flatten sink, keeping NodeCids stable.
Fields§
§id: NodeIdStable node identity. Survives content edits; edges reference this.
ntype: StringFree-form node-type label ("Person", "mnem:Class", …).
summary: Option<String>Optional short natural-language summary. Intended as the
token-cheap representation of this node for LLM-facing retrieval:
the field agents read when assembling context under a token
budget. Distinct from props (structured) and content
(opaque payload).
props: BTreeMap<String, Ipld>Property map. Values are any DAG-CBOR value, including Links.
content: Option<Bytes>Optional opaque payload (a document body, a file, …).
context_sentence: Option<String>Optional contextualized-chunk prefix. An
LLM-generated one-sentence placement cue (“This paragraph is
from Section 3 of a legal contract between Alice and Bob’s
employer…”) stored alongside the node. The ingest pipeline
prepends it to summary before embedding so the dense + sparse
lanes capture positional and relational context the chunk
alone would lose.
Anthropic’s 2024 Contextual Retrieval paper reports -49% to -67% retrieval-failure reduction when this prefix is present; mnem stores it on the node so the render path can surface it back to the agent for faithful source attribution.
Additive: existing nodes with context_sentence = None keep
byte-identical CIDs (same skip_serializing_if = "Option::is_none"
pattern as other optional fields).
extra: BTreeMap<String, Ipld>Forward-compat extension map per SPEC §3.2 - holds fields this
version doesn’t recognize and preserves them on re-encode so signed
Nodes remain verifiable across version upgrades. Legacy sparse_embed
fields written before G17 land here and round-trip byte-identically.
Implementations§
Source§impl Node
impl Node
Sourcepub const DEFAULT_NTYPE: &'static str = "Node"
pub const DEFAULT_NTYPE: &'static str = "Node"
Default ntype value used when a caller wants to ingest a node
without choosing a category. Applied by the HTTP bulk/single
handlers when the caller omits label or sends an empty string.
Direct Rust callers of Node::new still pass ntype explicitly;
Node::new_default is the zero-arg convenience.
Sourcepub fn new(id: NodeId, ntype: impl Into<String>) -> Self
pub fn new(id: NodeId, ntype: impl Into<String>) -> Self
Construct a Node with no summary, no props, no content.
Sourcepub fn new_default(id: NodeId) -> Self
pub fn new_default(id: NodeId) -> Self
Construct a Node with the project default ntype = "Node".
Convenience for callers that don’t want to categorise on write;
equivalent to Node::new(id, Node::DEFAULT_NTYPE).
Sourcepub fn with_summary(self, summary: impl Into<String>) -> Self
pub fn with_summary(self, summary: impl Into<String>) -> Self
Attach a short summary. Returns self for chaining.
Sourcepub fn with_prop(self, key: impl Into<String>, value: impl Into<Ipld>) -> Self
pub fn with_prop(self, key: impl Into<String>, value: impl Into<Ipld>) -> Self
Attach a property. Returns self for chaining.
Sourcepub fn with_content(self, content: Bytes) -> Self
pub fn with_content(self, content: Bytes) -> Self
Attach opaque content.
Sourcepub fn with_context_sentence(self, context: impl Into<String>) -> Self
pub fn with_context_sentence(self, context: impl Into<String>) -> Self
Attach an LLM-generated contextualized-chunk prefix . The render path prepends this to the summary so the agent sees where this chunk sits in its source document.
Typical callers run this at ingest time via a TextGenerator
from mnem-llm-providers with a prompt like:
“Give a single sentence that situates the following chunk within its source so a retrieval model can understand where it came from. Chunk:
{summary}Document context:{doc_title}”
Sourcepub fn get_str(&self, key: &str) -> Option<&str>
pub fn get_str(&self, key: &str) -> Option<&str>
Get a property as &str. Returns None if absent or not a string.
Sourcepub fn get_int(&self, key: &str) -> Option<i128>
pub fn get_int(&self, key: &str) -> Option<i128>
Get a property as i128. Returns None if absent or not an integer.
Sourcepub fn get_bool(&self, key: &str) -> Option<bool>
pub fn get_bool(&self, key: &str) -> Option<bool>
Get a property as bool. Returns None if absent or not a bool.