File size: 800 Bytes
1768b63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2949aaa
 
1768b63
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# storage.py (no BOM)
import os, tempfile
from pathlib import Path

def _first_writable(candidates):
    for c in candidates:
        if not c:
            continue
        try:
            p = Path(c)
            p.mkdir(parents=True, exist_ok=True)
            t = p / ".write_test"
            t.write_text("ok", encoding="utf-8")
            try:
                t.unlink()
            except OSError:
                pass
            return p
        except Exception:
            continue
    return Path(tempfile.mkdtemp(prefix="rag_"))

DATA_DIR = _first_writable([
    os.getenv("DATA_DIR") or None,
    "/tmp/rag_data",
    "/app/tmp/rag_data",
    str(Path.home() / ".cache" / "rag_data"),
    "/tmp/rag_data",
])

INDEX_DIR    = DATA_DIR / "index"
HISTORY_JSON = DATA_DIR / "history.json"