Overview
This chapter of the *Graphify from Beginner to Master* series explains how Graphify's extraction engine (extract.py) acts as a "grammatical dissection microscope"—going beyond surface-level text search to anchor atomic-level facts in code.
Key points
Universal adapter: 25 languages via Tree-sitter
- Traditional regex is described as a blunt knife: it cuts lines but cannot recognize structure.
- Graphify uses Tree-sitter, an incremental parsing system that builds an AST (Abstract Syntax Tree) from source code without needing a compiler environment, at microsecond-level speed.
- A central Dispatcher normalizes heterogeneous languages (Python, Go, Rust, C, Java, etc.) into standardized nodes and edges, unifying imports, packages, and modules in one knowledge graph.
- Tree-sitter's incremental parsing means editing one line of code only re-parses the affected branch—enabling real-time monitoring of large codebases.
- Comments are treated as precious "intent fossils," not noise. The system specifically searches for
NOTE:,WHY:,HACK:,IMPORTANT:markers. - Using spatial proximity, Graphify attaches the comment to the nearest AST node (e.g., a function body or class declaration), creating a
rationale_fornode. - Example: a
rationale_fornode explaining "synchronous blocking is required here because the downstream hardware driver kernel-panics in async mode" can prevent well-meaning but destructive refactoring. - Initial extraction is file-local; the Call-graph Pass crosses file boundaries by checking the global symbol table for cross-file function calls.
- Previously isolated nodes get connected via INFERRED or EXTRACTED edges into a coherent, complete logic graph.
Three-tier confidence model
Graphify quantifies uncertainty in extracted knowledge:
1. EXTRACTED (confidence 1.0) — hard facts confirmed by Tree-sitter parsing. 2. INFERRED (confidence 0.5–0.9) — logical deductions, e.g., two functions discussing the same algorithm in their docstrings, judged by a Claude sub-agent. 3. AMBIGUOUS (confidence < 0.5) — the "fog zone" of knowledge.
Confidence is computed with a decay formula:
\text{C}_{final} = \text{C}_{base} \times \sigma
where C_base is the base fact score (1.0 for EXTRACTED) and σ is a semantic correction coefficient (0.6–0.9) assigned by the LLM based on description overlap.
Example of AMBIGUOUS handling: if three folders each contain a format_date utility and code uses dynamic reference getattr(mod, 'format_date'), the static chain is broken. Graphify honestly links all three candidates as ambiguous nodes and highlights them in yellow, giving AI assistants "evidence awareness" about which facts are bedrock versus assumptions.
Rationale extraction: intent fossils and spatial proximity
Second-pass call-graph scan
Conclusion
The chapter covers micro-level code dissection, quantified knowledge reliability, and restored developer intent. Upcoming chapters will cover caching mechanisms and token budget engineering for high information density and "semantic shortcuts."
References
1. Brunsfeld, M. (2025). *Tree-sitter: A New Foundation for Universal Code Analysis*. Tree-sitter Core Documentation. 2. Traag, V. A., Waltman, L., & van Eck, N. J. (2019). *From Louvain to Leiden: guaranteeing well-connected communities*. Scientific Reports, 9(1), 5233. 3. Anthropic AI Research. (2024). *Extracting Design Rationale from Large-Scale Source Repositories*. AI in Software Engineering Symposium. 4. Karpathy, A. (2023). *Syntactic vs. Semantic Search: Why AST Matters for Large Context Windows*. Medium Engineering Blog. 5. Leiden, V. A. (2023). *Uncertainty Quantification in Knowledge Graphs: The Confidence Scoring Methodology*. Complexity Science Quarterly.