HallD commited on
Commit
d449956
·
verified ·
1 Parent(s): 20f5be1

Update utils/vector_db.py

Browse files
Files changed (1) hide show
  1. utils/vector_db.py +11 -9
utils/vector_db.py CHANGED
@@ -7,7 +7,6 @@ from typing import Any, Iterable, Optional, Sequence
7
  import chromadb as cdb
8
  import dotenv
9
  from langchain_openai import OpenAIEmbeddings
10
- from utils.text_processing import DocumentProcessing
11
 
12
 
13
  dotenv.load_dotenv()
@@ -52,15 +51,18 @@ class VectorDB:
52
 
53
  # Auto-initialize from 'me/' if empty and the directory exists
54
  try:
55
- if self.collection.count() == 0 and os.path.isdir(os.path.join(Path(__file__).resolve().parent.parent, "me")):
56
- try:
57
- # Avoid circular import issues and heavy work if OPENAI key missing
58
- if os.getenv("OPENAI_API_KEY"):
 
 
 
59
  dp = DocumentProcessing()
60
- dp.create_vector_db_from_directory(os.path.join(Path(__file__).resolve().parent.parent, "me"))
61
- except Exception:
62
- # If auto-build fails, continue with empty DB; app will still run
63
- pass
64
  except Exception:
65
  pass
66
 
 
7
  import chromadb as cdb
8
  import dotenv
9
  from langchain_openai import OpenAIEmbeddings
 
10
 
11
 
12
  dotenv.load_dotenv()
 
51
 
52
  # Auto-initialize from 'me/' if empty and the directory exists
53
  try:
54
+ project_root = Path(__file__).resolve().parent.parent
55
+ me_path = project_root / "me"
56
+ if self.collection.count() == 0 and me_path.is_dir():
57
+ if os.getenv("OPENAI_API_KEY"):
58
+ try:
59
+ from utils.text_processing import DocumentProcessing
60
+
61
  dp = DocumentProcessing()
62
+ dp.create_vector_db_from_directory(str(me_path))
63
+ except Exception:
64
+ # If auto-build fails, continue with empty DB; app will still run
65
+ pass
66
  except Exception:
67
  pass
68