SoumyaJ commited on
Commit
8451d71
·
verified ·
1 Parent(s): 7e780fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -35,7 +35,7 @@ app.add_middleware(
35
  UPLOAD_DIR = "uploads"
36
  os.makedirs(UPLOAD_DIR, exist_ok=True)
37
 
38
- persist_directory = "./chroma_db"
39
 
40
  load_dotenv()
41
  os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
@@ -64,7 +64,8 @@ def generate_file_id(file_path):
64
 
65
  def delete_existing_embedding(file_id):
66
  if os.path.exists(persist_directory):
67
- shutil.rmtree(persist_directory)
 
68
 
69
  def tempUploadFile(filePath,file):
70
  with open(filePath,'wb') as buffer:
@@ -111,7 +112,7 @@ def loadAndSplitPdfFile(filePath):
111
 
112
  def prepare_retriever(filePath = "", load_from_chromadb = False):
113
  if load_from_chromadb:
114
- vector_store = Chroma(persist_directory=persist_directory, embedding_function = embeddings)
115
  return vector_store.as_retriever(search_kwargs={"k": 5})
116
  elif filePath:
117
  doc_chunks = loadAndSplitPdfFile(filePath)
@@ -125,7 +126,7 @@ def prepare_retriever(filePath = "", load_from_chromadb = False):
125
  if isinstance(value, (str, int, float, bool, Path))
126
  }
127
 
128
- vector_store = Chroma.from_documents(documents= doc_chunks, persist_directory=persist_directory, embedding= embeddings)
129
  vector_store.persist()
130
 
131
  def get_retriever_chain(retriever):
 
35
  UPLOAD_DIR = "uploads"
36
  os.makedirs(UPLOAD_DIR, exist_ok=True)
37
 
38
+ persist_directory = "/home/user/.cache/chroma_db"
39
 
40
  load_dotenv()
41
  os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
 
64
 
65
  def delete_existing_embedding(file_id):
66
  if os.path.exists(persist_directory):
67
+ shutil.rmtree(persist_directory, ignore_errors = True)
68
+ os.makedirs(persist_directory, exist_ok=True)
69
 
70
  def tempUploadFile(filePath,file):
71
  with open(filePath,'wb') as buffer:
 
112
 
113
  def prepare_retriever(filePath = "", load_from_chromadb = False):
114
  if load_from_chromadb:
115
+ vector_store = Chroma(persist_directory=persist_directory, embedding_function = embeddings, client_settings={"allow_reset": True})
116
  return vector_store.as_retriever(search_kwargs={"k": 5})
117
  elif filePath:
118
  doc_chunks = loadAndSplitPdfFile(filePath)
 
126
  if isinstance(value, (str, int, float, bool, Path))
127
  }
128
 
129
+ vector_store = Chroma.from_documents(documents= doc_chunks, persist_directory=persist_directory, embedding= embeddings, read)
130
  vector_store.persist()
131
 
132
  def get_retriever_chain(retriever):