From 62bd93a4d2bf24b9e99e4598cb37e3f722f1f113 Mon Sep 17 00:00:00 2001 From: Merwane Hamadi Date: Wed, 12 Apr 2023 17:48:08 -0700 Subject: [PATCH 1/2] Import NoMemory and add it as a memory_backend option in get_memory function --- scripts/memory/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/memory/__init__.py b/scripts/memory/__init__.py index a07f9fd8..d407f087 100644 --- a/scripts/memory/__init__.py +++ b/scripts/memory/__init__.py @@ -1,4 +1,5 @@ from memory.local import LocalCache +from memory.no_memory import NoMemory # List of supported memory backends # Add a backend to this list if the import attempt is successful @@ -34,6 +35,8 @@ def get_memory(cfg, init=False): " use Redis as a memory backend.") else: memory = RedisMemory(cfg) + elif cfg.memory_backend == "no_memory": + memory = NoMemory(cfg) if memory is None: memory = LocalCache(cfg) @@ -50,4 +53,5 @@ __all__ = [ "LocalCache", "RedisMemory", "PineconeMemory", + "NoMemory" ] From 84c128fd0facca6a4f27c52a1032656d97abfc72 Mon Sep 17 00:00:00 2001 From: Merwane Hamadi Date: Wed, 12 Apr 2023 17:48:11 -0700 Subject: [PATCH 2/2] Create NoMemory provider as a memory provider that does not store any data --- scripts/memory/no_memory.py | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 scripts/memory/no_memory.py diff --git a/scripts/memory/no_memory.py b/scripts/memory/no_memory.py new file mode 100644 index 00000000..45dbd734 --- /dev/null +++ b/scripts/memory/no_memory.py @@ -0,0 +1,65 @@ +from typing import Optional, List, Any + +from memory.base import MemoryProviderSingleton + +class NoMemory(MemoryProviderSingleton): + def __init__(self, cfg): + """ + Initializes the NoMemory provider. + + Args: + cfg: The config object. + + Returns: None + """ + pass + + def add(self, data: str) -> str: + """ + Adds a data point to the memory. No action is taken in NoMemory. + + Args: + data: The data to add. + + Returns: An empty string. + """ + return "" + + def get(self, data: str) -> Optional[List[Any]]: + """ + Gets the data from the memory that is most relevant to the given data. + NoMemory always returns None. + + Args: + data: The data to compare to. + + Returns: None + """ + return None + + def clear(self) -> str: + """ + Clears the memory. No action is taken in NoMemory. + + Returns: An empty string. + """ + return "" + + def get_relevant(self, data: str, num_relevant: int = 5) -> Optional[List[Any]]: + """ + Returns all the data in the memory that is relevant to the given data. + NoMemory always returns None. + + Args: + data: The data to compare to. + num_relevant: The number of relevant data to return. + + Returns: None + """ + return None + + def get_stats(self): + """ + Returns: An empty dictionary as there are no stats in NoMemory. + """ + return {}