Skip to content

API Reference parrot.knowledge.wiki.ingest

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.wiki.ingest

View source

Wiki ingest orchestrator for the LLM Wiki feature (FEAT-260).

Implements the "Ingest" operation from Karpathy's 3-layer architecture. Orchestrates the full pipeline for a single source document:

  1. Check the source registry — skip if already ingested and not stale.
  2. Load source content from the file path.
  3. Process via PageIndexToolkit.insert_content() (which internally delegates to TwoStepIngester).
  4. Upsert the generated pages into the :class:WikiStore retrieval plane (bodies, categories, token counts) and record summarizes edges page → source. replace_source_slice guarantees re-ingest never accumulates duplicates.
  5. Optionally (sync_graph=True) mirror a wiki_page node into GraphIndex.
  6. Update the source registry (hash + mtime + pages generated).
  7. Append to the operation log via WikiBookkeeper.log_operation().

All operations are async. On partial failure the error is logged but no corrupt state is left: the registry is only updated after all steps succeed.

FEAT-402 (TASK-2074): ingest() accepts an optional supervised-triage context (triage: Optional[ManifestDocEntry]). With triage=None (the default), behavior is byte-identical to pre-FEAT-402 — this is the path wikitoolkit build/upsert use today. When a triage decision is given:

  • Its briefing is forwarded as the PageIndex hint (the slot this method used to drop at the insert_content call site) so triage work is reused, not repeated.
  • "discard" short-circuits the whole pipeline — no PageIndex call, no WikiStore sync, no GraphIndex mirror; only the source manifest (status="rejected") and bookkeeper DISCARD line are written.
  • "archive" creates pages exactly like "admit", except every page's category is forced to WikiPageCategory.ARCHIVE.
  • Decision fields (destination, decision_source, charter version, composite score) are persisted via SourceCollectionManager.record_decision (TASK-2073) instead of mark_ingested, and the bookkeeper line is tagged ADMIT/ ARCHIVE instead of INGEST.

Alias AcquiredDocument

Re-exported from parrot.knowledge.wiki.documents.AcquiredDocument.

Alias BaseWikiStore

Re-exported from parrot.knowledge.wiki.store.BaseWikiStore.

Alias DocumentAcquirer

Re-exported from parrot.knowledge.wiki.documents.DocumentAcquirer.

Alias DocumentAcquisitionError

Re-exported from parrot.knowledge.wiki.documents.DocumentAcquisitionError.

Alias DocumentRef

Re-exported from parrot.knowledge.wiki.documents.DocumentRef.

Class IngestReport

Result of a single wiki ingest run.

Fields:

Field Type Default Description
source_id str Stable identifier for the ingested source.
source_uri str Absolute path / URI of the source document.
pages_created int 0 Number of new wiki pages created.
pages_updated int 0 Number of existing pages updated.
graph_nodes_created int 0 Number of GraphIndex nodes created.
duration_ms float 0.0 Wall-clock time in milliseconds.
status str 'ok' "ok" or "error".
error Optional[str] None Optional error message when status == "error".

Alias ManifestDocEntry

Re-exported from parrot.knowledge.wiki.review.ManifestDocEntry.

Alias SourceCollectionManager

Re-exported from parrot.knowledge.wiki.sources.SourceCollectionManager.

Alias TriageProvenance

Re-exported from parrot.knowledge.wiki.documents.TriageProvenance.

Alias WikiBookkeeper

Re-exported from parrot.knowledge.wiki.bookkeeper.WikiBookkeeper.

Alias WikiConfig

Re-exported from parrot.knowledge.wiki.models.WikiConfig.

Class WikiIngestOrchestrator

Orchestrates the full source-to-wiki-page ingest pipeline.

Dependencies are injected at construction time so every component can be mocked in tests without a real LLM or database.

Example::

orch = WikiIngestOrchestrator(pi, gi, source_mgr, bookkeeper)
report = await orch.ingest("/docs/article.md", config)
print(report.pages_created)
Parameter Type Default Description
pageindex_toolkit Any A PageIndexToolkit instance.
graphindex_toolkit Any A GraphIndexToolkit instance.
source_manager SourceCollectionManager :class:SourceCollectionManager for the wiki.
bookkeeper WikiBookkeeper :class:WikiBookkeeper for log/index management.
store Optional[BaseWikiStore] None :class:BaseWikiStore retrieval plane. When None, store sync is skipped (legacy behaviour).
sync_graph bool False When True, additionally mirror a wiki_page node into GraphIndex (off by default — the WikiStore is the retrieval plane).

Attributes:

Attribute Type Description
logger logging.Logger Standard Python logger.

Method WikiIngestOrchestrator.ingest

Run the full ingest pipeline for a single source file.

