Skip to content

API Reference parrot.knowledge.wiki.triage

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

parrot.knowledge.wiki.triage

View source

Ingest triage cascade + novelty scorer for supervised wiki ingestion (FEAT-402).

Implements Module 3 of the spec (§3) — the heart of supervised ingestion. :class:IngestTriageRouter runs a cheap-first cascade per document:

  • Stage 0 (free): duplicate content / oversized / disallowed-suffix documents are rejected via :class:~parrot.knowledge.wiki.sources. SourceCollectionManager bookkeeping alone — zero LLM calls.
  • Stage 1 (lightweight): :meth:LLMCaller.ask_structured produces a :class:~parrot.knowledge.wiki.review.TriageOutput. Novelty is then re-scored via :class:NoveltyScorer (grounding-backed, never LLM-self-assessed), and the composite is computed in Python from the charter's weights — the LLM never emits a composite.
  • Stage 2 (gray zone only): the heavy tier re-scores with the charter's few-shot examples in the prompt; the refined score re-routes within the band.

Design notes:

  • Async throughout; the only sync work (content hashing) is cheap enough to run inline (a handful of KB of already-loaded text, not disk I/O).
  • Every routed :class:~parrot.knowledge.wiki.review.ManifestDocEntry carries decision_source so the manifest is auditable: which stage decided ("heuristic" or "model").
  • See the task's "Contract corrections" note for two intentional, additive resolutions of gaps between the spec's terse interface list and what TASK-2069/2070 actually shipped: (1) size/suffix caps are router constructor parameters, not charter fields (CharterScope only has include/exclude rules); (2) an optional heavy_adapter parameter supports the two distinct model tiers the cascade needs, since a single LLMCaller is bound to one model at construction time.

Alias Charter

Re-exported from parrot.knowledge.wiki.charter.Charter.

Alias Claim

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

Attribute DEFAULT_MAX_CLAIMS_FOR_NOVELTY

Attribute DEFAULT_MAX_SIZE_BYTES

Alias DimensionScores

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

Alias GroundingEvaluator

Re-exported from parrot.knowledge.graphindex.grounding.GroundingEvaluator.

Class IngestTriageRouter

Runs the cheap-first triage cascade for one document at a time.

Parameter Type Default Description
charter Charter The editorial charter (scope, weights, thresholds).
adapter LLMCaller Lightweight-tier LLM adapter (Stage 1).
sources SourceCollectionManager Source collection manager for Stage-0 duplicate detection.
novelty_scorer NoveltyScorer Grounding-first novelty scorer.
heavy_adapter LLMCaller | None None Heavy-tier LLM adapter (Stage 2). Defaults to adapter when omitted.
max_size_bytes int DEFAULT_MAX_SIZE_BYTES Stage-0 size cap in bytes.
allowed_suffixes frozenset[str] | None None Optional Stage-0 suffix allowlist.

Attributes:

Attribute Type Description
charter The editorial charter (scope, weights, thresholds).
adapter Lightweight-tier LLM adapter (Stage 1).
heavy_adapter Heavy-tier LLM adapter (Stage 2, gray zone only). Defaults to reusing adapter when not given (see the task's Contract corrections note — the fixed constructor signature carries only one adapter positional parameter).
sources Source collection manager, used for Stage-0 duplicate detection.
novelty_scorer Grounding-first novelty scorer.
max_size_bytes Stage-0 size cap.
allowed_suffixes Optional Stage-0 suffix allowlist (lower-cased, including the leading dot, e.g. {".md", ".txt"}). None disables the suffix check.

Method IngestTriageRouter.triage

Triage one document through the full cascade.

triage(path: Path, content: str, *, skip_duplicate_check: bool = False) -> ManifestDocEntry

Parameter Type Default Description
path Path Path (or path-like identifier) of the document.
content str The already-loaded document content.
skip_duplicate_check bool False When True, bypass only the two duplicate checks; size, suffix, sensitivity, novelty and both model stages still run.

Returns: ManifestDocEntry — class:ManifestDocEntry with decision=None (the manifest layer / human review fills in decision later) and proposed_action set to the router's best guess.

Alias LLMCaller

Re-exported from parrot.knowledge.graphindex.protocols.LLMCaller.

Alias ManifestDocEntry

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

Class NoveltyScorer

Grounding-first novelty scorer with a search-proxy fallback.

Primary path: grounds each (capped) claim against the GraphIndex plane via :class:GroundingEvaluator.ground_claim; novelty is 1 - mean(groundedness) — content that already has strong graph support is not novel. Falls back to a top-k similarity proxy via :class:WikiCombinedSearch.search when no graph DB is available.

Parameter Type Default Description
grounding_evaluator GroundingEvaluator | None None Grounding evaluator to use as the primary backend. When None, the search-proxy fallback is used for every call.
search WikiCombinedSearch | None None Combined wiki search, used by the fallback path. Ignored when grounding_evaluator is set.
max_claims int DEFAULT_MAX_CLAIMS_FOR_NOVELTY Maximum number of claims to ground per document (charter-configurable in spirit; default 3 per spec §7).

Attributes:

Attribute Type Description
grounding_evaluator Grounding evaluator over the GraphIndex plane, or None when the graph DB is absent.
search Wiki combined search, used only by the fallback path.
max_claims Maximum number of claims to ground per document.
backend Literal['grounding', 'search-proxy'] "grounding" or "search-proxy" — fixed at construction time based on whether grounding_evaluator was provided, so callers can read it before triaging any document (e.g. to populate ManifestRunHeader.novelty_backend).

Method NoveltyScorer.score

Score novelty for a document.

score(claims: list[Claim], text: str) -> tuple[float, str]

Parameter Type Default Description
claims list[Claim] Claims extracted from the document during triage. Mutated in place: each claim's grounded field is filled in when the grounding backend is used.
text str The full document text, used only by the search-proxy fallback.

Returns: tuple[float, str] — A (novelty, backend) tuple, where backend is "grounding" or "search-proxy".

Alias SourceCollectionManager

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

Alias TriageOutput

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

Alias WikiCombinedSearch

Re-exported from parrot.knowledge.wiki.search.WikiCombinedSearch.

Attribute logger

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