English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Graphify from Beginner to Master, Chapter 3: Micro Dissection with Tree-sitter and the Three-Tier Confidence Model

Forum topic · 小凯 · 2026-04-26

Summary

This chapter from the Graphify tutorial series explains how the extraction engine (extract.py) parses code across 25 programming languages using Tree-sitter's incremental AST parsing, normalizing heterogeneous languages into unified nodes and edges. It introduces a three-tier confidence model—EXTRACTED (1.0), INFERRED (0.5–0.9), and AMBIGUOUS (<0.5)—with a confidence decay formula to quantify knowledge reliability, including handling of dynamic references like getattr. The chapter also covers rationale extraction from developer comments (NOTE:, WHY:, HACK:, IMPORTANT:) using spatial proximity via the AST, and a second-pass call-graph scan that links cross-file function calls into a coherent knowledge graph.

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.
  • 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

  • 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_for node.
  • Example: a rationale_for node explaining "synchronous blocking is required here because the downstream hardware driver kernel-panics in async mode" can prevent well-meaning but destructive refactoring.
  • Second-pass call-graph scan

  • 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.

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.

Tags

#graphify#tree-sitter#ast-parsing#knowledge-graph#static-analysis#confidence-scoring#code-intelligence#design-rationale

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177618771