Fix checking settings

This commit is contained in:
Yiorgis Gozadinos 2025-09-02 13:01:36 +03:00
parent 9e5f11060d
commit ecf8894755
No known key found for this signature in database

View file

@ -97,32 +97,47 @@ class SettingsRepository:
def validate_config_compatibility(self) -> None: def validate_config_compatibility(self) -> None:
"""Validate that the current configuration is compatible with stored settings.""" """Validate that the current configuration is compatible with stored settings."""
try:
stored_settings = self.get_current_settings() stored_settings = self.get_current_settings()
# If no stored settings, this is a new database - save current config and return
if not stored_settings:
self.save_current_settings()
return
current_config = Config.model_dump(mode="json") current_config = Config.model_dump(mode="json")
# Check if embedding provider or model has changed # Check if embedding provider or model has changed
stored_provider = stored_settings.get("embedding_provider") stored_provider = stored_settings.get("EMBEDDINGS_PROVIDER")
current_provider = current_config.get("embedding_provider") current_provider = current_config.get("EMBEDDINGS_PROVIDER")
stored_model = stored_settings.get("embedding_model") stored_model = stored_settings.get("EMBEDDINGS_MODEL")
current_model = current_config.get("embedding_model") current_model = current_config.get("EMBEDDINGS_MODEL")
if (stored_provider and stored_provider != current_provider) or ( stored_vector_dim = stored_settings.get("EMBEDDINGS_VECTOR_DIM")
stored_model and stored_model != current_model current_vector_dim = current_config.get("EMBEDDINGS_VECTOR_DIM")
):
# Provider or model changed - need to recreate embeddings
from rich.console import Console
console = Console() # Check for incompatible changes
console.print( incompatible_changes = []
"[yellow]Warning: Embedding provider/model changed. "
"You may need to recreate embeddings for optimal performance.[/yellow]" if stored_provider and stored_provider != current_provider:
incompatible_changes.append(
f"Embedding provider changed from '{stored_provider}' to '{current_provider}'"
) )
# Optionally recreate embeddings table if stored_model and stored_model != current_model:
# self.store.recreate_embeddings_table() incompatible_changes.append(
f"Embedding model changed from '{stored_model}' to '{current_model}'"
)
except Exception: if stored_vector_dim and stored_vector_dim != current_vector_dim:
# If we can't validate, just continue incompatible_changes.append(
pass f"Vector dimension changed from {stored_vector_dim} to {current_vector_dim}"
)
if incompatible_changes:
error_msg = (
"Database configuration is incompatible with current settings:\n"
+ "\n".join(f" - {change}" for change in incompatible_changes)
)
error_msg += "\n\nPlease rebuild the database using: haiku-rag rebuild"
raise ConfigMismatchError(error_msg)