Fetch Paperless before wiping the index in reindex
CI / backend (push) Successful in 42s
CI / frontend (push) Failing after 7s
CI / backend (pull_request) Successful in 42s
CI / frontend (pull_request) Failing after 7s

`reindex` deleted every chunk before contacting Paperless, so an unreachable
or empty Paperless left the store empty (which happened when Paperless was
crash-looping during its v3 upgrade). It now fetches first, aborts without
deleting if that fails or returns nothing, and indexes the fetched documents
instead of fetching twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 08:30:27 -04:00
parent ec3d4229e3
commit b8d8bb8a57
3 changed files with 49 additions and 7 deletions
+15 -2
View File
@@ -8,6 +8,7 @@ import sys
from blueprints.rag.logic import (
delete_all_documents,
delete_documents_by_metadata,
fetch_documents_from_paperless_ngx,
get_vector_store_stats,
index_documents,
index_obsidian_documents,
@@ -33,11 +34,23 @@ async def index():
async def reindex():
"""Clear and reindex everything: Paperless documents and the Obsidian vault."""
"""Clear and reindex everything: Paperless documents and the Obsidian vault.
Paperless is fetched before anything is deleted, so an unreachable or
empty Paperless leaves the existing index untouched.
"""
print("Fetching documents from Paperless-NGX...")
documents = await fetch_documents_from_paperless_ngx()
if not documents:
raise RuntimeError(
"Paperless returned no documents to index; leaving the index untouched"
)
print(f"Fetched {len(documents)} documents")
print("Clearing existing documents...")
delete_all_documents()
print("Cleared")
await index()
await index_documents(documents)
print("Paperless indexing complete!")
await reindex_obsidian(clear=False)