Skip to content

add file store for memory plugin #111

Open
@kishoretvk

Description

@kishoretvk

can we add fiel store for the memory plugin? so we can give a permanent storage
i added a sample code below. let me know if its a good plan to add it will submit a PR

  1. using json to save data
  2. load data from a file on initialization

``def save_to_file(self):
today_date = datetime.today().strftime('%Y-%m-%d')
filename = f"memory-{today_date}.json"
try:
if os.path.exists(filename):
with open(filename, 'r') as f:
existing_data = json.load(f)
else:
existing_data = []

    combined_data = existing_data + self.items

    with open(filename, 'w') as f:
        json.dump(combined_data, f)
except IOError as e:
    print(f"Error saving memory to file: {e}")

``

Load form file

def load_from_file(self):
today_date = datetime.today().strftime('%Y-%m-%d')
filename = f"memory-{today_date}.json"
try:
with open(filename, 'r') as f:
self.items = json.load(f)
self.vectors = self.vectorizer.fit_transform(self.items)
except (IOError, json.JSONDecodeError) as e:
print(f"Error loading memory from file or file does not exist: {e}")
self.items = []
self.vectors = None

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions