pradeepsengarr commited on
Commit
2183bfd
·
verified ·
1 Parent(s): f05c81d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -477,14 +477,25 @@ def process_answer(question, full_text):
477
  # Load embeddings
478
  embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
479
 
480
- # Create a temporary directory for ChromaDB
 
 
 
 
 
481
  chroma_dir = os.path.join(tempfile.gettempdir(), "chroma_db")
 
 
482
  if os.path.exists(chroma_dir):
483
  shutil.rmtree(chroma_dir)
484
-
 
 
485
  db = Chroma.from_documents(splits, embeddings, persist_directory=chroma_dir)
 
486
  retriever = db.as_retriever()
487
 
 
488
  # Set up the model
489
  llm = load_model()
490
 
 
477
  # Load embeddings
478
  embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
479
 
480
+
481
+ import tempfile
482
+ import os
483
+ import shutil
484
+
485
+ # Use a safe, writable temp directory
486
  chroma_dir = os.path.join(tempfile.gettempdir(), "chroma_db")
487
+
488
+ # Clean up old data and recreate
489
  if os.path.exists(chroma_dir):
490
  shutil.rmtree(chroma_dir)
491
+ os.makedirs(chroma_dir, exist_ok=True)
492
+
493
+ # Create vectorstore and retriever
494
  db = Chroma.from_documents(splits, embeddings, persist_directory=chroma_dir)
495
+ db.persist() # Optional: Saves data to disk for reuse within the same session
496
  retriever = db.as_retriever()
497
 
498
+
499
  # Set up the model
500
  llm = load_model()
501