Skip to content

Commit

Permalink
Merge pull request #6 from AWAS666/main
Browse files Browse the repository at this point in the history
Save to disk broken after resource split
  • Loading branch information
vprelovac authored Nov 1, 2023
2 parents 5f91db6 + 9d1e53e commit a1ae208
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions vectordb/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ def __init__(
"""
self.memory_file = memory_file

self.memory = (
[] if memory_file is None else Storage(memory_file).load_from_disk()
)
if memory_file is None:
self.memory = []
self.metadata_memory = []
else:
load = Storage(memory_file).load_from_disk()
self.memory = [] if len(load) != 1 else load[0]["memory"]
self.metadata_memory = [] if len(load) != 1 else load[0]["metadata"]

if chunking_strategy is None:
chunking_strategy = {"mode": "sliding_window"}
self.chunker = Chunker(chunking_strategy)

self.metadata_memory = []
self.metadata_index_counter = 0
self.text_index_counter = 0

Expand Down Expand Up @@ -126,7 +130,7 @@ def save(
self.memory.append(entry)

if memory_file is not None:
Storage(memory_file).save_to_disk(self.memory)
Storage(self.memory_file).save_to_disk([{"memory": self.memory, "metadata" :self.metadata_memory}])

def search(
self, query: str, top_n: int = 5, unique: bool = False, batch_results: str = "flatten"
Expand Down Expand Up @@ -187,7 +191,7 @@ def clear(self):
self.text_index_counter = 0

if self.memory_file is not None:
Storage(self.memory_file).save_to_disk(self.memory)
Storage(self.memory_file).save_to_disk([{"memory": self.memory, "metadata" :self.metadata_memory}])

def dump(self):
"""
Expand Down

0 comments on commit a1ae208

Please sign in to comment.