Skip to content

API Reference parrot.knowledge.wiki.federation

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

parrot.knowledge.wiki.federation

View source

Multi-wiki federation for the LLM Wiki (FEAT-450).

A repository's wiki is one plane. Real work spans several: the sibling libraries a project depends on, an Obsidian vault of notes, a corpus of legislation held in ArangoDB. This module composes them.

Namespaces are declared in project.py (.parrot/wiki.json and the per-user PARROT_HOME/wikis.json); here they are resolved into opened stores (:func:resolve_namespaces) and composed behind one :class:BaseWikiStore (:class:FederatedWikiStore) that the CLI, the AbstractTool wrappers and the MCP server can hold in place of a plain store.

Three rules shape the design:

  • Foreign planes are read-only. A read of another project's wiki never migrates, mutates, or even creates a sidecar next to it — SQLite namespaces are opened with read_only=True.
  • Local ids stay unprefixed. Only foreign pages are qualified <ns>::<id>; the underlying stores never see the prefix. One narrow exception (FEAT-532 §8): a locally-owned edge's destination may be a foreign-qualified id, stored verbatim — a local page is allowed to reference a foreign one (e.g. Luau code referencing the Roblox API plane). The edge's source must still be local, and every other write path (pages, deletes, embeddings) is unaffected.
  • A broken namespace is a note, not a failure. An unbuilt plane or an unreachable server is recorded as a :class:NamespaceSkip and the remaining namespaces still answer.

Alias AttrsUnsupportedError

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

Alias BaseWikiStore

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

Attribute DEFAULT_ARANGO_TIMEOUT

Class FederatedWikiStore

One :class:BaseWikiStore over the local plane plus N namespaces.

Reads fan out concurrently, are normalised per namespace, weighted, qualified (foreign only) and merged. Writes go to the local plane — writing into a namespace is an explicit, single-target operation (--ns <name>) that opens that store directly and never travels through the federation.

Parameter Type Default Description
local BaseWikiStore The local (writable) plane.
local_name str 'local' Name shown for the local plane.
handles list[NamespaceHandle] | None None Opened foreign namespaces.
skipped list[NamespaceSkip] | None None Resolve-time skips to surface in stats.
qualify_local bool False Qualify the local plane's ids with local_name too. Used by :meth:scoped when a single foreign namespace is selected, so its rows keep the ns:: prefix the caller expects.
origin_local BaseWikiStore | None None The true project local plane, when it is different from local (FEAT-532 TASK-2904). Set by :meth:scoped when narrowing to a single foreign namespace replaces self._local with that namespace's own store — read-only incoming-reference lookups (:meth:neighbors on a qualified foreign seed) still need the real local plane's edges to find local callers, without changing what a write on this scoped instance targets. None means local already is the true local plane (the normal, non-scoped case).

Attributes:

Attribute Type Description
local_name Display name of the local plane.
namespaces dict[str, NamespaceHandle] Opened namespaces by name.
skipped list[NamespaceSkip] Namespaces that could not be opened at resolve time.
last_skipped list[NamespaceSkip] Namespaces that failed during THIS task's most recent read. Task-local (see :data:_CALL_SKIPS), so two concurrent reads on a shared store each see only their own notes.
local BaseWikiStore The local (writable) plane.
supports_attrs bool Whether any composed plane persists attrs. This is only a coarse hint: :meth:list_by_attrs still inspects every handle individually, so one unsupported backend cannot hide behind a supporting one.

Method FederatedWikiStore.scoped

Narrow the federation to one routing selector.

scoped(selector: str | None) -> BaseWikiStore

Parameter Type Default Description
selector str | None None or "all" for the whole federation, "local" for the local plane only, or a namespace name. A comma-separated list selects that subset.

Returns: BaseWikiStore — A store honouring the selector — self for a broadcast.

Raises:

  • KeyError — When a named namespace is not resolved.

Method FederatedWikiStore.search_fts

Lexical search across the local plane and every namespace.

search_fts(query: str, category: str | None = None, limit: int = 10) -> list[dict[str, Any]]

