diff --git a/docs/configuration.md b/docs/configuration.md index 529841f0..9094052a 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -211,6 +211,16 @@ Authentication is handled through standard cloud provider credentials (AWS CLI, **Note:** Table optimization is automatically handled by LanceDB Cloud (`db://` URIs) and is disabled for better performance. For object storage backends (S3, Azure, GCS), optimization is still performed locally. +#### Disable database auto-creation + +By default, haiku.rag creates the local LanceDB directory and required tables on first use. To prevent accidental database creation and fail fast if a database hasn’t been set up yet, set: + +```bash +DISABLE_DB_AUTOCREATE=true +``` + +When enabled, for local paths, haiku.rag errors if the LanceDB directory does not exist, and it will not create parent directories. + ### Document Processing ```bash diff --git a/src/haiku/rag/client.py b/src/haiku/rag/client.py index 20e5b089..9a6b89ec 100644 --- a/src/haiku/rag/client.py +++ b/src/haiku/rag/client.py @@ -33,8 +33,6 @@ class HaikuRAG: db_path: Path to the database file. skip_validation: Whether to skip configuration validation on database load. """ - if not db_path.parent.exists(): - Path.mkdir(db_path.parent, parents=True) self.store = Store(db_path, skip_validation=skip_validation) self.document_repository = DocumentRepository(self.store) self.chunk_repository = ChunkRepository(self.store) diff --git a/src/haiku/rag/config.py b/src/haiku/rag/config.py index 13227e69..82a7fb5d 100644 --- a/src/haiku/rag/config.py +++ b/src/haiku/rag/config.py @@ -53,6 +53,10 @@ class AppConfig(BaseModel): ANTHROPIC_API_KEY: str = "" COHERE_API_KEY: str = "" + # If true, refuse to auto-create a new LanceDB database or tables + # and error out when the database does not already exist. + DISABLE_DB_AUTOCREATE: bool = False + @field_validator("MONITOR_DIRECTORIES", mode="before") @classmethod def parse_monitor_directories(cls, v): diff --git a/src/haiku/rag/store/engine.py b/src/haiku/rag/store/engine.py index aabb7360..4d736834 100644 --- a/src/haiku/rag/store/engine.py +++ b/src/haiku/rag/store/engine.py @@ -54,6 +54,19 @@ class Store: # Create the ChunkRecord model with the correct vector dimension self.ChunkRecord = create_chunk_model(self.embedder._vector_dim) + # Local filesystem handling for DB directory + if not self._has_cloud_config(): + if Config.DISABLE_DB_AUTOCREATE: + # LanceDB uses a directory path for local databases; enforce presence + if not db_path.exists(): + raise FileNotFoundError( + f"LanceDB path does not exist: {db_path}. Auto-creation is disabled." + ) + else: + # Ensure parent directories exist when autocreation allowed + if not db_path.parent.exists(): + Path.mkdir(db_path.parent, parents=True) + # Connect to LanceDB self.db = self._connect_to_lancedb(db_path)