Spaces:
Sleeping
Sleeping
Update utils/vector_db.py
Browse files- 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 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
dp = DocumentProcessing()
|
| 60 |
-
dp.create_vector_db_from_directory(
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 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 |
|