Fetch Paperless before wiping the index in reindex
`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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user