Parameter Type Default Description
query str
category str | None None
limit int 10

Returns: list[dict[str, Any]]

Method FederatedWikiStore.search_vector

Vector search across the local plane and every namespace.

search_vector(embedding: list[float], limit: int = 10) -> list[dict[str, Any]]

Parameter Type Default Description
embedding list[float]
limit int 10

Returns: list[dict[str, Any]]

Method FederatedWikiStore.list_pages

List page stubs across the local plane and every namespace.

list_pages(category: str | None = None, limit: int = 100, origin: list[str] | None = None) -> list[dict[str, Any]]

Parameter Type Default Description
category str | None None
limit int 100
origin list[str] | None None

Returns: list[dict[str, Any]]

Method FederatedWikiStore.get_page

Fetch one page, routing a qualified id to its namespace.

get_page(concept_id: str, include_body: bool = True) -> dict[str, Any] | None

Parameter Type Default Description
concept_id str
include_body bool True

Returns: dict[str, Any] | None

Method FederatedWikiStore.get_attrs

Return the attrs of one page, routing a qualified id to its plane.

get_attrs(concept_id: str) -> dict[str, str]

Parameter Type Default Description
concept_id str Page id, qualified (ns::id) or local.

Returns: dict[str, str] — The attrs mapping; empty for an unknown namespace, an unsupported plane or a plane that failed.

Method FederatedWikiStore.list_by_attrs

List attr-matching page stubs across every plane that supports attrs.

Planes without attrs support, or that fail, are skipped and recorded in :attr:last_skipped. Foreign rows are qualified (ns::id); local rows follow the existing local convention.

list_by_attrs(filters: Mapping[str, str | Sequence[str]], *, date_key: str | None = None, since: str | None = None, until: str | None = None, limit: int = 200) -> list[dict[str, Any]]

Parameter Type Default Description
filters Mapping[str, str | Sequence[str]] {key: value | [values]} (ANDed across keys).
date_key str | None None Attr key the date bounds apply to.
since str | None None Inclusive lower ISO-date bound.
until str | None None Inclusive upper ISO-date bound.
limit int 200 Maximum merged rows (newest updated_at first).

Returns: list[dict[str, Any]] — The merged stubs.

Raises:

  • ValueError — A date bound was given without date_key.

Method FederatedWikiStore.upsert_attrs

Write attrs to an existing page of the true local plane only.

upsert_attrs(concept_id: str, attrs: Mapping[str, str], *, replace: bool = True) -> int

Parameter Type Default Description
concept_id str Local page id.
attrs Mapping[str, str] Attribute mapping.
replace bool True Replace (True) or merge into existing attrs.

Returns: int — Rows written.

Raises:

  • ValueError — concept_id names a foreign namespace.
  • AttrsUnsupportedError — This store is a namespace-scoped facade (never a valid writer) or the local plane lacks attrs.

Method FederatedWikiStore.neighbors

Return edge neighbours, qualified with the seed's namespace.

