Karthikeyen92 commited on
Commit
22482b0
·
verified ·
1 Parent(s): 86f9d48

Update py/db_storage.py

Browse files
Files changed (1) hide show
  1. py/db_storage.py +14 -10
py/db_storage.py CHANGED
@@ -15,18 +15,26 @@ from langchain_community.vectorstores import FAISS
15
 
16
 
17
  warnings.filterwarnings("ignore")
18
- CHROMA_DB_PATH = os.path.join(os.getcwd(), "chroma_db")
19
- # FAISS_DB_PATH = os.path.join(os.getcwd(), "faiss_index")
 
20
  tesla_10k_collection = 'tesla-10k-2019-to-2023'
21
  embedding_model = ""
22
  # embedding_model = SentenceTransformerEmbeddings(model_name='thenlper/gte-large')
23
 
 
 
 
 
 
24
 
25
  class DBStorage:
26
- def __init__(self):
27
  self.CHROMA_PATH = CHROMA_DB_PATH
 
 
28
  self.vector_store = None
29
- self.client = chromadb.PersistentClient(path=CHROMA_DB_PATH)
30
  print(self.client.list_collections())
31
  self.collection = self.client.get_or_create_collection(name=tesla_10k_collection)
32
  print(self.collection.count())
@@ -73,7 +81,7 @@ class DBStorage:
73
  )
74
 
75
  self.vector_store = Chroma(collection_name=tesla_10k_collection,
76
- persist_directory=CHROMA_DB_PATH,
77
  # embedding_function=embeddings
78
  embedding_function=embedding_model
79
  )
@@ -158,13 +166,9 @@ class DBStorage:
158
 
159
  def check_and_delete(PATH):
160
  if os.path.isdir(PATH):
161
- # shutil.rmtree(PATH, onexc=lambda func, path, exc: os.chmod(path, 0o777))
162
- shutil.rmtree(PATH)
163
  print(f'Deleted {PATH}')
164
 
165
- def clear_db():
166
- check_and_delete(CHROMA_DB_PATH)
167
- # check_and_delete(FAISS_DB_PATH)
168
 
169
 
170
  # Usage example
 
15
 
16
 
17
  warnings.filterwarnings("ignore")
18
+ CHROMA_DB_PATH = os.path.join(os.getcwd(), "Stock Sentiment Analysis", "chroma_db")
19
+ CHROMA_DB_PATHH = os.path.join(os.getcwd(), "chroma_db")
20
+ # FAISS_DB_PATH = os.path.join(os.getcwd(), "Stock Sentiment Analysis", "faiss_index")
21
  tesla_10k_collection = 'tesla-10k-2019-to-2023'
22
  embedding_model = ""
23
  # embedding_model = SentenceTransformerEmbeddings(model_name='thenlper/gte-large')
24
 
25
+ def clear_db(hugg = False):
26
+ check_and_delete(CHROMA_DB_PATH)
27
+ if hugg:
28
+ check_and_delete(CHROMA_DB_PATHH)
29
+ # check_and_delete(FAISS_DB_PATH)
30
 
31
  class DBStorage:
32
+ def __init__(self, hugg = False):
33
  self.CHROMA_PATH = CHROMA_DB_PATH
34
+ if hugg:
35
+ self.CHROMA_PATH = CHROMA_DB_PATHH
36
  self.vector_store = None
37
+ self.client = chromadb.PersistentClient(path=self.CHROMA_PATH)
38
  print(self.client.list_collections())
39
  self.collection = self.client.get_or_create_collection(name=tesla_10k_collection)
40
  print(self.collection.count())
 
81
  )
82
 
83
  self.vector_store = Chroma(collection_name=tesla_10k_collection,
84
+ persist_directory=self.CHROMA_PATH,
85
  # embedding_function=embeddings
86
  embedding_function=embedding_model
87
  )
 
166
 
167
  def check_and_delete(PATH):
168
  if os.path.isdir(PATH):
169
+ shutil.rmtree(PATH, onexc=lambda func, path, exc: os.chmod(path, 0o777))
 
170
  print(f'Deleted {PATH}')
171
 
 
 
 
172
 
173
 
174
  # Usage example