aiq.memory.interfaces#

Classes#

MemoryEditor

Abstract interface for editing and

MemoryIOBase

Base abstract class for I/O operations

MemoryReader

Responsible for retrieving MemoryItems

MemoryWriter

Responsible for converting new observations

MemoryManager

Manages the lifecycle of the stored

Module Contents#

class MemoryEditor#

Bases: abc.ABC

Abstract interface for editing and retrieving memory items.

A MemoryEditor is responsible for adding, searching, and removing MemoryItems.

Implementations may integrate with vector stores or other indexing backends.

abstractmethod add_items(items: list[aiq.memory.models.MemoryItem]) None#
Async:

Insert multiple MemoryItems into the memory.

Args:

items (list[MemoryItem]): The items to be added.

abstractmethod search(
query: str,
top_k: int = 5,
**kwargs,
) list[aiq.memory.models.MemoryItem]#
Async:

Retrieve items relevant to the given query. Relevance criteria depend on implementation.

Args:

query (str): The query string to match. top_k (int): Maximum number of items to return. kwargs (dict): Keyword arguments to pass to the search method.

Returns:

list[MemoryItem]: The most relevant MemoryItems.

abstractmethod remove_items(**kwargs) None#
Async:

Remove items. Additional parameters needed for deletion can be specified in keyword arguments.

Args:

kwargs (dict): Keyword arguments to pass to the remove-items method.

class MemoryIOBase(editor: MemoryEditor)#

Bases: abc.ABC

Base abstract class for I/O operations on memory, providing a common interface for

MemoryReader and MemoryWriter to interact with a MemoryEditor.

Concrete subclasses should hold a reference to a MemoryEditor instance.

_editor#
class MemoryReader(editor: MemoryEditor)#

Bases: MemoryIOBase

Responsible for retrieving MemoryItems from the MemoryEditor based on context or queries.

abstractmethod retrieve(
context: str,
top_k: int = 5,
) list[aiq.memory.models.MemoryItem]#
Async:

Retrieve a subset of MemoryItems relevant to the provided context.

Args:

context (str): A string representing the current user context or query. top_k (int): Maximum number of items to return.

Returns:

list[MemoryItem]: Relevant MemoryItems.

class MemoryWriter(editor: MemoryEditor)#

Bases: MemoryIOBase

Responsible for converting new observations (textual inputs) into MemoryItems andstoring them via the MemoryEditor.

abstractmethod write(
observation: str,
context: str | None = None,
) list[aiq.memory.models.MemoryItem]#
Async:

Process the given observation and store the resulting MemoryItems.

Args:

observation (str): The new textual input to record. context (Optional[str]): Additional context that might influence how the observation is stored.

Returns:

list[MemoryItem]: The newly created MemoryItems.

class MemoryManager#

Bases: abc.ABC

Manages the lifecycle of the stored memory by applying policies such as summarization, reflection, forgetting, and mergingn to ensure long-term coherence and relevance.

abstractmethod summarize() None#
Async:

Summarize long or numerous MemoryItems into a more compact form. This may remove the original items and store a new summary item.

abstractmethod reflect() None#
Async:

Generate higher-level insights or abstractions from existing MemoryItems. This may call out to an LLM or other logic to produce conceptual memory.

abstractmethod forget(
criteria: collections.abc.Callable[[aiq.memory.models.MemoryItem], bool],
) None#
Async:

Remove MemoryItems that are no longer relevant or have low importance.

Args:

criteria (Callable[[MemoryItem], bool]): A function that returns True for items to forget.

abstractmethod merge(
criteria: collections.abc.Callable[[aiq.memory.models.MemoryItem, aiq.memory.models.MemoryItem], bool],
) None#
Async:

Merge similar or redundant MemoryItems into a smaller set of more concise items.

Args:

criteria (Callable[[MemoryItem, MemoryItem], bool]): A function that determines which items can be merged.