Mnemosyne.MemoryStore (mnemosyne v0.3.0)

Copy Markdown View Source

GenServer owning the graph backend state.

Uses a two-lane queue for concurrent operations:

  • Write lane: serialized queue for changesets, ingestion commits, and deletions. Only one write runs at a time; others enqueue.
  • Maintenance lane: single slot for consolidate/decay operations.
  • Recall lane: multiple concurrent retrieval+reasoning tasks (unchanged).

Write tasks return deltas applied to the GenServer's current backend state, not a captured snapshot. Maintenance tasks return updated backend state and are idempotent with respect to concurrent writes.

Summary

Functions

Applies a changeset to the graph via the backend.

Returns a specification to start this module under a supervisor.

Consolidates near-duplicate semantic nodes.

Prunes low-utility nodes via decay scoring.

Removes nodes from the graph via the backend.

Returns the current in-memory graph.

Fetches nodes by their IDs from the backend.

Fetches metadata for the given node IDs.

Fetches a single node by ID from the backend.

Fetches all nodes of the given types from the backend.

Stores a complete trajectory or returns an error without exposing partial memory.

Fetches the most recently created nodes of the given types, sorted by creation time.

Runs async retrieval + reasoning and returns the result.

Strips dangling link references and deletes orphaned routing nodes.

Validates episodic grounding and penalizes weakly grounded nodes.

Functions

apply_changeset(server, changeset)

@spec apply_changeset(GenServer.server(), Mnemosyne.Graph.Changeset.t()) :: :ok

Applies a changeset to the graph via the backend.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

consolidate_semantics(server, opts \\ [])

@spec consolidate_semantics(
  GenServer.server(),
  keyword()
) :: :ok

Consolidates near-duplicate semantic nodes.

decay_nodes(server, opts \\ [])

@spec decay_nodes(
  GenServer.server(),
  keyword()
) :: :ok

Prunes low-utility nodes via decay scoring.

delete_nodes(server, node_ids)

@spec delete_nodes(GenServer.server(), [String.t()]) :: :ok

Removes nodes from the graph via the backend.

get_graph(server)

@spec get_graph(GenServer.server()) :: Mnemosyne.Graph.t()

Returns the current in-memory graph.

Only works with backends that expose a :graph field in their state (e.g. InMemory). Returns an empty graph for other backends.

get_linked_nodes(server, node_ids)

@spec get_linked_nodes(GenServer.server(), [String.t()]) ::
  {:ok, [struct()]} | {:error, term()}

Fetches nodes by their IDs from the backend.

get_metadata(server, node_ids)

@spec get_metadata(GenServer.server(), [String.t()]) ::
  {:ok, %{required(String.t()) => Mnemosyne.NodeMetadata.t()}}
  | {:error, term()}

Fetches metadata for the given node IDs.

get_node(server, node_id)

@spec get_node(GenServer.server(), String.t()) ::
  {:ok, struct() | nil} | {:error, term()}

Fetches a single node by ID from the backend.

get_nodes_by_type(server, types)

@spec get_nodes_by_type(GenServer.server(), [atom()]) ::
  {:ok, [struct()]} | {:error, term()}

Fetches all nodes of the given types from the backend.

ingest(server, trajectory, opts \\ [])

Stores a complete trajectory or returns an error without exposing partial memory.

latest(server, top_k, opts \\ [])

@spec latest(GenServer.server(), pos_integer(), keyword()) ::
  {:ok, [{struct(), Mnemosyne.NodeMetadata.t()}]} | {:error, term()}

Fetches the most recently created nodes of the given types, sorted by creation time.

Returns up to top_k nodes paired with their metadata, newest first. Defaults to semantic and procedural node types.

recall(server, query, opts \\ [])

Runs async retrieval + reasoning and returns the result.

repair_graph(server, opts \\ [])

@spec repair_graph(
  GenServer.server(),
  keyword()
) :: :ok

Strips dangling link references and deletes orphaned routing nodes.

start_link(opts)

validate_episodic(server, opts \\ [])

@spec validate_episodic(
  GenServer.server(),
  keyword()
) :: :ok

Validates episodic grounding and penalizes weakly grounded nodes.