phaethon-order commited on
Commit
49354f6
·
unverified ·
1 Parent(s): ca8ecc7

Update ChromaDB path to use absolute directory for improved reliability

Browse files
infrastructure/chunker.py CHANGED
@@ -364,16 +364,13 @@ def chunk_doc(text: str, doc_id: str, max_chars: int = 1200, overlap: int = 150,
364
  rec['next_id'] = chunk_metadata_records[i+1]['index']
365
 
366
  # Write / upsert JSONL file
367
- os.makedirs(os.path.dirname(CHUNKS_DIR), exist_ok=True)
368
  records = json.dumps(chunk_metadata_records, ensure_ascii=False, indent=0)
369
  path = os.path.join(CHUNKS_DIR, "chunks.jsonl")
370
 
371
  try:
372
- with open(path, "r+", encoding="utf-8") as f:
373
- existing = f.read()
374
- f.seek(0)
375
- updated = existing + "\n" + records if existing else records
376
- f.write(updated)
377
  logger.info(f"Appended {len(chunk_metadata_records)} chunk records to existing chunks file {path}")
378
  except FileNotFoundError:
379
  with open(path, "w", encoding="utf-8") as f:
 
364
  rec['next_id'] = chunk_metadata_records[i+1]['index']
365
 
366
  # Write / upsert JSONL file
367
+ os.makedirs(CHUNKS_DIR, exist_ok=True)
368
  records = json.dumps(chunk_metadata_records, ensure_ascii=False, indent=0)
369
  path = os.path.join(CHUNKS_DIR, "chunks.jsonl")
370
 
371
  try:
372
+ with open(path, "a", encoding="utf-8") as f:
373
+ f.write(records)
 
 
 
374
  logger.info(f"Appended {len(chunk_metadata_records)} chunk records to existing chunks file {path}")
375
  except FileNotFoundError:
376
  with open(path, "w", encoding="utf-8") as f:
infrastructure/database.py CHANGED
@@ -27,7 +27,7 @@ SEG_VER = int(os.getenv("SEG_VER", "1"))
27
  # ---------------------------------------------------------------------------
28
  # ChromaDB client setup (with HuggingFace / read-only filesystem resilience)
29
  # ---------------------------------------------------------------------------
30
- CHROMA_PATH = os.getenv("CHROMA_PATH", "chroma_db")
31
 
32
  def _init_chroma_client():
33
  """Initialize a Chroma client with fallbacks.
@@ -37,7 +37,7 @@ def _init_chroma_client():
37
  2. /tmp/chroma_db (writable in most containerized envs incl. HF Spaces)
38
  3. In-memory (non-persistent) client as last resort
39
  """
40
- candidates: list[Optional[str]] = [CHROMA_PATH, "/tmp/chroma_db"]
41
  tried: list[tuple[Optional[str], str]] = []
42
 
43
  for cand in candidates:
 
27
  # ---------------------------------------------------------------------------
28
  # ChromaDB client setup (with HuggingFace / read-only filesystem resilience)
29
  # ---------------------------------------------------------------------------
30
+ CHROMA_PATH = os.getenv("CHROMA_PATH", "/data/chroma_db")
31
 
32
  def _init_chroma_client():
33
  """Initialize a Chroma client with fallbacks.
 
37
  2. /tmp/chroma_db (writable in most containerized envs incl. HF Spaces)
38
  3. In-memory (non-persistent) client as last resort
39
  """
40
+ candidates: list[Optional[str]] = [CHROMA_PATH, "/data/chroma_db"]
41
  tried: list[tuple[Optional[str], str]] = []
42
 
43
  for cand in candidates:
infrastructure/document_processor.py CHANGED
@@ -16,8 +16,8 @@ from datetime import datetime, timezone
16
  logger = get_logger()
17
 
18
  API_KEY = os.getenv("OPENAI_API_KEY")
19
- MANIFEST_DIR = os.getenv("MANIFEST_DIR", "data/manifest")
20
- CHUNKS_DIR = os.getenv("CHUNKS_DIR", "data/chunks")
21
 
22
  def ocr_page(page: fitz.Page, zoom: float = 2.0) -> str:
23
  mat = fitz.Matrix(zoom, zoom)
@@ -263,7 +263,7 @@ def upsert_manifest_record(text: str, size: str, doc_id: str, sha256: str, sourc
263
  manifest_path = MANIFEST_DIR + "/manifest.jsonl"
264
 
265
  try:
266
- os.makedirs(os.path.dirname(MANIFEST_DIR), exist_ok=True)
267
 
268
  with open(manifest_path, "a", encoding="utf-8") as f:
269
  f.write(line)
 
16
  logger = get_logger()
17
 
18
  API_KEY = os.getenv("OPENAI_API_KEY")
19
+ MANIFEST_DIR = os.getenv("MANIFEST_DIR", "/data/manifest")
20
+ CHUNKS_DIR = os.getenv("CHUNKS_DIR", "/data/chunks")
21
 
22
  def ocr_page(page: fitz.Page, zoom: float = 2.0) -> str:
23
  mat = fitz.Matrix(zoom, zoom)
 
263
  manifest_path = MANIFEST_DIR + "/manifest.jsonl"
264
 
265
  try:
266
+ os.makedirs(MANIFEST_DIR, exist_ok=True)
267
 
268
  with open(manifest_path, "a", encoding="utf-8") as f:
269
  f.write(line)
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 = "chroma_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_db"
44
  CHROMA_COLLECTION = "techtrans_rag"
45
 
46