Pipeline steps (triage=None, the default — legacy path, byte-identical to pre-FEAT-402 behavior):

  1. Register / check the source in the manifest.
  2. Skip (return early) if already ingested and not stale.
  3. Load source content from disk.
  4. Insert into PageIndex tree via insert_content (TwoStepIngester).
  5. Create a WIKI_PAGE node in GraphIndex.
  6. Link graph node → source via REFERENCES edge.
  7. Update manifest with pages generated + new hash/mtime.
  8. Append to log.md.

When triage is given (FEAT-402, TASK-2074), the effective destination is triage.decision if set, else triage.proposed_action:

  • "discard" short-circuits everything above — no PageIndex call, no WikiStore sync, no GraphIndex mirror. Only the source manifest (status="rejected") and a bookkeeper DISCARD line are written (spec §2: rejected docs are recorded but never ingested).
  • "admit"/"archive" run the same pipeline as the legacy path, except: (a) the staleness skip (step 2) is bypassed — triage-driven re-application (e.g. re-running --review) must always re-persist the (possibly human-edited) decision fields even when file content is unchanged; (b) triage. briefing is forwarded as the PageIndex hint; (c) "archive" forces every created page's category to WikiPageCategory.ARCHIVE; (d) decision fields are persisted via SourceCollectionManager.record_decision (TASK-2073) instead of mark_ingested, and the bookkeeper line is tagged ADMIT/ARCHIVE instead of INGEST. replace_source_slice (step 4) still guarantees re-applying the same source replaces its pages rather than duplicating them.

ingest(source_path: str, wiki_config: WikiConfig, *, triage: Optional[ManifestDocEntry] = None, charter_version: Optional[str] = None, acquired: AcquiredDocument | None = None) -> IngestReport

Parameter Type Default Description
source_path str Absolute or relative path to the source file.
wiki_config WikiConfig Configuration for the target wiki instance.
triage Optional[ManifestDocEntry] None Optional supervised-ingestion triage decision (FEAT-402). None preserves the exact legacy behavior used by wikitoolkit build/upsert.
charter_version Optional[str] None Editorial charter version the triage decision was made against, for audit persistence (ManifestDocEntry itself does not carry this — it is only recorded once per manifest run header — so the caller that has the run header passes it here). Ignored when triage is None.
acquired AcquiredDocument | None None FEAT-451 — an already-acquired :class:~parrot.knowledge.wiki.documents.AcquiredDocument (typically the triage lane's own acquisition result). When given, ingest() reuses it instead of re-acquiring the source through :class:DocumentAcquirer — so the triaged text and the ingested text always agree. When None (the default), the source is acquired internally. On the supervised path (triage given), the acquired document's metadata is persisted onto the source manifest and rendered as YAML frontmatter on every generated page; on the legacy path (triage=None, the wikitoolkit build/upsert callers), no frontmatter is ever emitted, keeping that output byte-identical to pre-FEAT-451 behavior.

Returns: IngestReport — class:IngestReport describing what was created/updated.

Raises:

  • DocumentAcquisitionError — When acquired is not given and the source cannot be decoded/extracted (FEAT-451). This propagates out of ingest() rather than degrading to an IngestReport(status="error") — callers must explicitly decide to skip an undecodable document, never triage or ingest mojibake.

Method WikiIngestOrchestrator.extract_entities

Phase 2 (FEAT-392): LLM entity/concept extraction from pages.

Iterates over the content-bearing nodes of an already-ingested PageIndex tree, asks the PageIndex LLM adapter for the entities and concepts each page mentions, creates one sub-node per extracted item, and mirrors each as a CONCEPT node in GraphIndex (when a graph toolkit is configured).

extract_entities(tree_name: str, wiki_config: WikiConfig, granularity: Any = 'standard', custom_instructions: Optional[str] = None) -> IngestReport

Parameter Type Default Description
tree_name str PageIndex tree to extract from (must exist).
wiki_config WikiConfig Wiki configuration (used for logging context).
granularity Any 'standard' ExtractionGranularity or its string value — minimal (up to 3 key concepts per page), standard (up to 8 entities + concepts), fine (exhaustive), or custom (drive with custom_instructions).
custom_instructions Optional[str] None Extraction directive used when granularity="custom".

Returns: IngestReport — class:IngestReport — pages_created counts entity sub-nodes, graph_nodes_created counts GraphIndex mirrors.

Alias WikiPageCategory

Re-exported from parrot.knowledge.wiki.models.WikiPageCategory.

Alias WikiPageRecord

Re-exported from parrot.knowledge.wiki.store.WikiPageRecord.

Alias estimate_tokens

Re-exported from parrot.knowledge.wiki.store.estimate_tokens.

Alias format_decision_log_details

Re-exported from parrot.knowledge.wiki.sources.format_decision_log_details.

Alias render_frontmatter

Re-exported from parrot.knowledge.wiki.documents.render_frontmatter.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally