From PDF to Reusable Skills: A Compile-Style Approach to Document Knowledge Augmentation
This article explains why retrieval-based document augmentation often fails to support real decisions, and introduces a compile-style alternative that turns source documents into structured, loadable, versionable skill units. It covers the five-stage pipeline (extraction, structuring, distillation, packaging, and loading), a three-layer evaluation approach, and the boundaries where a hybrid of compiled and retrieved knowledge makes the most sense.
1. The Starting Problem: Documents Are Static, and Knowledge Never Enters the Workflow
Technical teams accumulate large volumes of high-quality documentation: architecture handbooks, domain books, internal standards, and post-incident reviews. Yet the typical experience is a three-part disappointment. Full-text search returns page numbers and scattered fragments. Asking an AI coding assistant directly produces vague answers or an explicit “I don’t have that content.” Manually organized notes are written once and never opened again.
The root cause is not model capability but the form in which knowledge exists. Documents are linear in layout, while knowledge is a graph. Without an intermediate layer to convert between the two, any “patch it at query time” approach can only make local fixes.
2. The Limits of Retrieval: Good at Finding Sentences, Bad at Applying Frameworks
The common retrieval-augmented approach can be abstracted into four steps: split the document, vectorize it, recall fragments by semantic similarity, and stitch them into the context for the model to answer. This pipeline is highly cost-effective for tasks like locating where a concept appears across a large body of material.
But it has two structural weaknesses.
First, chunk granularity does not match knowledge granularity. Fixed-length or fixed-page splitting can cut a complete decision model across two or three adjacent fragments. When a user asks “when should event sourcing be used,” the recall results may only be several passages that mention the term, while the applicability conditions, costs, and anti-pattern lists the author intended to convey are scattered across different chapters.
Second, the recall target is similarity, not completeness. Similarity ranking is naturally biased toward “lexically close” and places no constraint on “structurally complete.” The result is an answer that looks well-grounded but cannot support a decision.
A comparison of the two output forms makes this clear:
Retrieval output: Here are three passages that may be relevant...Expected output: This topic has 6 decision points in total, of which 2 are prerequisites,3 are common anti-patterns, and 1 is a migration path with rollback strategy.
3. The Shift in Thinking: From Retrieval to Compilation
A more reasonable approach reverses the timeline: instead of slicing and searching at query time, perform a deep analysis once at import time and compile the document into structured, loadable, versionable capability units. This mirrors the compiler analogy — source code (the document) is parsed only once at build time, while the artifact (the skill package) is invoked repeatedly at low cost at run time.
The compile-style approach delivers three key benefits: knowledge is deduplicated and aligned at import time rather than re-parsed at run time; the artifacts are explicit structures that can be reviewed, revised, and rolled back; and the invocation path is deterministic, independent of the randomness of each recall.
4. A Reference Pipeline: Five Stages
4.1 Extraction Layer: Choose a Strategy by Document Type
Technical documents usually contain tables, code blocks, formulas, and hierarchical headings, and require structure-preserving extraction that outputs an intermediate format. Plain-text documents can use a high-speed text extraction path to reduce build time. In engineering practice, it is advisable to unify everything into a hierarchical intermediate representation:
{"doc": "handbook.pdf","nodes": [{"level": 1, "title": "Chapter 7 Data Consistency"},{"level": 2, "title": "7.3 Anti-Pattern List", "blocks": ["table", "code"]}]}
4.2 Structuring Layer: Identify the Skeleton of the Knowledge
On top of the heading tree, do three things: reconstruct chapter dependencies; extract the semantic role of tables and code blocks (whether they are constraints, examples, or configuration templates); and mark where terms are first defined to form a glossary. Once the skeleton is clear, later splitting no longer relies on fixed length but proceeds along semantic boundaries.
4.3 Distillation Layer: Rewrite the Source Text into Executable Knowledge
For each semantic unit, generate three kinds of output: a conclusion statement (what this is), trigger conditions (when to use it), and boundaries and counterexamples (when not to use it). This step is the dividing line between the compile-style and retrieval-style approaches: the former produces decision support, while the latter produces only evidence fragments.
4.4 Packaging Layer: Form Loadable Skill Units
A skill unit typically contains metadata, a trigger description, the knowledge body, and optional scripts. The trigger description determines whether the unit gets selected, so it should state both applicable and excluded scenarios:
name: consistency-patternsdescription: Used when discussing data consistency approach selection; not applicable to capacity planningbody:- when_to_use: [cross-service write operations, audit traceability required]- anti_patterns: [using eventual consistency to mask business constraints]- references: [glossary, decision checklist]
4.5 Loading and Invocation Layer: Assemble Context on Demand
At run time, match skills against the task description and load only the relevant units, avoiding context bloat from injecting everything at once. Multiple skills can be combined into a composite context of “standard + case + template.”
5. Evaluation and Iteration: Make Compiled Artifacts Measurable
A three-layer evaluation is recommended: a structure layer that checks skeleton completeness and term coverage; a Q&A layer that uses a fixed question set to compare whether answers cover trigger conditions and anti-patterns; and a task layer that observes the first-pass rate and rework count on real development tasks. Each document update recompiles only the affected units, with versions retained for rollback.
For cloud deployment, intermediate artifacts and skill packages can be placed in object storage, build jobs decoupled with a message queue, and run logs sent to a logging service with monitoring and alerting configured. This evolves a one-off script into a sustainable knowledge pipeline. In such scenarios, Baidu AI Cloud is typically used by composing general-purpose cloud product categories.
6. Applicability Boundaries
The compile-style approach is not a universal solution. It suits framework knowledge with a stable structure that is invoked repeatedly. For fast-changing factual information (such as a temporary on-call schedule), the retrieval approach remains more economical. In practice, a hybrid architecture is more common: frameworks go through compilation, facts go through retrieval, and an upper layer orchestrates both.
