Skip to content

Commit d790361

Browse files
committed
feat: add caching
1 parent 7ed2fe8 commit d790361

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scrapegraphai/nodes/rag_node.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ def execute(self, state: dict) -> dict:
9999
)
100100
embeddings = self.embedder_model
101101

102-
if self.node_config.get("cache", False):
103-
index = FAISS.from_documents(chunked_docs, embeddings)
104-
folder_name = "cache"
102+
folder_name = "cache"
105103

106-
if not os.path.exists(folder_name):
107-
os.makedirs(folder_name)
104+
if self.node_config.get("cache", False) and not os.path.exists(folder_name):
105+
index = FAISS.from_documents(chunked_docs, embeddings)
106+
os.makedirs(folder_name)
108107

109108
index.save_local(folder_name)
109+
if self.node_config.get("cache", False) and os.path.exists(folder_name):
110+
index = FAISS.load_local(folder_path=folder_name, embeddings=embeddings)
110111
else:
111112
index = FAISS.from_documents(chunked_docs, embeddings)
112113

0 commit comments

Comments
 (0)