@@ -99,18 +99,18 @@ def execute(self, state: dict) -> dict:
99
99
)
100
100
embeddings = self .embedder_model
101
101
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 )
111
112
112
113
retriever = index .as_retriever ()
113
- #------
114
114
115
115
redundant_filter = EmbeddingsRedundantFilter (embeddings = embeddings )
116
116
# similarity_threshold could be set, now k=20
@@ -133,4 +133,4 @@ def execute(self, state: dict) -> dict:
133
133
self .logger .info ("--- (tokens compressed and vector stored) ---" )
134
134
135
135
state .update ({self .output [0 ]: compressed_docs })
136
- return state
136
+ return state
0 commit comments