From 2678c1aaad8d82b67f36f380758fafe3142aec35 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Fri, 19 Dec 2025 11:45:35 +0200 Subject: [PATCH] history command, shows available lancedb versions per table --- haiku_rag_slim/haiku/rag/app.py | 52 +++++++++++++++++++++++++++++++++ haiku_rag_slim/haiku/rag/cli.py | 24 +++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/haiku_rag_slim/haiku/rag/app.py b/haiku_rag_slim/haiku/rag/app.py index 9f3c378a..1c76b4ff 100644 --- a/haiku_rag_slim/haiku/rag/app.py +++ b/haiku_rag_slim/haiku/rag/app.py @@ -221,6 +221,58 @@ class HaikuRAGApp: f" [repr.attrib_name]docling[/repr.attrib_name]: {docling_version}" ) + async def history(self, table: str | None = None, limit: int | None = None): + """Display version history for database tables. + + Args: + table: Specific table to show history for (documents, chunks, settings). + If None, shows history for all tables. + limit: Maximum number of versions to show per table. + """ + from haiku.rag.store.engine import Store + + if not self.db_path.exists(): + self.console.print("[red]Database path does not exist.[/red]") + return + + store = Store(self.db_path, config=self.config, skip_validation=True) + + tables = ["documents", "chunks", "settings"] + if table: + if table not in tables: + self.console.print( + f"[red]Unknown table: {table}. Must be one of: {', '.join(tables)}[/red]" + ) + store.close() + return + tables = [table] + + self.console.print("[bold]Version History[/bold]") + + for table_name in tables: + versions = store.list_table_versions(table_name) + + # Sort by version descending (newest first) + versions = sorted(versions, key=lambda v: v["version"], reverse=True) + + if limit: + versions = versions[:limit] + + self.console.print(f"\n[bold cyan]{table_name}[/bold cyan]") + + if not versions: + self.console.print(" [dim]No versions found[/dim]") + continue + + for v in versions: + version_num = v["version"] + timestamp = v["timestamp"] + self.console.print( + f" [repr.attrib_name]v{version_num}[/repr.attrib_name]: {timestamp}" + ) + + store.close() + async def list_documents(self, filter: str | None = None): async with HaikuRAG( db_path=self.db_path, diff --git a/haiku_rag_slim/haiku/rag/cli.py b/haiku_rag_slim/haiku/rag/cli.py index 8648adc8..65c0479a 100644 --- a/haiku_rag_slim/haiku/rag/cli.py +++ b/haiku_rag_slim/haiku/rag/cli.py @@ -529,6 +529,30 @@ def info( asyncio.run(app.info()) +@cli.command("history", help="Show version history for database tables") +def history( + db: Path | None = typer.Option( + None, + "--db", + help="Path to the LanceDB database file", + ), + table: str | None = typer.Option( + None, + "--table", + "-t", + help="Specific table to show history for (documents, chunks, settings)", + ), + limit: int | None = typer.Option( + None, + "--limit", + "-l", + help="Maximum number of versions to show per table", + ), +): + app = create_app(db) + asyncio.run(app.history(table=table, limit=limit)) + + @cli.command("download-models", help="Download Docling and Ollama models per config") def download_models_cmd(): app = HaikuRAGApp(db_path=Path(), config=get_config())