pub struct Node {
pub id: NodeId,
pub ntype: String,
pub summary: Option<String>,
pub props: BTreeMap<String, Ipld>,
pub content: Option<Bytes>,
pub sparse_embed: Option<SparseEmbed>,
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.
Node is PartialEq but not Eq: sparse_embed carries Vec<f32>
whose values cannot be Eq (NaN). Use CID equality via
hash_to_cid when you need a canonical identity check; field-wise
== comparison still works for non-NaN data.
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, …).
sparse_embed: Option<SparseEmbed>Optional learned-sparse embedding . Produced
by a SparseEncoder adapter (OpenSearch neural-sparse-doc-v3-
distill, BGE-M3-sparse, etc.) and indexed by
crate::index::sparse::SparseInvertedIndex::build_from_repo.
Additive: existing nodes with sparse_embed = None keep
byte-identical CIDs because the wire serializer omits the field
via skip_serializing_if = "Option::is_none".
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 sparse_embed).
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.
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_sparse_embed(self, sparse_embed: SparseEmbed) -> Self
pub fn with_sparse_embed(self, sparse_embed: SparseEmbed) -> Self
Attach a learned-sparse embedding. Consumed by the sparse lane in
Retriever via crate::index::sparse::SparseInvertedIndex.
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.