Config DISABLE_DB_AUTOCREATE option to not auto-create dbs

This commit is contained in:
Yiorgis Gozadinos 2025-09-22 10:09:07 +03:00
parent ab8020e0bc
commit 6b7f574180
No known key found for this signature in database
4 changed files with 27 additions and 2 deletions

View file

@ -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 hasnt 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

View file

@ -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)

View file

@ -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):

View file

@ -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)