Remove defensive checks in info()

This commit is contained in:
Yiorgis Gozadinos 2026-01-15 10:30:45 +02:00
parent 345807e699
commit fae274a04d
No known key found for this signature in database
2 changed files with 19 additions and 47 deletions

View file

@ -79,7 +79,6 @@ class HaikuRAGApp:
# Connect without going through Store to avoid upgrades/validation writes # Connect without going through Store to avoid upgrades/validation writes
db = lancedb.connect(self.db_path) db = lancedb.connect(self.db_path)
table_names = set(db.table_names())
versions = get_package_versions() versions = get_package_versions()
@ -90,24 +89,17 @@ class HaikuRAGApp:
table_stats = store.get_stats() table_stats = store.get_stats()
# Read settings after Store init (migrations have run) # Read settings after Store init (migrations have run)
stored_version = "unknown" settings_tbl = db.open_table("settings")
embed_provider: str | None = None arrow = settings_tbl.search().where("id = 'settings'").limit(1).to_arrow()
embed_model: str | None = None rows = arrow.to_pylist()
vector_dim: int | None = None raw = rows[0].get("settings") or "{}"
data = json.loads(raw) if isinstance(raw, str) else (raw or {})
if "settings" in table_names: stored_version = str(data.get("version", "unknown"))
settings_tbl = db.open_table("settings") embeddings = data.get("embeddings", {})
arrow = settings_tbl.search().where("id = 'settings'").limit(1).to_arrow() embed_model_obj = embeddings.get("model", {})
rows = arrow.to_pylist() if arrow is not None else [] embed_provider = embed_model_obj.get("provider", "unknown")
if rows: embed_model = embed_model_obj.get("name", "unknown")
raw = rows[0].get("settings") or "{}" vector_dim = embed_model_obj.get("vector_dim")
data = json.loads(raw) if isinstance(raw, str) else (raw or {})
stored_version = str(data.get("version", stored_version))
embeddings = data.get("embeddings", {})
embed_model_obj = embeddings.get("model", {})
embed_provider = embed_model_obj.get("provider")
embed_model = embed_model_obj.get("name")
vector_dim = embed_model_obj.get("vector_dim")
store.close() store.close()
@ -122,32 +114,17 @@ class HaikuRAGApp:
num_unindexed_rows = table_stats["chunks"].get("num_unindexed_rows", 0) num_unindexed_rows = table_stats["chunks"].get("num_unindexed_rows", 0)
# Table versions per table (direct API) # Table versions per table (direct API)
doc_versions = ( doc_versions = len(list(db.open_table("documents").list_versions()))
len(list(db.open_table("documents").list_versions())) chunk_versions = len(list(db.open_table("chunks").list_versions()))
if "documents" in table_names
else 0
)
chunk_versions = (
len(list(db.open_table("chunks").list_versions()))
if "chunks" in table_names
else 0
)
self.console.print( self.console.print(
f" [repr.attrib_name]haiku.rag version (db)[/repr.attrib_name]: {stored_version}" f" [repr.attrib_name]haiku.rag version (db)[/repr.attrib_name]: {stored_version}"
) )
if embed_provider or embed_model or vector_dim: dim_part = f"{vector_dim}" if vector_dim is not None else "unknown"
provider_part = embed_provider or "unknown" self.console.print(
model_part = embed_model or "unknown" " [repr.attrib_name]embeddings[/repr.attrib_name]: "
dim_part = f"{vector_dim}" if vector_dim is not None else "unknown" f"{embed_provider}/{embed_model} (dim: {dim_part})"
self.console.print( )
" [repr.attrib_name]embeddings[/repr.attrib_name]: "
f"{provider_part}/{model_part} (dim: {dim_part})"
)
else:
self.console.print(
" [repr.attrib_name]embeddings[/repr.attrib_name]: unknown"
)
self.console.print( self.console.print(
f" [repr.attrib_name]documents[/repr.attrib_name]: {num_docs} " f" [repr.attrib_name]documents[/repr.attrib_name]: {num_docs} "
f"({format_bytes(doc_bytes)})" f"({format_bytes(doc_bytes)})"

View file

@ -85,12 +85,7 @@ class SettingsRepository:
if existing: if existing:
# Preserve existing version if present to avoid interfering with upgrade flow # Preserve existing version if present to avoid interfering with upgrade flow
try: existing_settings = json.loads(existing[0].settings)
existing_settings = (
json.loads(existing[0].settings) if existing[0].settings else {}
)
except Exception:
existing_settings = {}
if "version" in existing_settings: if "version" in existing_settings:
current_config["version"] = existing_settings["version"] current_config["version"] = existing_settings["version"]