memoryscope.core.storage.base_memory_store

class memoryscope.core.storage.base_memory_store.BaseMemoryStore[source]

Bases: object

An abstract base class defining the interface for a memory store which handles memory nodes. It outlines essential operations like retrieval, updating, flushing, and closing of memory scopes.

abstract retrieve_memories(query: str = '', top_k: int = 3, filter_dict: Dict[str, List[str]] | None = None) List[MemoryNode][source]

Retrieves a list of MemoryNode objects that are most relevant to the query, considering a filter dictionary for additional constraints. The number of nodes returned is limited by top_k.

Parameters:
  • query (str) – The query string used to find relevant memories.

  • top_k (int) – The maximum number of MemoryNode objects to return.

  • filter_dict (Dict[str, List[str]]) – A dictionary with keys representing filter fields and values as lists of strings for filtering criteria.

Returns:

A list of MemoryNode objects sorted by relevance to the query,

limited to top_k items.

Return type:

List[MemoryNode]

abstract async a_retrieve_memories(query: str = '', top_k: int = 3, filter_dict: Dict[str, List[str]] | None = None) List[MemoryNode][source]

Asynchronously retrieves a list of MemoryNode objects that best match the query, respecting a filter dictionary, with the result size capped at top_k.

Parameters:
  • query (str) – The text to search for in memory nodes.

  • top_k (int) – Maximum number of nodes to return.

  • filter_dict (Dict[str, List[str]]) – Filters to apply on memory nodes.

Returns:

A list of up to top_k MemoryNode objects matching the criteria.

Return type:

List[MemoryNode]

abstract batch_insert(nodes: List[MemoryNode])[source]
abstract batch_update(nodes: List[MemoryNode], update_embedding: bool = True)[source]
abstract batch_delete(nodes: List[MemoryNode])[source]
flush()[source]

Flushes any pending memory updates or operations to ensure data consistency. This method should be overridden by subclasses to provide the specific flushing mechanism.

abstract close()[source]

Closes the memory store, releasing any resources associated with it. Subclasses must implement this method to define how the memory store is properly closed.