Skip to content

Deletion API

scinr.newton.ingest.deletion.delete_document async

delete_document(
    path: str, version: int | None = None
) -> DeletionResult

Completely delete a Document node, its entire cascade, and orphans.

Unlike delete_document_content() (which only wipes content for in-place re-ingestion and keeps the :Document node), this permanently removes the :Document node(s) matching path (and, if version is given, only that version) along with:

  • Every descendant reached via IS_COMPOSED_OF* (folder-parent Document nodes, sibling documents, etc.).
  • All :StructureNode descendants (HAS_STRUCTURE / HAS_CHILD), their :InfoUnit, :ModelDecision, :ProposedModel, :ProposedField, and :ExtractionResult children.

Before any Neo4j deletion happens, this also deletes the documental storage records (raw binary + converted Markdown pages) for every non-empty raw_file_id found on the target Document(s) and their IS_COMPOSED_OF* descendants, via the configured storage backend (storage/factory.py::get_storage()). This step is fail-fast: if deleting storage for any raw_file_id raises an unexpected exception, it propagates immediately and the Neo4j cascade delete is never run.

After the cascade delete, runs two independent garbage-collection passes (up to :data:GC_MAX_PASSES iterations each) to remove any :Entity/:ModelInstance and :LabeledEntity nodes left orphaned by the deletion.

Opens and closes its own Neo4j driver — does not require the caller to manage one. The Neo4j-specific work (existence check, raw_file_id lookup, cascade delete, GC passes) uses the existing synchronous Neo4j driver under the hood, dispatched via asyncio.to_thread(); the storage deletion calls are awaited directly since storage repositories (Motor-backed) are natively async.

Parameters

path: The path property of the Document to delete. Required. version: Specific integer version to delete. When None (default), every version of path is deleted (including each one's full cascade).

Returns

DeletionResult Structured counts of everything deleted. If no Document matches path/version, found is False and all counters are 0 (no storage, delete, or GC queries are executed in that case).