Shared Steps 2-4: concepts plan → generate/update → index. Uses ``_CONCEPTS_PLAN_USER`` to get a plan with create/update/related actions, then executes each action type accordingly. Concept bodies are generated in memory, scrubbed of unresolved wikilinks, and only then written to di
(
wiki_dir: Path,
kb_dir: Path,
model: str,
system_msg: dict,
doc_msg: dict,
summary: str,
doc_name: str,
max_concurrency: int,
doc_brief: str = "",
doc_type: str = "short",
rewrite_summary: bool = False,
entity_types: list[str] | None = None,
)
| 1569 | |
| 1570 | |
| 1571 | async def _compile_concepts( |
| 1572 | wiki_dir: Path, |
| 1573 | kb_dir: Path, |
| 1574 | model: str, |
| 1575 | system_msg: dict, |
| 1576 | doc_msg: dict, |
| 1577 | summary: str, |
| 1578 | doc_name: str, |
| 1579 | max_concurrency: int, |
| 1580 | doc_brief: str = "", |
| 1581 | doc_type: str = "short", |
| 1582 | rewrite_summary: bool = False, |
| 1583 | entity_types: list[str] | None = None, |
| 1584 | ) -> None: |
| 1585 | """Shared Steps 2-4: concepts plan → generate/update → index. |
| 1586 | |
| 1587 | Uses ``_CONCEPTS_PLAN_USER`` to get a plan with create/update/related |
| 1588 | actions, then executes each action type accordingly. Concept bodies are |
| 1589 | generated in memory, scrubbed of unresolved wikilinks, and only then |
| 1590 | written to disk. When ``rewrite_summary=True`` (short-doc path), the |
| 1591 | summary is rewritten by the LLM after concepts are finalized so its |
| 1592 | wikilinks reflect the actual concept pages on disk. |
| 1593 | """ |
| 1594 | source_file = f"summaries/{doc_name}.md" |
| 1595 | |
| 1596 | # Effective entity types for this compile (config-driven; defaults to the |
| 1597 | # canonical enum when unset, keeping behavior byte-identical to today). |
| 1598 | if entity_types is None: |
| 1599 | entity_types = list(_ENTITY_TYPE_LIST) |
| 1600 | types_str = ", ".join(entity_types) |
| 1601 | valid_types = frozenset(entity_types) |
| 1602 | |
| 1603 | # --- Step 2: Get concepts plan (A cached) --- |
| 1604 | concept_briefs = _read_concept_briefs(wiki_dir) |
| 1605 | entity_briefs = _read_entity_briefs(wiki_dir) |
| 1606 | |
| 1607 | # Second cache breakpoint: end of the assistant summary message. Covers |
| 1608 | # (system + doc + summary) for the plan call and every concept call. |
| 1609 | summary_msg = {"role": "assistant", "content": _cached_text(summary)} |
| 1610 | |
| 1611 | plan_raw = _llm_call( |
| 1612 | model, |
| 1613 | [ |
| 1614 | system_msg, |
| 1615 | doc_msg, |
| 1616 | summary_msg, |
| 1617 | { |
| 1618 | "role": "user", |
| 1619 | "content": _CONCEPTS_PLAN_USER.format( |
| 1620 | concept_briefs=concept_briefs, |
| 1621 | entity_briefs=entity_briefs, |
| 1622 | ).replace("__ENTITY_TYPES__", types_str), |
| 1623 | }, |
| 1624 | ], |
| 1625 | "concepts-plan", |
| 1626 | response_format=_JSON_RESPONSE_FORMAT, |
| 1627 | ) |
| 1628 |