Memory behaviour (fnord v0.8.88)

View Source

Summary

Callbacks

Returns true if a memory with the given title exists in the impl's storage.

Deletes the given memory from the impl's storage. The impl is responsible for locking any shared resources and ensuring atomic delete behavior. Expects an :error tuple if the memory does not exist.

Performs any necessary one-time initialization for the impl's storage. For example, creating directories, loading currently select project from Services.Globals, etc.

Returns true if this memory implementation is available in the current context. For example, project memory requires a selected project, and session memory requires an active conversation.

Returns a list of all memory titles available in the impl's storage. Ordering is not guaranteed.

Reads and returns the memory with the given title from the impl's storage. The impl is responsible for ensuring that the returned memory is in the correct structural format, including atomic keys (e.g. not strings if unmarshalling JSON from disk).

Saves the given memory to the impl's storage. The impl is responsible for locking any shared resources and ensuring atomic write behavior. It is expected that the title of the memory is unique, and any existing memory with the same title will be overwritten.

Functions

A title is unique within the given scope if no existing memory with the same title exists.

A title is valid if it is non-empty, does not contain more than one non-word character in a row (which would lead to either multiple hyphens in the slug or cases where multiple titles map to the same slug), and does not start or end with a non-word character.

Serializes the given memory to a JSON binary.

Creates a new Memory struct from the given map. Expects keys to be atoms. Returns a Memory.t.

Converts a slug back to a title by replacing hyphens with spaces and capitalizing each word.

Converts a title to a slug by lowercasing it, replacing non-word characters with hyphens, and trimming leading/trailing hyphens.

Deserializes the given JSON binary to a Memory struct.

Types

scope()

@type scope() :: :global | :project | :session

t()

@type t() :: %Memory{
  content: binary(),
  embeddings: [float()] | nil,
  scope: scope(),
  slug: binary() | nil,
  title: binary(),
  topics: [binary()]
}

Callbacks

exists?(title)

@callback exists?(title :: binary()) :: boolean()

Returns true if a memory with the given title exists in the impl's storage.

forget(title)

@callback forget(title :: binary()) :: :ok | {:error, term()}

Deletes the given memory from the impl's storage. The impl is responsible for locking any shared resources and ensuring atomic delete behavior. Expects an :error tuple if the memory does not exist.

init()

@callback init() :: :ok | {:error, term()}

Performs any necessary one-time initialization for the impl's storage. For example, creating directories, loading currently select project from Services.Globals, etc.

is_available?()

@callback is_available?() :: boolean()

Returns true if this memory implementation is available in the current context. For example, project memory requires a selected project, and session memory requires an active conversation.

list()

@callback list() :: {:ok, [binary()]} | {:error, term()}

Returns a list of all memory titles available in the impl's storage. Ordering is not guaranteed.

read(title)

@callback read(title :: binary()) :: {:ok, t()} | {:error, term()}

Reads and returns the memory with the given title from the impl's storage. The impl is responsible for ensuring that the returned memory is in the correct structural format, including atomic keys (e.g. not strings if unmarshalling JSON from disk).

save(memory)

@callback save(memory :: t()) :: :ok | {:error, term()}

Saves the given memory to the impl's storage. The impl is responsible for locking any shared resources and ensuring atomic write behavior. It is expected that the title of the memory is unique, and any existing memory with the same title will be overwritten.

Functions

append(memory, new_content)

@spec append(t(), binary()) :: t()

exists?(arg1, title)

@spec exists?(scope(), binary()) :: boolean()

forget(map)

@spec forget(t()) :: :ok | {:error, term()}

generate_embeddings(memory)

@spec generate_embeddings(t()) :: {:ok, t()} | {:error, term()}

init()

@spec init() :: :ok | {:error, term()}

is_available?()

@spec is_available?() :: boolean()

is_stale?(arg1)

@spec is_stale?(t()) :: boolean()

is_unique_title?(scope, title)

@spec is_unique_title?(scope(), binary()) :: boolean()

A title is unique within the given scope if no existing memory with the same title exists.

is_valid_title?(title)

@spec is_valid_title?(binary()) :: boolean()

A title is valid if it is non-empty, does not contain more than one non-word character in a row (which would lead to either multiple hyphens in the slug or cases where multiple titles map to the same slug), and does not start or end with a non-word character.

list()

@spec list() :: {:ok, [{:scope, binary()}]} | {:error, term()}

list(atom)

marshal(memory)

@spec marshal(t()) :: {:ok, binary()} | {:error, term()}

Serializes the given memory to a JSON binary.

new(scope, title, content, topics)

@spec new(scope(), binary(), binary(), [binary()]) :: {:ok, t()} | {:error, term()}

new_from_map(data)

@spec new_from_map(map()) :: t()

Creates a new Memory struct from the given map. Expects keys to be atoms. Returns a Memory.t.

read(atom, title)

@spec read(scope(), binary()) :: {:ok, t()} | {:error, term()}

read_me()

@spec read_me() :: {:ok, t()} | {:error, term()}

save(memory)

@spec save(t()) :: {:ok, t()} | {:error, term()}

search(query, limit)

@spec search(binary(), non_neg_integer()) ::
  {:ok, [{t(), float()}]} | {:error, term()}

slug_to_title(slug)

@spec slug_to_title(binary()) :: binary()

Converts a slug back to a title by replacing hyphens with spaces and capitalizing each word.

title_to_slug(title)

@spec title_to_slug(binary()) :: binary()

Converts a title to a slug by lowercasing it, replacing non-word characters with hyphens, and trimming leading/trailing hyphens.

unmarshal(json)

@spec unmarshal(binary()) :: {:ok, t()} | {:error, term()}

Deserializes the given JSON binary to a Memory struct.