nitdaa / manage_db.py
Sam-max1's picture
Upload folder using huggingface_hub
af8ac78 verified
Raw
History Blame
4.56 kB
#!/usr/bin/env python3
"""Manage HealthExpert databases.
Database plan:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Database β”‚ Management β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ ChromaDB β”‚ Embedded (in-process). No Docker container. β”‚
β”‚ (Vector Store) β”‚ Data stored at: data/chroma_db/ β”‚
β”‚ β”‚ Managed by: pipeline/vector_store.py β”‚
β”‚ β”‚ Use /api/admin/purge (UI) or wipe data/chroma_db/ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Kuzu β”‚ Embedded (in-process). No Docker container. β”‚
β”‚ (Graph DB) β”‚ Data stored at: data/kuzu_db/ β”‚
β”‚ β”‚ Managed by: pipeline/graph_store.py β”‚
β”‚ β”‚ Use /api/admin/purge (UI) or wipe data/kuzu_db/ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Usage:
python manage_db.py # show status of all databases
python manage_db.py -chroma # show ChromaDB data directory info
python manage_db.py -kuzu # show Kuzu data directory info
"""
import argparse
import sys
import os
from pathlib import Path
CHROMA_DIR = Path(__file__).parent / "data" / "chroma_db"
KUZU_DIR = Path(__file__).parent / "data" / "kuzu_db"
def _dir_info(path: Path) -> dict:
exists = path.exists()
size_mb = 0.0
file_count = 0
if exists:
for f in path.rglob("*"):
if f.is_file():
size_mb += f.stat().st_size / 1024 ** 2
file_count += 1
return {"exists": exists, "path": str(path), "size_mb": size_mb, "files": file_count}
def chroma_status() -> None:
info = _dir_info(CHROMA_DIR)
print("\n── ChromaDB (Vector Store) ──────────────────────────────────")
print(f" Type : Embedded (in-process, no server)")
print(f" Data dir : {info['path']}")
if info["exists"]:
print(f" Status : PRESENT ({info['files']} files, {info['size_mb']:.2f} MB)")
else:
print(f" Status : EMPTY (will be created on first ingest)")
print("─" * 60)
def kuzu_status() -> None:
info = _dir_info(KUZU_DIR)
print("\n── Kuzu (Graph DB) ──────────────────────────────────────────")
print(f" Type : Embedded (in-process, no server)")
print(f" Data dir : {info['path']}")
if info["exists"]:
print(f" Status : PRESENT ({info['files']} files, {info['size_mb']:.2f} MB)")
else:
print(f" Status : EMPTY (will be created on first ingest)")
print("─" * 60)
def status() -> None:
print("\n══════════════════════════════════════════════════════════════")
print(" HealthExpert β€” Database Status")
print("══════════════════════════════════════════════════════════════")
chroma_status()
kuzu_status()
print("")
def main() -> None:
parser = argparse.ArgumentParser(
description="Manage HealthExpert databases",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=__doc__,
)
parser.add_argument("-chroma", action="store_true", help="Show ChromaDB info")
parser.add_argument("-kuzu", action="store_true", help="Show Kuzu DB info")
args = parser.parse_args()
if args.chroma: chroma_status()
elif args.kuzu: kuzu_status()
else: status()
if __name__ == "__main__":
main()