Skip to content

API Reference parrot.knowledge.graphindex.context_builder

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

parrot.knowledge.graphindex.context_builder

View source

Task-scoped context construction from a knowledge graph.

Implements the paper's graph-grounded context recipe: resolve the entities a task mentions, expand a bounded neighbourhood over allowed edge types, prefer recent verified (asserted) claims, surface conflicts explicitly, and serialize everything within a token budget — with a stable, citable id attached to every relation so downstream evaluators can check answers edge-by-edge instead of trusting free-form prose.

The builder is a thin composition over :class:GraphExpandedRetriever (which already provides seeded search, decayed multi-hop expansion, and budgeting) — the deltas here are entity seeding, edge-kind filtering, assertion-aware ranking, conflict surfacing, and citation serialization.

Alias BudgetConfig

Re-exported from parrot.knowledge.graphindex.retriever.BudgetConfig.

Class ContextBuildConfig

Configuration for graph context construction.

Fields:

Field Type Default Description
allowed_edge_kinds Optional[list[str]] None
max_hops int 2
max_tokens int 4000
seed_top_k int 8
include_conflicts bool True
prefer_asserted bool True
max_entities int 10

Alias ExpansionConfig

Re-exported from parrot.knowledge.graphindex.retriever.ExpansionConfig.

Class GraphContext

Serialized, citable graph context for one task.

Fields:

Field Type Default Description
text str
entities list[str]
node_ids list[str]
cited_edge_ids list[str]
conflicts list[str]
budget_used int 0
truncated bool False

Class GraphContextBuilder

Build task-specific, token-budgeted context from a graph.

Parameter Type Default Description
retriever GraphExpandedRetriever A :class:GraphExpandedRetriever over the graph.
entity_resolver Optional[object] None Optional resolver with an async extract_and_resolve(text) API; when absent, entities are resolved by (case-insensitive) title mention matching — dependency-free and adequate for agent-memory graphs.

Method GraphContextBuilder.build

Build the serialized graph context for a task.

build(task: str, config: Optional[ContextBuildConfig] = None) -> GraphContext

Parameter Type Default Description
task str The task/question the context should ground.
config Optional[ContextBuildConfig] None Optional build configuration.

Returns: GraphContext — class:GraphContext with citable relations.

Alias GraphExpandedRetriever

Re-exported from parrot.knowledge.graphindex.retriever.GraphExpandedRetriever.

Alias ScoredNode

Re-exported from parrot.knowledge.graphindex.retriever.ScoredNode.

Alias UniversalNode

Re-exported from parrot.knowledge.graphindex.schema.UniversalNode.

Attribute logger

Alias stable_edge_id

Re-exported from parrot.knowledge.graphindex.schema.stable_edge_id.

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