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

Function _update_index

openkb/agent/compiler.py:1484–1554  ·  view source on GitHub ↗

Append document and concept entries to index.md. When ``doc_brief`` or entries in ``concept_briefs`` are provided, entries are written as ``- [[link]] (type) — brief text``. Existing entries are detected within their own section by exact entry prefix and skipped to avoid duplicates.

(
    wiki_dir: Path,
    doc_name: str,
    concept_names: list[str],
    doc_brief: str = "",
    concept_briefs: dict[str, str] | None = None,
    doc_type: str = "short",
    entity_names: list[str] | None = None,
    entity_meta: dict[str, tuple[str, str]] | None = None,
)

Source from the content-addressed store, hash-verified

1482
1483
1484def _update_index(
1485 wiki_dir: Path,
1486 doc_name: str,
1487 concept_names: list[str],
1488 doc_brief: str = "",
1489 concept_briefs: dict[str, str] | None = None,
1490 doc_type: str = "short",
1491 entity_names: list[str] | None = None,
1492 entity_meta: dict[str, tuple[str, str]] | None = None,
1493) -> None:
1494 """Append document and concept entries to index.md.
1495
1496 When ``doc_brief`` or entries in ``concept_briefs`` are provided, entries
1497 are written as ``- [[link]] (type) — brief text``. Existing entries are
1498 detected within their own section by exact entry prefix and skipped to
1499 avoid duplicates.
1500 ``doc_type`` is ``"short"`` or ``"pageindex"`` — shown in the entry so the
1501 query agent knows how to access detailed content.
1502 """
1503 if concept_briefs is None:
1504 concept_briefs = {}
1505
1506 index_path = wiki_dir / "index.md"
1507 if not index_path.exists():
1508 atomic_write_text(index_path, INDEX_SEED)
1509
1510 lines = index_path.read_text(encoding="utf-8").split("\n")
1511
1512 _ensure_h2_section(lines, "## Documents")
1513 if concept_names:
1514 _ensure_h2_section(lines, "## Concepts")
1515
1516 doc_link = f"[[summaries/{doc_name}]]"
1517 if not _section_contains_link(lines, "## Documents", doc_link):
1518 doc_entry = f"- {doc_link} ({doc_type})"
1519 if doc_brief:
1520 doc_entry += f" — {doc_brief}"
1521 _insert_section_entry(lines, "## Documents", doc_entry)
1522
1523 for name in concept_names:
1524 concept_link = f"[[concepts/{name}]]"
1525 concept_entry = f"- {concept_link}"
1526 if name in concept_briefs:
1527 concept_entry += f" — {concept_briefs[name]}"
1528 if _section_contains_link(lines, "## Concepts", concept_link):
1529 if name in concept_briefs:
1530 _replace_section_entry(lines, "## Concepts", concept_link, concept_entry)
1531 else:
1532 _insert_section_entry(lines, "## Concepts", concept_entry)
1533
1534 entity_names = entity_names or []
1535 entity_meta = entity_meta or {}
1536 if entity_names:
1537 # Keep canonical order: Entities sits before Explorations. On an older
1538 # index.md that predates the Entities section, plain ``_ensure_h2_section``
1539 # would append it after Explorations.
1540 _ensure_h2_section_before(lines, "## Entities", "## Explorations")
1541 for name in entity_names:

Calls 7

atomic_write_textFunction · 0.90
_ensure_h2_sectionFunction · 0.85
_section_contains_linkFunction · 0.85
_insert_section_entryFunction · 0.85
_replace_section_entryFunction · 0.85
getMethod · 0.45