File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments