Skip to content

Commit eecc0bc

Browse files
author
Sebastian Braun
committed
fix(cli): auto-delete also on 'skipped' status to keep raw/ clean
Duplicates (skipped files) should also be auto-deleted when auto_delete_added_files is enabled, so raw/ stays clean. Only 'failed' status files are preserved to allow retries. Updated docstrings and helper function logic accordingly.
1 parent 326ac40 commit eecc0bc

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

openkb/cli.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ def add_single_file(
455455
def _delete_if_auto_cleanup_enabled(
456456
file_path: Path, status: Literal["added", "skipped", "failed"], config: dict
457457
) -> bool:
458-
"""Delete file if addition succeeded and auto_delete_added_files is enabled.
458+
"""Delete file if auto_delete_added_files is enabled and ingestion succeeded/skipped.
459+
460+
Deletes on both "added" (successful ingestion) and "skipped" (duplicate already
461+
in KB) to keep raw/ directory clean. Preserves files on "failed" to allow retries.
459462
460463
Args:
461464
file_path: Path to the file to potentially delete.
@@ -465,7 +468,7 @@ def _delete_if_auto_cleanup_enabled(
465468
Returns:
466469
True if file was deleted, False otherwise.
467470
"""
468-
if status == "added" and config.get("auto_delete_added_files", False):
471+
if status in ("added", "skipped") and config.get("auto_delete_added_files", False):
469472
try:
470473
file_path.unlink(missing_ok=True)
471474
return True
@@ -1110,8 +1113,9 @@ def add(ctx, path, from_pageindex_cloud):
11101113
that is already indexed in PageIndex Cloud, with no local file. Requires
11111114
the PAGEINDEX_API_KEY environment variable.
11121115
1113-
If ``auto_delete_added_files`` is enabled in config.yaml, successfully
1114-
added files are automatically deleted after ingestion.
1116+
If ``auto_delete_added_files`` is enabled in config.yaml, files are
1117+
automatically deleted after ingestion (both on successful addition and
1118+
on skip/duplicate).
11151119
"""
11161120
kb_dir = _find_kb_dir(ctx.obj.get("kb_dir_override"))
11171121
if kb_dir is None:
@@ -1194,8 +1198,8 @@ def add_all(ctx):
11941198
11951199
This command walks the ``raw/`` directory recursively for all supported
11961200
document types and ingests them into the KB. If ``auto_delete_added_files``
1197-
is enabled in config.yaml, successfully added files are automatically deleted
1198-
after ingestion.
1201+
is enabled in config.yaml, files are automatically deleted after ingestion
1202+
(both on successful addition and on skip/duplicate).
11991203
12001204
Returns a summary of the operation (added, skipped, failed, deleted counts).
12011205
"""

0 commit comments

Comments
 (0)