VectifyAI/PageIndex · error · PageIndexAPIError

Failed to delete document: Document not found.

Error message

Failed to delete document: Document not found.

What it means

Raised by PageIndexLocal.delete_document when the underlying store reports the delete failed, which in local mode means no document with that doc_id exists (already deleted, wrong ID, or store path mismatch). The local store is filesystem/index-backed, so a stale ID from a previous session or a different data directory will not resolve.

Source

Thrown at pageindex/local_api.py:342

    # ── document management ──

    def _require_doc(self, doc_id: str, error_prefix: str) -> dict:
        meta = self._store.get_meta(doc_id)
        if meta is None:
            raise PageIndexAPIError(f"{error_prefix}: Document not found.")
        return meta

    def get_document(self, doc_id: str) -> dict[str, Any]:
        meta = self._store.get_meta(doc_id)
        if meta is None:
            raise PageIndexAPIError("Failed to get document metadata: Document not found")
        return {key: meta.get(key) for key in
                ("id", "name", "description", "status", "createdAt", "pageNum", "folderId")}

    def delete_document(self, doc_id: str) -> dict[str, Any]:
        if not self._store.delete_document(doc_id):
            raise PageIndexAPIError("Failed to delete document: Document not found.")
        return {"message": "Document deleted successfully."}

    def list_documents(
        self,
        limit: int = 50,
        offset: int = 0,
        folder_id: str | None = None,
    ) -> dict[str, Any]:
        if limit < 1 or limit > 100:
            raise ValueError("limit must be between 1 and 100")
        if offset < 0:
            raise ValueError("offset must be non-negative")
        if folder_id is not None:
            raise PageIndexAPIError(
                "Failed to list documents: folders are not supported in local mode."
            )
        metas = sorted(self._store.list_metas(), key=lambda m: m.get("id") or "")
        metas.sort(key=lambda m: m.get("createdAt") or "", reverse=True)

View on GitHub (pinned to afb5e11976)

Solutions

  1. Verify the ID exists first: client.get_document(doc_id) (or list_documents) before deleting
  2. Treat 'not found' as success if the goal is absence: catch and ignore this specific error
  3. Ensure all processes point at the same local store/data directory

Example fix

// before
client.delete_document("doc_123")

// after
try:
    client.delete_document("doc_123")
except PageIndexAPIError:
    pass  # already gone
Defensive patterns

Strategy: try-catch

Validate before calling

try:
    meta = client.get_document(doc_id)
except PageIndexAPIError:
    meta = None
if meta is None:
    skip_delete = True

Type guard

null

Try / catch

try:
    client.delete_document(doc_id)
except PageIndexAPIError as e:
    if "not found" not in str(e).lower():
        raise
    # idempotent delete: treat as success

Prevention

When it happens

Trigger: Calling client.delete_document(doc_id) with an ID returned by a previous process run, an ID from another machine's store, or calling delete twice (second call raises).

Common situations: Retrying a delete after a network-looking failure, syncing IDs between environments, UI showing a stale document list, deleting after the store directory was recreated.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of VectifyAI/PageIndex@afb5e11976 (2026-08-27). Data as JSON: /api/errors/9f0907c0f11d3fea. Report an issue: GitHub.