diff --git a/src/paperless_ai/vector_store.py b/src/paperless_ai/vector_store.py index 5a866488f..06a1cae69 100644 --- a/src/paperless_ai/vector_store.py +++ b/src/paperless_ai/vector_store.py @@ -599,9 +599,12 @@ class PaperlessSqliteVecVectorStore(BasePydanticVectorStore): """ if not self.table_exists(): return - live = self._conn.execute( - "SELECT count(*) FROM " + DEFAULT_TABLE_NAME, - ).fetchone()[0] + # document_chunks is a plain indexed table kept in lockstep with the + # vec0 table (see _index_chunks()/_delete_chunks_by_document_id()), + # so it gives an identical live-row count to `SELECT count(*) FROM + # documents` without vec0's full table scan -- count(*) has no + # equivalent point-lookup fast path, unlike an EQ constraint on `id`. + live = self._conn.execute("SELECT count(*) FROM document_chunks").fetchone()[0] total = int(self._meta_get("total_inserts") or str(live)) if not force and total <= max(live, 1) * COMPACT_BLOAT_RATIO: return