Expose safe dry-run and apply command for caption-index repair

This commit is contained in:
Sleeps
2026-10-08 10:54:06 +01:00
parent e9047133d4
commit f7155b5b3e
+51 -1
View File
@@ -44,7 +44,12 @@ from .maintenance import (
from .meili import Meili
from .routing import ExplicitContentRouter, apply_context_routing
from .search_service import SearchService
from .sync import CaptionMeiliSync, rebuild_meili
from .sync import (
CaptionMeiliSync,
count_caption_repair_documents,
rebuild_meili,
repair_caption_documents,
)
def format_ts(ms: int) -> str:
@@ -171,6 +176,37 @@ def cmd_sync_meili(_: argparse.Namespace) -> None:
def cmd_repair_caption_index(args: argparse.Namespace) -> None:
"""Restore only the Meilisearch documents touched by caption sync."""
candidate_count = count_caption_repair_documents()
print(f"Caption-affected canonical frame documents: {candidate_count:,}")
if not candidate_count:
print("Nothing to repair.")
return
if not args.apply:
print(
"Dry run: no changes made. Stop captioning/indexing first, then "
"rerun with --apply to restore these documents from SQLite."
)
return
def progress(update: dict) -> None:
count = int(update.get("documents_processed") or 0)
print(f"Restored and indexed {count:,}/{candidate_count:,} documents")
repaired = repair_caption_documents(
batch_size=args.batch_size,
progress=progress,
)
print(
f"Repair complete: {repaired:,} full documents restored from SQLite. "
"No visual embeddings or captions were regenerated."
)
def _route_policy() -> str:
if settings.caption_force_specialist:
return (
@@ -996,6 +1032,20 @@ def make_parser() -> argparse.ArgumentParser:
sync = sub.add_parser("sync-meili", help="Rebuild/feed Meilisearch from canonical SQLite vectors")
sync.set_defaults(func=cmd_sync_meili)
repair = sub.add_parser(
"repair-caption-index",
help="Restore caption-affected Meilisearch documents without a full rebuild",
)
repair.add_argument(
"--apply", action="store_true",
help="Actually restore documents; default is a read-only count",
)
repair.add_argument(
"--batch-size", type=int, default=250,
help="Documents per Meilisearch repair task (default: 250)",
)
repair.set_defaults(func=cmd_repair_caption_index)
jf_test = sub.add_parser("jellyfin-test", help="Verify Jellyfin API connectivity")
jf_test.set_defaults(func=cmd_jellyfin_test)