"""Central construction of deployment-specific adapters.""" from tht.adapters.dwh import PostgresDwhAdapter, ThothRestDwhAdapter from tht.adapters.vector import QdrantVectorStore from tht.config import Config, ConfigError from tht.ports.dwh import DwhAdapter from tht.ports.vector import VectorStore def build_dwh(cfg: Config) -> DwhAdapter: """Build the DWH adapter selected by the validated workspace resource.""" resource = cfg.dwh match resource.type: case "postgres_direct": return PostgresDwhAdapter( resource.connection, statement_timeout_ms=cfg.execution.statement_timeout_ms, ) case "thoth_rest": return ThothRestDwhAdapter(resource.database, resource.endpoint) case other: # pragma: no cover - Pydantic's discriminator rejects this first. raise ConfigError(f"Adapter DWH non supportato: {other}") def build_vector_store(cfg: Config, *, require_write: bool = False) -> VectorStore: """Build the vector adapter, optionally requiring write capability.""" resource = cfg.vectors if resource is None: raise ConfigError("Risorsa vectors non configurata") match resource.type: case "qdrant": return QdrantVectorStore( base_url=resource.base_url, collections=resource.collections, workspace_id=cfg._workspace_id, workspace_revision=cfg._workspace_revision, expected_dimension=cfg.embeddings.dim if cfg.embeddings is not None else None, collection_lifecycle=resource.collection_lifecycle, ) case other: # pragma: no cover - Pydantic's discriminator rejects this first. raise ConfigError(f"Adapter vector non supportato: {other}") __all__ = ["build_dwh", "build_vector_store"]