MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / remove_doc_from_index

Function remove_doc_from_index

openkb/agent/compiler.py:1448–1481  ·  view source on GitHub ↗

Remove the document's entry from ``index.md`` along with any concept and entity entries for pages that were deleted as a side effect. No-op when ``index.md`` doesn't exist. Section headings are kept even when their last entry is removed — adding a new doc later repopulates them.

(
    wiki_dir: Path,
    doc_name: str,
    concept_slugs_deleted: list[str],
    entity_slugs_deleted: list[str] | None = None,
)

Source from the content-addressed store, hash-verified

1446
1447
1448def remove_doc_from_index(
1449 wiki_dir: Path,
1450 doc_name: str,
1451 concept_slugs_deleted: list[str],
1452 entity_slugs_deleted: list[str] | None = None,
1453) -> None:
1454 """Remove the document's entry from ``index.md`` along with any concept
1455 and entity entries for pages that were deleted as a side effect.
1456
1457 No-op when ``index.md`` doesn't exist. Section headings are kept even
1458 when their last entry is removed — adding a new doc later repopulates
1459 them.
1460 """
1461 index_path = wiki_dir / "index.md"
1462 if not index_path.exists():
1463 return
1464
1465 lines = index_path.read_text(encoding="utf-8").split("\n")
1466
1467 doc_link = f"[[summaries/{doc_name}]]"
1468 while _remove_section_entry(lines, "## Documents", doc_link):
1469 pass
1470
1471 for slug in concept_slugs_deleted:
1472 concept_link = f"[[concepts/{slug}]]"
1473 while _remove_section_entry(lines, "## Concepts", concept_link):
1474 pass
1475
1476 for slug in entity_slugs_deleted or []:
1477 entity_link = f"[[entities/{slug}]]"
1478 while _remove_section_entry(lines, "## Entities", entity_link):
1479 pass
1480
1481 atomic_write_text(index_path, "\n".join(lines))
1482
1483
1484def _update_index(

Calls 2

atomic_write_textFunction · 0.90
_remove_section_entryFunction · 0.85