feat(maria): depozit local, in afara oglinzii Drive
Dictionarul de erori Oracle pus in `documents/` ar fi disparut in 10 minute: `rclone sync` sterge de acolo tot ce nu exista in Drive. Aceeasi problema o avea si butonul de adaugare document din dashboard — documentul traia pana la urmatorul tur de sincronizare, ceea ce README-ul mentiona ca pe o ciudatenie, nu ca pe un bug. Acum sunt doua directoare cu un singur spatiu de nume: `documents/` (oglinda Drive) si `documents-local/` (ce nu vine din Drive). La acelasi nume castiga Drive-ul — e sursa comuna a echipei, iar copia locala poate fi o versiune veche uitata acolo. Dashboard-ul scrie in cel local si marcheaza documentele „local". Recalibrat cu dictionarul indexat (169 chunk-uri): 19/19, cele patru intrebari Oracle noi ies la 0,73-0,75. Reindexarea a durat cat cele 29 de chunk-uri noi, nu cat toate 169 — refolosirea vectorilor isi face treaba (log: "29 embeddings noi, 140 refolosite"). Verificat pe canalul viu: o escaladare cu captura chiar pleaca pe WhatsApp, imagine + rezumat + referinta, si apare in dashboard. 73 pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q4uzvgm7AyJch5WH8QHRhY
This commit is contained in:
@@ -61,6 +61,9 @@ MARIA_DOC_EXTENSIONS = (".txt", ".md", ".xml")
|
||||
_MARIA_FORMAT_RANK = {".xml": 0, ".md": 1, ".txt": 2}
|
||||
MARIA_STATE_DIR = Path(os.environ.get("MARIA_BRIDGE_DIR") or (Path.home() / ".maria-bridge"))
|
||||
MARIA_DOCS_DIR = MARIA_STATE_DIR / "documents"
|
||||
# Documentele care nu vin din Drive (rclone sync sterge din MARIA_DOCS_DIR tot ce
|
||||
# nu exista in Drive). Oglinda lui rag/config.py:DOCS_LOCAL_DIR.
|
||||
MARIA_DOCS_LOCAL_DIR = MARIA_STATE_DIR / "documents-local"
|
||||
MARIA_INDEX_FILE = MARIA_STATE_DIR / "rag_index.json"
|
||||
MARIA_ENV_FILE = MARIA_STATE_DIR / "env"
|
||||
MARIA_LOG_DIR = MARIA_STATE_DIR / "logs"
|
||||
@@ -144,10 +147,14 @@ def maria_documents() -> list[dict]:
|
||||
Nu importam modulul acela: si el, si `discord-bridge/config.py` s-ar numi `config`.
|
||||
"""
|
||||
MARIA_DOCS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
files = [
|
||||
f for f in sorted(MARIA_DOCS_DIR.glob("*"))
|
||||
if f.is_file() and f.suffix in MARIA_DOC_EXTENSIONS
|
||||
]
|
||||
vazute: dict[str, Path] = {}
|
||||
for d in (MARIA_DOCS_LOCAL_DIR, MARIA_DOCS_DIR): # Drive ultimul = castiga la acelasi nume
|
||||
if not d.is_dir():
|
||||
continue
|
||||
for f in sorted(d.glob("*")):
|
||||
if f.is_file() and f.suffix in MARIA_DOC_EXTENSIONS:
|
||||
vazute[f.name] = f
|
||||
files = [vazute[n] for n in sorted(vazute)]
|
||||
winners: dict[str, str] = {}
|
||||
for f in files:
|
||||
best = winners.get(f.stem)
|
||||
@@ -162,6 +169,7 @@ def maria_documents() -> list[dict]:
|
||||
"name": f.name,
|
||||
"size": st.st_size,
|
||||
"mtime": st.st_mtime,
|
||||
"local": f.parent == MARIA_DOCS_LOCAL_DIR,
|
||||
"shadowed_by": None if winner == f.name else winner,
|
||||
})
|
||||
return out
|
||||
@@ -206,18 +214,29 @@ def _maria_validate_name(name: str) -> str:
|
||||
|
||||
|
||||
def maria_write_document(name: str, content: str) -> None:
|
||||
"""Scrie in documents-local/, nu in oglinda Drive.
|
||||
|
||||
Pana acum ajungea in `documents/` si disparea la urmatorul `rclone sync` —
|
||||
documentul adaugat din dashboard traia pana la 10 minute.
|
||||
"""
|
||||
name = _maria_validate_name(name)
|
||||
MARIA_DOCS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
(MARIA_DOCS_DIR / name).write_text(content, encoding="utf-8")
|
||||
MARIA_DOCS_LOCAL_DIR.mkdir(parents=True, exist_ok=True)
|
||||
(MARIA_DOCS_LOCAL_DIR / name).write_text(content, encoding="utf-8")
|
||||
|
||||
|
||||
def maria_delete_document(name: str) -> bool:
|
||||
"""Sterge documentul din oricare din cele doua directoare.
|
||||
|
||||
Cel din Drive revine la urmatoarea sincronizare — sterge-l din Drive daca vrei
|
||||
sa dispara definitiv.
|
||||
"""
|
||||
name = _maria_validate_name(name)
|
||||
path = MARIA_DOCS_DIR / name
|
||||
if not path.exists():
|
||||
return False
|
||||
path.unlink()
|
||||
return True
|
||||
for d in (MARIA_DOCS_DIR, MARIA_DOCS_LOCAL_DIR):
|
||||
path = d / name
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _maria_run(script: str, timeout: float = 600.0, extra_args: list[str] | None = None) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user