Three layers of processing (FEAT-532 §8, FEAT-566 M13):

  1. Outgoing hydration: any neighbor whose own id is already a foreign-qualified reference (a locally-owned edge's destination stored verbatim — TASK-2903) is hydrated with its real title/summary/category from that namespace's own read-only store, via :meth:_hydrate_foreign_neighbors. The qualified id itself is never re-derived — :func:qualify_id is idempotent against re-homing an already-qualified id, so no double prefix can occur.
  2. Overlay outgoing-to-code: when the seed is in an overlay namespace and a neighbor's kind is NOT in that overlay's prefixes, return the neighbor unqualified and hydrated from the local plane (FEAT-566 M13).
  3. Incoming references + overlay edges: when the seed itself is a qualified foreign id or overlay id, local pages that reference it are folded in (:meth:_local_incoming_references) AND each overlay namespace's incoming edges are folded in (:meth:_overlay_incoming_edges).

neighbors(concept_id: str, rel: str | None = None, direction: str = 'both') -> list[dict[str, Any]]

Parameter Type Default Description
concept_id str
rel str | None None
direction str 'both'

Returns: list[dict[str, Any]]

Method FederatedWikiStore.stats

Local counters plus a per-namespace block and the skip notes.

The local top-level keys (pages, edges, …) are preserved untouched so every existing status / WikiStatusTool consumer keeps working.

stats() -> dict[str, Any]

Returns: dict[str, Any] — The local stats dict extended with local, namespaces and skipped.

Method FederatedWikiStore.upsert_pages

Write pages into the local plane.

upsert_pages(pages: list[WikiPageRecord]) -> int

Parameter Type Default Description
pages list[WikiPageRecord]

Returns: int

Method FederatedWikiStore.add_edges

Write edges into the local plane.

The source of every edge must be local; the destination may additionally be a syntactically qualified foreign reference (FEAT-532 §8) — see :meth:_strip_edge. The whole batch is validated (the list comprehension below) before self._local.add_edges is ever called, so one forbidden edge in a batch leaves nothing written, not a partial insert.

add_edges(edges: list[tuple]) -> int

Parameter Type Default Description
edges list[tuple]

Returns: int

Method FederatedWikiStore.replace_source_slice

Replace one source's slice of the local plane.

Same edge-destination exception as :meth:add_edges — the source-owned slice's outgoing references/extends edges may target a foreign-qualified id. Validated in full (both pages and edges) before the local plane's own atomic replace runs.

replace_source_slice(source_id: str, pages: list[WikiPageRecord], edges: list[tuple[str, str, str]] | None = None) -> dict[str, Any]

Parameter Type Default Description
source_id str
pages list[WikiPageRecord]
edges list[tuple[str, str, str]] | None None

Returns: dict[str, Any]

Method FederatedWikiStore.delete_page

Delete a page from the local plane.

delete_page(concept_id: str) -> bool

Parameter Type Default Description
concept_id str

Returns: bool

Method FederatedWikiStore.upsert_embedding

Store an embedding on the local plane.

upsert_embedding(concept_id: str, vector: list[float], model: str = '') -> None

Parameter Type Default Description
concept_id str
vector list[float]
model str ''

Method FederatedWikiStore.upsert_symbols

Write symbol rows into the local plane (no cross-namespace writes).

upsert_symbols(symbols: list[Any], source_id: str | None = None) -> int

Parameter Type Default Description
symbols list[Any]
source_id str | None None

Returns: int

Method FederatedWikiStore.symbols_for

Read symbols from the local plane only — foreign namespaces' files are not on this disk, so there is nothing to fan out to.

symbols_for(rel_path: str) -> list[Any]

Parameter Type Default Description
rel_path str

Returns: list[Any]

Method FederatedWikiStore.find_symbols

Local plane + every namespace; foreign rows carry namespace (FEAT-609 M5).

find_symbols(name: str | None = None, qualname_prefix: str | None = None, kind: str | None = None, language: str | None = None, path_prefix: str | None = None, limit: int = 50) -> list[Any]

Parameter Type Default Description
name str | None None
qualname_prefix str | None None
kind str | None None
language str | None None
path_prefix str | None None
limit int 50

Returns: list[Any]

Method FederatedWikiStore.search_symbols_fts

BM25 per plane, merged local-first then by namespace weight (FEAT-609 M5).

search_symbols_fts(query: str, limit: int = 20) -> list[Any]

Parameter Type Default Description
query str
limit int 20

Returns: list[Any]

Method FederatedWikiStore.get_meta

Local plane only — a namespace's metadata is not ours to read.

get_meta(key: str) -> str | None

Parameter Type Default Description
key str

Returns: str | None

Method FederatedWikiStore.set_meta

Local plane only — never writes into a foreign namespace.

set_meta(key: str, value: str) -> None

Parameter Type Default Description
key str
value str

Method FederatedWikiStore.page_hashes

Look up content hashes on the local plane only.

page_hashes(concept_ids: list[str]) -> dict[str, str | None]

Parameter Type Default Description
concept_ids list[str]

Returns: dict[str, str | None]

Method FederatedWikiStore.rebuild_from_tree

Rebuild the local plane from a PageIndex tree.

rebuild_from_tree(tree: dict[str, Any], content_loader: Any = None, source_id: str | None = None) -> dict[str, Any]

Parameter Type Default Description
tree dict[str, Any]
content_loader Any None
source_id str | None None

Returns: dict[str, Any]

Method FederatedWikiStore.dump_pages

Dump the local plane's pages (export is a local operation).

dump_pages() -> list[dict[str, Any]]

Returns: list[dict[str, Any]]

Method FederatedWikiStore.dump_edges

Dump the local plane's edges.

dump_edges() -> list[dict[str, Any]]

Returns: list[dict[str, Any]]

Method FederatedWikiStore.orphan_sources

Lint the local plane only.

orphan_sources() -> list[str]

Returns: list[str]

Method FederatedWikiStore.broken_edges

Classify the local plane's broken-edge candidates at the federated boundary (FEAT-532 TASK-2905).

self._local.broken_edges() (standalone BaseWikiStore behavior, unchanged) reports every edge whose dst is neither a local page nor a local source — that necessarily includes every foreign-qualified destination TASK-2903 now allows storing verbatim, since a foreign id is never a local page. This method resolves each such candidate against the actual federation state instead of leaving it a false positive OR silently dropping it:

  • Resolved (the foreign page exists in an available namespace) — healthy, excluded from the report entirely.
  • Missing in an available namespace (e.g. a typo'd class name) — still reported, status="broken". A namespace being available is exactly what makes this a real finding, not a guess.
  • Namespace unavailable/unbuilt — reported separately as status="unverifiable", never silently treated as healthy and never conflated with a genuine local broken edge.
  • A malformed or purely local dst (no valid :: prefix, or naming this store's own local plane) is never blanket-ignored just because it happens to contain :: — it is reported as an ordinary local status="broken" edge, same as before this task.

No API/CDN/GitHub network probe of any kind — resolution is a read-only get_page against an already-opened namespace store, or a plain dict lookup when the namespace was never resolved at all.

broken_edges() -> list[dict[str, Any]]

Returns: list[dict[str, Any]] — The local plane's broken-edge candidates, each augmented with a status field ("broken" or "unverifiable") and, for namespace-related findings, a reason. Resolved foreign edges are omitted.

Method FederatedWikiStore.missing_bodies

Lint the local plane only.

missing_bodies() -> list[str]

Returns: list[str]

Class NamespaceHandle

An opened namespace, ready to be read.

Parameter Type Default Description
name str
store BaseWikiStore
config WikiNamespaceConfig
origin Literal['repo', 'global'] 'repo'
storage_dir Path | None None
read_only bool True

Fields:

Field Type Default Description
name str Namespace name (the <ns> of <ns>::<id>).
store BaseWikiStore The opened backing store.
config WikiNamespaceConfig Declaration this handle was resolved from.
origin Literal['repo', 'global'] 'repo' Which registry declared it (repo or global).
storage_dir Path | None None On-disk plane directory, when the backend has one.
read_only bool True Whether the store was opened read-only.

Attributes:

Attribute Type Description
kind str Entry kind of the declaration (path/store/…).
backend str Backend serving this namespace.
weight float Score multiplier applied when merging this namespace.

Class NamespaceSkip

A namespace that could not be served, and why.

Fields:

Field Type Default Description
name str Namespace name.
reason Literal['unbuilt', 'unreachable', 'invalid'] unbuilt (no plane yet), unreachable (open or query failed), or invalid (the entry itself is broken).
detail str '' Human-readable cause.
hint str '' Optional command that would fix it.

Attribute SELECTOR_ALL

Attribute SELECTOR_LOCAL

Alias SQLitePragmaPolicy

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

Alias SQLiteWikiStore

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

Class StalePlaneError

A foreign plane predates the current schema and needs a rebuild.

Read-only mode deliberately never migrates a foreign plane, so a plane missing post-schema columns would otherwise fail every query with a raw no such column error. Detecting it at open time turns that into an actionable skip.

Alias WikiNamespaceConfig

Re-exported from parrot.knowledge.wiki.project.WikiNamespaceConfig.

Alias WikiPageRecord

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

Alias WikiProjectConfig

Re-exported from parrot.knowledge.wiki.project.WikiProjectConfig.

Alias create_wiki_store

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

Alias load_effective_config

Re-exported from parrot.knowledge.wiki.project.load_effective_config.

Alias load_global_registry

Re-exported from parrot.knowledge.wiki.project.load_global_registry.

Attribute logger

Alias merge_namespaces

Re-exported from parrot.knowledge.wiki.project.merge_namespaces.

Function normalize_scores

Min-max the score of one namespace's rows into [0, 1].

search_fts returns raw -bm25, which is corpus-relative: a five-page plane and a five-hundred-page plane produce scores on different scales, and merging them raw lets the smaller corpus dominate. Normalising per namespace before the merge is what makes the comparison meaningful (same semantics as WikiCombinedSearch._apply_weight: an all-equal group maps to 1.0).

normalize_scores(rows: list[dict[str, Any]]) -> list[dict[str, Any]]

Parameter Type Default Description
rows list[dict[str, Any]] Result rows of one namespace, mutated in place.

Returns: list[dict[str, Any]] — The same rows.

Function open_namespace_store

Open the single store behind one namespace declaration.

This is both the read path (read_only=True, used by :func:resolve_namespaces) and the --ns <name> write path (read_only=False, spec U2) — the latter bypasses the federation entirely and hands the caller that one plane, writable.

open_namespace_store(name: str, cfg: WikiNamespaceConfig, *, base_dir: Path, read_only: bool = True, arango_timeout: float = DEFAULT_ARANGO_TIMEOUT) -> tuple[BaseWikiStore, Path | None]

Parameter Type Default Description
name str Namespace name.
cfg WikiNamespaceConfig Namespace declaration.
base_dir Path Directory relative paths resolve against (see :func:parrot.knowledge.wiki.project.resolve_entry_base).
read_only bool True Open the plane read-only.
arango_timeout float DEFAULT_ARANGO_TIMEOUT Seconds allowed for an ArangoDB connect.

Returns: tuple[BaseWikiStore, Path | None] — (store, storage_dir); storage_dir is None for server-hosted backends.

Raises:

  • FileNotFoundError — The plane (or its root) does not exist.
  • TimeoutError — An ArangoDB namespace did not answer in time.

Alias qualify_id

Re-exported from parrot.knowledge.wiki.context.qualify_id.

Alias resolve_arango_params

Re-exported from parrot.knowledge.wiki.project.resolve_arango_params.

Alias resolve_entry_base

Re-exported from parrot.knowledge.wiki.project.resolve_entry_base.

Function resolve_namespaces

Merge both registries and open every declared namespace.

Repo declarations win over global ones on a name clash. A namespace that cannot be opened never propagates its error: it comes back as a :class:NamespaceSkip so a broadcast still answers from the rest (spec G9).

resolve_namespaces(root: Path, config: WikiProjectConfig, *, only: set[str] | None = None, registry_path: Path | None = None, read_only: bool = True, arango_timeout: float = DEFAULT_ARANGO_TIMEOUT) -> tuple[list[NamespaceHandle], list[NamespaceSkip]]

Parameter Type Default Description
root Path Repository root (base for relative repo-entry paths).
config WikiProjectConfig The repo's project config.
only set[str] | None None When given, resolve just these namespace names.
registry_path Path | None None Override for the global registry file.
read_only bool True Open the namespaces read-only.
arango_timeout float DEFAULT_ARANGO_TIMEOUT Seconds allowed for an ArangoDB connect.

Returns: tuple[list[NamespaceHandle], list[NamespaceSkip]] — (handles, skipped) — the opened namespaces and the notes for the ones that were not.

Alias split_namespaced_id

Re-exported from parrot.knowledge.wiki.context.split_namespaced_id.

Alias wiki_store

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

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