Skip to main content

Node

Struct Node 

Source
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: NodeId

Stable node identity. Survives content edits; edges reference this.

§ntype: String

Free-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

Source

pub const KIND: &'static str = "node"

The _kind discriminator for nodes. "node" on the wire.

Source

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.

Source

pub fn new(id: NodeId, ntype: impl Into<String>) -> Self

Construct a Node with no summary, no props, no content.

Source

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).

Source

pub fn with_summary(self, summary: impl Into<String>) -> Self

Attach a short summary. Returns self for chaining.

Source

pub fn with_prop(self, key: impl Into<String>, value: impl Into<Ipld>) -> Self

Attach a property. Returns self for chaining.

Source

pub fn with_content(self, content: Bytes) -> Self

Attach opaque content.

Source

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.

Source

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}

Source

pub fn get_str(&self, key: &str) -> Option<&str>

Get a property as &str. Returns None if absent or not a string.

Source

pub fn get_int(&self, key: &str) -> Option<i128>

Get a property as i128. Returns None if absent or not an integer.

Source

pub fn get_bool(&self, key: &str) -> Option<bool>

Get a property as bool. Returns None if absent or not a bool.

Source

pub fn get_float(&self, key: &str) -> Option<f64>

Get a property as f64. Returns None if absent or not a float.

Source

pub fn get_bytes(&self, key: &str) -> Option<&[u8]>

Get a property as a byte slice. Returns None if absent or not bytes.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Node

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Node

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl !Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,