b04823e67b
Persist uploaded files to {data_dir}/documents/{content_hash}{ext} after
successful ingestion. Add GET /documents/{id}/file endpoint for retrieval,
delete stored files on document deletion, and add `kb export` client command.
Includes schema migration, tests, and spec updates.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
"""Engine configuration — all settings from environment variables."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
class Config:
|
|
data_dir: Path
|
|
model: str
|
|
device: str
|
|
ingest_device: str
|
|
api_key: str | None
|
|
host: str
|
|
port: int
|
|
|
|
def __init__(self):
|
|
self.data_dir = Path(os.environ.get("KB_DATA_DIR", "/data"))
|
|
self.model = os.environ.get("KB_MODEL", "all-MiniLM-L6-v2")
|
|
self.device = os.environ.get("KB_DEVICE", "auto")
|
|
self.ingest_device = os.environ.get("KB_INGEST_DEVICE", "auto")
|
|
self.api_key = os.environ.get("KB_API_KEY") or None
|
|
self.search_threshold = float(os.environ.get("KB_SEARCH_THRESHOLD", "0.01"))
|
|
self.host = os.environ.get("KB_HOST", "0.0.0.0")
|
|
self.port = int(os.environ.get("KB_PORT", "8000"))
|
|
|
|
@property
|
|
def db_path(self) -> Path:
|
|
return self.data_dir / "kb.db"
|
|
|
|
@property
|
|
def hf_cache(self) -> Path:
|
|
return self.data_dir / "hf_cache"
|
|
|
|
@property
|
|
def staging_dir(self) -> Path:
|
|
return self.data_dir / "staging"
|
|
|
|
@property
|
|
def documents_dir(self) -> Path:
|
|
return self.data_dir / "documents"
|
|
|
|
def ensure_dirs(self):
|
|
self.data_dir.mkdir(parents=True, exist_ok=True)
|
|
self.hf_cache.mkdir(exist_ok=True)
|
|
self.staging_dir.mkdir(exist_ok=True)
|
|
self.documents_dir.mkdir(exist_ok=True)
|
|
|
|
|
|
cfg = Config()
|