Skip to content

Python scraper based on AI

feat: add caching

Marco Vinciguerrad79036149a31
diff --git a/scrapegraphai/nodes/rag_node.py b/scrapegraphai/nodes/rag_node.py
index bc239ebb..9c4dc164 100644
--- a/scrapegraphai/nodes/rag_node.py
+++ b/scrapegraphai/nodes/rag_node.py
@@ -99,14 +99,15 @@ class RAGNode(BaseNode):
)
embeddings = self.embedder_model
- if self.node_config.get("cache", False):
- index = FAISS.from_documents(chunked_docs, embeddings)
- folder_name = "cache"
+ folder_name = "cache"
- if not os.path.exists(folder_name):
- os.makedirs(folder_name)
+ if self.node_config.get("cache", False) and not os.path.exists(folder_name):
+ index = FAISS.from_documents(chunked_docs, embeddings)
+ os.makedirs(folder_name)
index.save_local(folder_name)
+ if self.node_config.get("cache", False) and os.path.exists(folder_name):
+ index = FAISS.load_local(folder_path=folder_name, embeddings=embeddings)
else:
index = FAISS.from_documents(chunked_docs, embeddings)