Config DISABLE_DB_AUTOCREATE option to not auto-create dbs
This commit is contained in:
parent
ab8020e0bc
commit
6b7f574180
4 changed files with 27 additions and 2 deletions
|
|
@ -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.
|
**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
|
### Document Processing
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ class HaikuRAG:
|
||||||
db_path: Path to the database file.
|
db_path: Path to the database file.
|
||||||
skip_validation: Whether to skip configuration validation on database load.
|
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.store = Store(db_path, skip_validation=skip_validation)
|
||||||
self.document_repository = DocumentRepository(self.store)
|
self.document_repository = DocumentRepository(self.store)
|
||||||
self.chunk_repository = ChunkRepository(self.store)
|
self.chunk_repository = ChunkRepository(self.store)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ class AppConfig(BaseModel):
|
||||||
ANTHROPIC_API_KEY: str = ""
|
ANTHROPIC_API_KEY: str = ""
|
||||||
COHERE_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")
|
@field_validator("MONITOR_DIRECTORIES", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_monitor_directories(cls, v):
|
def parse_monitor_directories(cls, v):
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,19 @@ class Store:
|
||||||
# Create the ChunkRecord model with the correct vector dimension
|
# Create the ChunkRecord model with the correct vector dimension
|
||||||
self.ChunkRecord = create_chunk_model(self.embedder._vector_dim)
|
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
|
# Connect to LanceDB
|
||||||
self.db = self._connect_to_lancedb(db_path)
|
self.db = self._connect_to_lancedb(db_path)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue