From e5a2f4d54e425e4f44ea7997f4590314ce5b0402 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 9 Jan 2024 18:35:10 +0100 Subject: [PATCH] Fix #10 - Fix index out of bounds when database is empty --- vectordb/memory.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vectordb/memory.py b/vectordb/memory.py index b2a4dcb..a5a8d47 100644 --- a/vectordb/memory.py +++ b/vectordb/memory.py @@ -39,7 +39,7 @@ def __init__( self.memory = [] self.metadata_memory = [] else: - load = Storage(memory_file).load_from_disk() + 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"] @@ -150,8 +150,9 @@ def search( else: query_embedding = self.embedder.embed_text([query])[0] - embeddings = [entry["embedding"] for entry in self.memory] + if len(embeddings) == 0: + return [] indices = self.vector_search.search_vectors(query_embedding, embeddings, top_n, batch_results) if unique: