How nazib-riasat/graft_system works
Purpose and entry points
GRAFT is a provenance-preserving temporal graph-memory research system. It builds evidence graphs from conversational/corpus material, selects checker-valid evidence sets, and is designed to support retrieval, answerability gating, and later reading. Primary programmatic entry is the graft Python package; experiment entry points are phase scripts such as scripts/phase3_calibrate.py, scripts/phase5_bakeoff.py, and scripts/phase7_retrieval.py. Configuration starts through graft/config/loader.py with presets in graft/config/presets/.
Shared contracts, identity, and reproducibility
The repository centers its data model in graft/schemas.py, with canonical serialization and content-derived IDs in graft/canonical.py and graft/ids.py. Runs are deterministic and auditable: graft/runtime.py establishes seeds/manifests, graft/eventlog.py records append-only operations, and graft/graphstore.py exposes replay-backed graph snapshots. This is the main boundary between domain stages and durable/reproducible artifacts.
Deterministic evidence-set core
graft/core/ defines the formal decision layer used by learning and search. graft/core/checker.py implements validity \(H\); graft/core/obligations.py represents required evidence/coverage and derives state obligations; graft/core/masks.py constrains legal additions and terminal decisions. graft/core/utility.py and graft/core/reward.py turn valid sets into utility and reward, while graft/core/incremental.py provides add/undo-compatible validity logic. graft/ledger.py supplies budget enforcement at this boundary.
Synthetic environment and learner training
The synthetic proof-lattice environment provides enumerable ground truth and exact evaluation for early-phase learning experiments: graft/synth/lattice.py, graft/synth/exact.py, and graft/synth/audits.py. The set-generation subsystem consumes these state/action semantics through policy, rollout, and trainer layers in graft/setgen/policy.py, graft/setgen/rollout.py, and graft/setgen/trainer.py. Multiple supervised, imitation, RL, trajectory-balance, and checker-conditioned learner arms live under graft/setgen/learners/; this stage requires the ML/PyTorch dependency boundary.
Evidence-set search and portfolio selection
Search is separated from learned generation so methods can be compared under the same checker and utility. graft/setgen/search/base.py defines the search interface; greedy, beam, submodular, PCST, and portfolio methods are in graft/setgen/search/s1_greedy.py, graft/setgen/search/s2_beam.py, and graft/setgen/search/s5_portfolio.py. graft/setgen/search/gate3.py is the comparative gate harness. Search operates on candidate evidence sets and must respect core masks/checker outcomes rather than independently redefining validity.
Ingestion: corpus material to grounded graph evidence
Stage-A ingestion transforms source material into structured, provenance-linked evidence. graft/ingest/pipeline.py orchestrates extraction and processing; graft/ingest/extractor.py produces candidate content; graft/ingest/grounding.py attaches graph grounding; and graft/ingest/nli.py verifies entailment/support. Obligation parsing and support gating are explicit downstream controls in graft/ingest/oblparse.py and graft/ingest/support.py. Annotation artifacts and finalized labels are stored under data/phase2_5/.
Graph construction, retrieval, and answerability boundaries
Later real-data stages are modularized behind distinct package boundaries. graft/graphbuild/ builds and validates graph edges/candidates, notably graft/graphbuild/candidates.py, graft/graphbuild/commit.py, and graft/graphbuild/validate.py; it may use embeddings or LLM linking via graft/graphbuild/embed.py and graft/graphbuild/llmlink.py. graft/retrieve/ forms and ranks evidence pools using BM25, dense, entity, temporal, and fused retrieval (graft/retrieve/pool.py, graft/retrieve/fuse.py, graft/retrieve/scorer.py). graft/gate/decide.py is the separate answerability/risk decision layer, preventing retrieval or graph construction from directly asserting answerability.
Runtime and infrastructure
The project targets Python 3.11/3.12, with baseline dependencies in requirements.txt and optional ML/GPU dependencies in requirements-ml.txt; CUDA/PyTorch is material for Phase 3 training. Bootstrap scripts support Windows and Unix environments: scripts/bootstrap.ps1 and scripts/bootstrap.sh. External model and corpus integrations are implied by ingestion NLI/extraction, graph-building embeddings/LLM linking, and retrieval backends, but are contained in their respective stage packages rather than exposed as a web-service architecture.
Main entry points: checker.py Checker, obligations & masks · trainer.py Policy, rollout & trainer · phase3_calibrate.py Phase experiment scripts · utility.py Utility, reward & ledger
Components 19
Reproducible foundation
Shared contracts and durable run artifacts.
- graft package · Primary programmatic entry point.
graft - Config loader & presets
graft/config/loader.py - Domain schemas · Canonical evidence, graph, and run data model.
graft/schemas.py - Canonical IDs · Canonical serialization and content-derived identifiers.
graft/canonical.py - Deterministic runtime · Establishes seeds and manifests.
graft/runtime.py - Event log & graph snapshots · Append-only operations with replay-backed graph snapshots.
graft/eventlog.py
Evidence decision and learning
Formal validity semantics, synthetic evaluation, and set generation.
- Checker, obligations & masks · Defines validity, required coverage, and legal evidence actions.
graft/core/checker.py - Utility, reward & ledger · Scores valid sets and enforces budgets.
graft/core/utility.py - Proof-lattice environment · Enumerable ground truth and exact audits for learning experiments.
graft/synth/lattice.py - Policy, rollout & trainer · Trains learner arms against shared state and action semantics.
graft/setgen/trainer.py - Search & portfolio methods · Comparable greedy, beam, and portfolio selection methods.
graft/setgen/search/base.py - Search comparison gate
graft/setgen/search/gate3.py
Real-data evidence pipeline
Corpus ingestion through graph, retrieval, and answerability stages.
- Extraction & grounding · Transforms corpus material into provenance-linked candidate evidence.
graft/ingest/pipeline.py - Obligation parse & support gate · Parses obligations and verifies entailment/support.
graft/ingest/oblparse.py - Phase 2.5 annotations · Finalized labels and annotation artifacts.
- Graph build & validation · Builds, commits, and validates grounded graph edges.
graft/graphbuild/commit.py - Evidence retrieval & fusion · Builds and ranks BM25, dense, entity, temporal, and fused pools.
graft/retrieve/pool.py - Answerability decision · Separates answerability and risk decisions from retrieval.
graft/gate/decide.py
Other components
- Phase experiment scripts · Calibration, bakeoff, and retrieval experiment runners.
scripts/phase3_calibrate.py
Connections 23
- graft package → Config loader & presets: loads
- Config loader & presets → Deterministic runtime: configures
- Domain schemas → Canonical IDs: canonicalizes
- Deterministic runtime → Event log & graph snapshots: records runs
- Domain schemas → Checker, obligations & masks: defines evidence contracts
- Checker, obligations & masks → Utility, reward & ledger: valid sets
- Proof-lattice environment → Checker, obligations & masks: uses state semantics
- Checker, obligations & masks → Policy, rollout & trainer: constrains actions
- Utility, reward & ledger → Policy, rollout & trainer: provides rewards
- Proof-lattice environment → Policy, rollout & trainer: provides exact evaluation
- Checker, obligations & masks → Search & portfolio methods: enforces validity
- Utility, reward & ledger → Search & portfolio methods: ranks candidates
- Search & portfolio methods → Search comparison gate: compares methods
- Extraction & grounding → Obligation parse & support gate: candidate evidence
- Phase 2.5 annotations → Extraction & grounding: annotation input
- Obligation parse & support gate → Graph build & validation: grounded supported evidence
- Graph build & validation → Event log & graph snapshots: commits graph operations
- Graph build & validation → Evidence retrieval & fusion: graph evidence
- Evidence retrieval & fusion → Answerability decision: ranked evidence pool
- Checker, obligations & masks → Answerability decision: checker-valid evidence
- Phase experiment scripts → Policy, rollout & trainer: Phase 3
- Phase experiment scripts → Search comparison gate: Phase 5
- Phase experiment scripts → Evidence retrieval & fusion: Phase 7