Skip to main content

MemoryNode API Reference

The MemoryNode is the fundamental unit of storage in EngramDB. This document provides a detailed reference for the MemoryNode API.

Creating a Memory Node

MemoryNode::new(embeddings)

Creates a new memory node with the given embeddings. Parameters:
  • embeddings: Vec<f32> - Vector representation of the memory content
Returns:
  • A new MemoryNode with a generated UUID and initialized fields
Example:

Basic Properties

id()

Returns the unique identifier of this memory node. Returns:
  • Uuid - The unique identifier
Example:

embeddings()

Returns a reference to the vector embeddings. Returns:
  • &[f32] - Reference to the embeddings vector
Example:

set_embeddings(embeddings)

Sets the embeddings to a new value. Parameters:
  • embeddings: Vec<f32> - New vector embeddings
Example:

creation_timestamp()

Returns the creation timestamp. Returns:
  • u64 - Unix timestamp when the memory was created
Example:

Working with Attributes

attributes()

Returns a reference to all attributes. Returns:
  • &HashMap<String, AttributeValue> - Reference to the attributes map
Example:

get_attribute(key)

Gets the value of a specific attribute. Parameters:
  • key: &str - The attribute key to retrieve
Returns:
  • Option<&AttributeValue> - The attribute value, or None if not found
Example:

set_attribute(key, value)

Sets an attribute. Parameters:
  • key: String - The attribute key
  • value: AttributeValue - The attribute value
Example:

Working with Connections

connections()

Returns a reference to all connections. Returns:
  • &Vec<Connection> - Reference to the connections vector
Example:

add_connection(connection)

Adds a connection to another memory node. Parameters:
  • connection: Connection - The connection to add
Example:

remove_connection(target_id)

Removes a connection to the specified target. Parameters:
  • target_id: Uuid - The ID of the target memory node
Returns:
  • bool - True if a connection was removed, false otherwise
Example:

Working with Temporal Layers

temporal_layers()

Returns a reference to all temporal layers. Returns:
  • &Vec<TemporalLayer> - Reference to the temporal layers vector
Example:

add_temporal_layer(layer)

Adds a temporal layer to track changes to this memory. Parameters:
  • layer: TemporalLayer - The temporal layer to add
Example:

Access Patterns

access_patterns()

Returns a reference to the access patterns. Returns:
  • &AccessHistory - Reference to the access history
Example:

record_access()

Records an access to this memory node. Example:

AttributeValue Types

The AttributeValue enum represents different types of values that can be stored as attributes:
Example: