@@ -99,18 +99,18 @@ def execute(self, state: dict) -> dict:
9999 )
100100 embeddings = self .embedder_model
101101
102- #------
103- index = FAISS .from_documents (chunked_docs , embeddings )
104- # Define the folder name
105- folder_name = "cache"
106- # Check if the folder exists, if not, create it
107- if not os .path .exists (folder_name ):
108- os .makedirs (folder_name )
109- # Save the index to the folder
110- index .save_local (folder_name )
102+ if self .node_config .get ("cache" , False ):
103+ index = FAISS .from_documents (chunked_docs , embeddings )
104+ folder_name = "cache"
105+
106+ if not os .path .exists (folder_name ):
107+ os .makedirs (folder_name )
108+
109+ index .save_local (folder_name )
110+ else :
111+ index = FAISS .from_documents (chunked_docs , embeddings )
111112
112113 retriever = index .as_retriever ()
113- #------
114114
115115 redundant_filter = EmbeddingsRedundantFilter (embeddings = embeddings )
116116 # similarity_threshold could be set, now k=20
@@ -133,4 +133,4 @@ def execute(self, state: dict) -> dict:
133133 self .logger .info ("--- (tokens compressed and vector stored) ---" )
134134
135135 state .update ({self .output [0 ]: compressed_docs })
136- return state
136+ return state
0 commit comments