Spaces:
Running
Running
add chmod
Browse files
infrastructure/database.py
CHANGED
|
@@ -49,7 +49,7 @@ def _setup_cache_dir():
|
|
| 49 |
|
| 50 |
_setup_cache_dir()
|
| 51 |
|
| 52 |
-
CHROMA_PATH = os.getenv("CHROMA_PATH", "/data/
|
| 53 |
|
| 54 |
def _init_chroma_client():
|
| 55 |
"""Initialize a Chroma client with robust write tests & fallbacks.
|
|
@@ -75,7 +75,7 @@ def _init_chroma_client():
|
|
| 75 |
force_tmp = os.getenv("CHROMA_FORCE_TMP") in {"1", "true", "yes", "on"}
|
| 76 |
|
| 77 |
candidates: list[Optional[str]] = [
|
| 78 |
-
"/data/
|
| 79 |
if force_tmp:
|
| 80 |
candidates = ["/data/db_tmp"] # override order if forced
|
| 81 |
|
|
@@ -85,11 +85,10 @@ def _init_chroma_client():
|
|
| 85 |
def _dir_writeable(path: str) -> bool:
|
| 86 |
try:
|
| 87 |
_logger.error(f"Ensured directory exists: {path}")
|
| 88 |
-
_logger.error(f"Set directory permissions to 1411: {path}")
|
| 89 |
test_file = os.path.join(path, "write_test.txt")
|
| 90 |
with open(test_file, "x", encoding="utf-8") as tf:
|
| 91 |
tf.write("ok")
|
| 92 |
-
_logger.
|
| 93 |
os.remove(test_file)
|
| 94 |
return True
|
| 95 |
except Exception as e: # pragma: no cover - env specific
|
|
@@ -114,10 +113,13 @@ def _init_chroma_client():
|
|
| 114 |
for fname in os.listdir(abs_path):
|
| 115 |
if any(fname.endswith(ext) for ext in (".sqlite3", ".db", ".duckdb")):
|
| 116 |
fpath = os.path.join(abs_path, fname)
|
|
|
|
| 117 |
if not os.access(fpath, os.W_OK):
|
| 118 |
try:
|
| 119 |
os.chmod(path=fpath, mode=0o777)
|
|
|
|
| 120 |
except Exception:
|
|
|
|
| 121 |
pass
|
| 122 |
except Exception:
|
| 123 |
pass
|
|
|
|
| 49 |
|
| 50 |
_setup_cache_dir()
|
| 51 |
|
| 52 |
+
CHROMA_PATH = os.getenv("CHROMA_PATH", "/data/chroma_data")
|
| 53 |
|
| 54 |
def _init_chroma_client():
|
| 55 |
"""Initialize a Chroma client with robust write tests & fallbacks.
|
|
|
|
| 75 |
force_tmp = os.getenv("CHROMA_FORCE_TMP") in {"1", "true", "yes", "on"}
|
| 76 |
|
| 77 |
candidates: list[Optional[str]] = [
|
| 78 |
+
"/data/chroma_data"]
|
| 79 |
if force_tmp:
|
| 80 |
candidates = ["/data/db_tmp"] # override order if forced
|
| 81 |
|
|
|
|
| 85 |
def _dir_writeable(path: str) -> bool:
|
| 86 |
try:
|
| 87 |
_logger.error(f"Ensured directory exists: {path}")
|
|
|
|
| 88 |
test_file = os.path.join(path, "write_test.txt")
|
| 89 |
with open(test_file, "x", encoding="utf-8") as tf:
|
| 90 |
tf.write("ok")
|
| 91 |
+
_logger.error(f"Directory {path} is writable.")
|
| 92 |
os.remove(test_file)
|
| 93 |
return True
|
| 94 |
except Exception as e: # pragma: no cover - env specific
|
|
|
|
| 113 |
for fname in os.listdir(abs_path):
|
| 114 |
if any(fname.endswith(ext) for ext in (".sqlite3", ".db", ".duckdb")):
|
| 115 |
fpath = os.path.join(abs_path, fname)
|
| 116 |
+
_logger.info(f"Found existing DB file: {fpath}")
|
| 117 |
if not os.access(fpath, os.W_OK):
|
| 118 |
try:
|
| 119 |
os.chmod(path=fpath, mode=0o777)
|
| 120 |
+
_logger.info(f"Set DB file to 777: {fpath}")
|
| 121 |
except Exception:
|
| 122 |
+
_logger.error(f"Failed to set DB file permissions: {fpath}")
|
| 123 |
pass
|
| 124 |
except Exception:
|
| 125 |
pass
|
infrastructure/embeddings.py
CHANGED
|
@@ -40,7 +40,7 @@ from .logger import get_logger
|
|
| 40 |
logger = get_logger()
|
| 41 |
|
| 42 |
DEFAULT_MODEL = os.getenv("EMBEDDING_MODEL", "text-embedding-3-large")
|
| 43 |
-
CHROMA_DATA_PATH = "/data/
|
| 44 |
CHROMA_COLLECTION = "techtrans_rag"
|
| 45 |
|
| 46 |
|
|
|
|
| 40 |
logger = get_logger()
|
| 41 |
|
| 42 |
DEFAULT_MODEL = os.getenv("EMBEDDING_MODEL", "text-embedding-3-large")
|
| 43 |
+
CHROMA_DATA_PATH = "/data/chroma_data"
|
| 44 |
CHROMA_COLLECTION = "techtrans_rag"
|
| 45 |
|
| 46 |
|