Skip to content

API Reference parrot.knowledge.graphindex.projection

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

parrot.knowledge.graphindex.projection

View source

GraphIndex OKF Projection Layer (FEAT-239).

Projects every UniversalNode as an OKF-compatible .md sidecar file with YAML frontmatter. Also provides the frontmatter string for GRAPH_REPORT.md.

Key design decisions:

  • node_to_frontmatter_dict() and project_node_sidecar() are pure functions (no I/O) for easy unit testing.
  • project_graph_sidecars() is async; all disk I/O runs via asyncio.to_thread() to avoid blocking the event loop.
  • Sidecars are written to output_dir/nodes/<filename>.md.
  • Sidecar filenames use flatten_concept_id_for_filename(node_id) — slashes become --.
  • Byte-determinism: project_node_sidecar() produces identical bytes for the same inputs. project_report_frontmatter() is deterministic when an explicit timestamp is passed; without one it uses the current UTC time (non-deterministic by definition).
  • If content_store is not provided (or a content_ref fails to resolve), the body falls back gracefully to summary or title.
  • Projection failures do NOT propagate as exceptions; callers are expected to wrap the async call in a try/except.

Attribute EDGE_KIND_TO_RELATION_TYPE

Type: dict[EdgeKind, RelationType]

Attribute NODE_KIND_TO_CONCEPT_TYPE

Type: dict[NodeKind, ConceptType]

Function node_to_frontmatter_dict

Convert a UniversalNode + its outgoing edges into a project_frontmatter() dict.

The returned dict conforms to the contract expected by project_frontmatter(node_dict, tree_name). It is a pure function with no I/O — the same inputs always produce the same output.

node_to_frontmatter_dict(node: UniversalNode, edges: list[UniversalEdge]) -> dict

Parameter Type Default Description
node UniversalNode The GraphIndex node to project.
edges list[UniversalEdge] All edges in the graph. Only outgoing edges from node are included in relates_to.

Returns: dict — Dict suitable for project_frontmatter(dict, "graphindex").

Function project_graph_sidecars

Write per-node .md sidecars to output_dir/nodes/.

All disk I/O runs via asyncio.to_thread() to avoid blocking the event loop. For each node:

  1. Resolves body from content_ref (via thread) if content_store is available.
  2. Projects YAML frontmatter + body via project_node_sidecar() (CPU-only).
  3. Writes to output_dir/nodes/<flattened_node_id>.md (via thread).

project_graph_sidecars(nodes: list[UniversalNode], edges: list[UniversalEdge], output_dir: Path, content_store: Optional[object] = None, pageindex_toolkit: Optional[object] = None) -> GraphProjectionReport

Parameter Type Default Description
nodes list[UniversalNode] All UniversalNode objects to project.
edges list[UniversalEdge] All UniversalEdge objects in the graph.
output_dir Path Base directory for output. A nodes/ subdirectory is created automatically.
content_store Optional[object] None Optional NodeContentStore for body resolution.
pageindex_toolkit Optional[object] None Unused in the current implementation; reserved for future direct-toolkit body resolution.

Returns: GraphProjectionReport — A GraphProjectionReport summarising the projection run.

Function project_node_sidecar

Return the complete sidecar text: YAML frontmatter + body.

The output is byte-deterministic: the same node, edges, and body always produce the same result.

project_node_sidecar(node: UniversalNode, edges: list[UniversalEdge], body: str) -> str

Parameter Type Default Description
node UniversalNode The GraphIndex node to project.
edges list[UniversalEdge] All edges (outgoing edges from node become relates_to).
body str Full text body for the sidecar (may be full content or summary).

Returns: str — Complete sidecar string starting with ---\n frontmatter.

Function project_report_frontmatter

Generate OKF YAML frontmatter string for GRAPH_REPORT.md.

The output is byte-deterministic when timestamp is supplied; without it the current UTC time is embedded, making each call unique.

project_report_frontmatter(analytics: AnalyticsResult, tenant_id: str, timestamp: Optional[str] = None) -> str

Parameter Type Default Description
analytics AnalyticsResult The analytics result from the graph build.
tenant_id str Tenant identifier used in the concept-id.
timestamp Optional[str] None Optional ISO-8601 timestamp string. When provided, the frontmatter is byte-identical for the same inputs. When omitted, the current UTC time is used (non-deterministic across calls).

Returns: str — YAML frontmatter string delimited by ---\n.

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