MohammedNasser commited on
Commit
1511464
1 Parent(s): 30b68de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -42,15 +42,24 @@ def load_pdf(file_path):
42
  return documents
43
 
44
  def prepare_vectorstore(data):
 
 
 
45
  text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=20, separator="\n")
46
  texts = data
47
  vectorstore = FAISS.from_texts(texts, embeddings)
48
- vectorstore.save_local("faiss_index")
49
 
50
  return vectorstore
51
 
52
  def load_vectorstore():
53
- vectorstore = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
 
 
 
 
 
 
54
  return vectorstore
55
 
56
  def create_chain(vectorstore):
 
42
  return documents
43
 
44
  def prepare_vectorstore(data):
45
+ index_dir = "faiss_index"
46
+ if not os.path.exists(index_dir):
47
+ os.makedirs(index_dir)
48
  text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=20, separator="\n")
49
  texts = data
50
  vectorstore = FAISS.from_texts(texts, embeddings)
51
+ vectorstore.save_local(index_dir)
52
 
53
  return vectorstore
54
 
55
  def load_vectorstore():
56
+ index_dir = "faiss_index"
57
+
58
+ # Ensure the directory exists before trying to load the index
59
+ if not os.path.exists(index_dir):
60
+ raise RuntimeError(f"FAISS index directory '{index_dir}' does not exist.")
61
+
62
+ vectorstore = FAISS.load_local(index_dir, embeddings, allow_dangerous_deserialization=True)
63
  return vectorstore
64
 
65
  def create_chain(vectorstore):