Skip to content

Commit a0b1d60

Browse files
committed
abs path fix 2
Signed-off-by: Kevin Guan <kevinwguan@protonmail.com>
1 parent a7450a8 commit a0b1d60

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

backend/src/chains/hybrid_retriever_chain.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def create_hybrid_retriever(self) -> None:
7676
use_cuda=self.use_cuda,
7777
)
7878
if self.vector_db is None:
79-
path = os.path.abspath("faiss_db")
79+
cur_path = os.path.abspath(__file__)
80+
path = os.path.join(cur_path, "../../../", "faiss_db")
81+
path = os.path.abspath(path) # Ensure proper parent directory
8082
load_flag = os.path.isdir(path) # Checks if database already exists
8183
if load_flag:
8284
database_name = similarity_retriever_chain.name

backend/src/vectorstores/faiss.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,22 @@ def add_documents(
190190

191191
return None
192192

193+
def get_db_path(self) -> str:
194+
cur_path = os.path.abspath(__file__)
195+
path = os.path.join(cur_path, "../../../", "faiss_db")
196+
path = os.path.abspath(path) # Ensure proper parent directory
197+
return path
198+
193199
def save_db(self, name) -> None:
194200
if self._faiss_db is None:
195201
raise ValueError("No documents in FAISS database")
196202
else:
197-
self._faiss_db.save_local(f"faiss_db/{name}")
203+
save_path = f"{self.get_db_path()}/{name}"
204+
self._faiss_db.save_local(save_path)
198205

199206
def load_db(self, name) -> None:
200-
self._faiss_db = FAISS.load_local(f"faiss_db/{name}", self.embedding_model, allow_dangerous_deserialization=True)
207+
load_path = f"{self.get_db_path()}/{name}"
208+
self._faiss_db = FAISS.load_local(load_path, self.embedding_model, allow_dangerous_deserialization=True)
201209

202210
def get_documents(self) -> list[Document]:
203211
return self._faiss_db.docstore._dict.values()

0 commit comments

Comments
 (0)