How yifanfeng97/hyper-extract works
1. Repository purpose
Hyper-Extract is a Python 3.11+ package for turning unstructured documents into structured “Knowledge Abstracts.” The core architecture is centered on extracting text into strongly typed outputs such as models, lists, sets, graphs, hypergraphs, temporal graphs, and spatial/spatio-temporal graphs.
2. Primary runtime boundary
The main runtime is a Python library plus a CLI. Users either call the package API directly or invoke he/he-mcp from the command line. There is no separate backend service in the repo; the system runs locally and talks to external model providers over network APIs.
3. Top-level pipeline
The dominant data flow is: input document → template selection/configuration → extraction method → LLM/embedding provider calls → typed knowledge abstract → search/show/export actions. This same pipeline is reused across the CLI, Python API, and MCP server.
4. Type system / knowledge structures
hyperextract/types defines the canonical data structures that all extraction methods target. These types are the architectural backbone: they provide serialization, merging, search, iteration, slicing, and graph-specific behaviors. The repo treats the output structure as first-class, not as loose JSON.
5. Template subsystem
hyperextract/templates contains a large preset library of YAML templates and the template design docs. Templates define language, output schema, identifiers, and extraction intent. The template engine in hyperextract/utils/template_engine parses these YAML definitions into runtime objects, validates fields, handles display/output metadata, and drives template discovery/generation.
6. Extraction methods subsystem
hyperextract/methods is the algorithm layer. It contains “typical” extractors such as ATOM, ITEXT2KG, ITEXT2KG*, and KG-Gen, plus RAG-oriented methods such as GraphRAG, LightRAG, Hyper-RAG, Hypergraph-RAG, and Cog-RAG. These methods are the strategy boundary between a template/type specification and the actual LLM-driven extraction process.
7. Model/provider integration
hyperextract/utils/client.py and the provider-related docs indicate a pluggable provider system for both LLM and embedding backends. The repo supports OpenAI-compatible endpoints, Anthropic Claude, Alibaba Bailian, and local vLLM. This provider layer is important because structured output and embeddings are external dependencies, and the extraction quality depends on them.
8. CLI subsystem
hyperextract/cli is the user-facing operational layer. It exposes commands for configuration, listing templates, parsing documents, searching, showing results, exporting, and cleaning knowledge abstracts. The CLI is the main orchestration point for end-to-end document ingestion, query, and maintenance workflows.
9. MCP server boundary
hyperextract/mcp_server.py exposes a read/query/export interface through the Model Context Protocol. This is a separate integration boundary for AI assistants and IDE agents: it wraps existing knowledge-abstract capabilities without introducing a new storage layer or extraction pipeline.
10. Export and local knowledge representation
Utilities such as hyperextract/utils/obsidian.py and the export workflow show that knowledge abstracts can be serialized into external note systems, especially Obsidian vaults with linked Markdown. This means the repo supports a “structured knowledge → portable local artifact” boundary, not just in-memory querying.
11. Configuration and logging
hyperextract/cli/config.py, .env.example, and hyperextract/utils/logging.py indicate standard runtime configuration through environment/file-based settings plus structured logging. This supports credential setup, provider selection, and reproducible CLI behavior.
12. Docs and examples as architecture probes
The extensive docs/ and examples/ trees are not just marketing material; they mirror the product’s architecture. They document the template system, provider system, method families, and end-to-end workflows in both English and Chinese, and the examples demonstrate the same flows across languages, domains, and output types.
13. Testing strategy
tests/ is organized around the same boundaries as the code: types, template engine, CLI, utilities, integration, and MCP. This suggests the project’s correctness model is centered on preserving template parsing, type behavior, provider integration, and extraction workflow consistency rather than on a single monolithic app layer.
14. External dependencies that shape architecture
The architecture is shaped by LLM APIs and embedding endpoints, plus the structured-output capabilities those models must support (json_schema/function-calling style behavior). The repo’s design emphasizes provider abstraction so the same extraction pipeline can run against cloud APIs or local inference servers.
Main entry points: base.py Base Type · registry.py Method Registry · client.py Provider Client · template.py Template Engine
Components 25
User Interfaces
Library, CLI, and MCP entry points for running extraction and querying results.
- Package API · Public import surface for programmatic use.
hyperextract/__init__.py - CLI · Main command-line orchestration entry point.
hyperextract/cli/cli.py - Commands · Operational commands for parse, search, show, export, config, and maintenance.
hyperextract/cli/commands - MCP Server · Model Context Protocol boundary for assistant-driven query and export workflows.
hyperextract/mcp_server.py
Core Domain
Canonical knowledge-abstract types and their behaviors.
- Base Type · Shared serialization, merging, iteration, and search behavior.
hyperextract/types/base.py - Model · Attribute-oriented knowledge abstract.
hyperextract/types/model.py - List · Ordered extracted items with slicing and iteration.
hyperextract/types/list.py - Set · Deduplicated extracted items and operators.
hyperextract/types/set.py - Graph · Node-edge knowledge abstraction for relationships.
hyperextract/types/graph.py - Hypergraph · Higher-order relation structure for grouped associations.
hyperextract/types/hypergraph.py - Temporal Graph · Graph abstraction with temporal structure.
hyperextract/types/temporal_graph.py - Spatial Graph · Graph abstraction with spatial structure.
hyperextract/types/spatial_graph.py
Templates
YAML presets and the runtime template engine that turns them into usable extraction specs.
- Preset Templates · Domain and output presets organized by task and vertical.
hyperextract/templates/presets - Template Engine · Loads, validates, and materializes template definitions.
hyperextract/utils/template_engine/template.py - Template Parsers · Field, output, schema, and metadata parsing for YAML templates.
hyperextract/utils/template_engine/parsers
Extraction Methods
Strategy layer for typical extraction and RAG-oriented pipelines.
- Method Registry · Selects and exposes extraction strategies.
hyperextract/methods/registry.py - ATOM · Representative non-RAG extraction strategy.
hyperextract/methods/typical/atom.py - iText2KG · Text-to-knowledge-graph extraction family.
hyperextract/methods/typical/itext2kg.py - GraphRAG · Graph-based retrieval-augmented extraction strategy.
hyperextract/methods/rag/graph_rag.py - Hyper-RAG · Hypergraph-oriented retrieval-augmented extraction strategy.
hyperextract/methods/rag/hyper_rag.py
Integration
Provider clients, export paths, and runtime support utilities.
- Provider Client · Pluggable client layer for model and embedding backends.
hyperextract/utils/client.py - Obsidian Export · Serializes knowledge abstracts into linked Markdown vaults.
hyperextract/utils/obsidian.py - Logging · Structured logging and runtime diagnostics.
hyperextract/utils/logging.py
Docs & Examples
Reference material and examples that mirror the main architecture.
- Architecture Docs · Core design, provider, methods, and template concepts.
docs/en/concepts/architecture.md - Examples · Cross-language demos for templates, methods, autotypes, and providers.
examples
Connections 39
- CLI → Commands: dispatches · CLI routes user commands into operational handlers.
- Package API → Method Registry: exposes · Package API makes the extraction method surface available.
- CLI → Template Engine: loads templates · Command workflows resolve templates before extraction.
- Commands → Method Registry: selects methods · Commands choose extraction strategies via the registry.
- MCP Server → Package API: wraps · MCP exposes library capabilities without a separate backend.
- Method Registry → ATOM: registers · Typical extractor family is available through the registry.
- Method Registry → iText2KG: registers · Typical extractor family is available through the registry.
- Method Registry → GraphRAG: registers · RAG extractor family is available through the registry.
- Method Registry → Hyper-RAG: registers · RAG extractor family is available through the registry.
- Preset Templates → Template Engine: parsed by · YAML presets become runtime template objects.
- Template Engine → Template Parsers: uses · Engine delegates validation and schema parsing to parser modules.
- Template Engine → Method Registry: configures · Template metadata drives method selection and execution parameters.
- Template Engine → Base Type: targets · Templates specify the structured output shape to produce.
- ATOM → Provider Client: calls · Extraction requires model or embedding provider access.
- iText2KG → Provider Client: calls · Extraction requires model or embedding provider access.
- GraphRAG → Provider Client: calls · Retrieval-augmented extraction depends on external providers.
- Hyper-RAG → Provider Client: calls · Retrieval-augmented extraction depends on external providers.
- ATOM → Base Type: produces · All extractors emit canonical knowledge-abstract types.
- iText2KG → Graph: produces · Graph-oriented outputs are a central target for this family.
- GraphRAG → Graph: produces · GraphRAG builds graph-structured knowledge abstracts.
- Hyper-RAG → Hypergraph: produces · Hyper-RAG builds hypergraph-structured knowledge abstracts.
- Base Type → Model: specializes · Model is one canonical structured output form.
- Base Type → List: specializes · List is one canonical structured output form.
- Base Type → Set: specializes · Set is one canonical structured output form.
- Base Type → Graph: specializes · Graph is one canonical structured output form.
- Base Type → Hypergraph: specializes · Hypergraph is one canonical structured output form.
- Base Type → Temporal Graph: specializes · Temporal graph extends the canonical output family.
- Base Type → Spatial Graph: specializes · Spatial graph extends the canonical output family.
- Base Type → Obsidian Export: exports to · Knowledge abstracts can be serialized into local note artifacts.
- Commands → Obsidian Export: exports · CLI export commands target external note systems.
- Commands → Logging: logs · Operational commands rely on structured runtime logging.
- MCP Server → Obsidian Export: offers export · Assistant-facing workflows can surface export actions.
- Architecture Docs → Preset Templates: documents · Docs explain the preset library and selection patterns.
- Architecture Docs → Method Registry: documents · Docs describe the method families and registry boundary.
- Architecture Docs → Provider Client: documents · Docs explain provider abstraction and backend choices.
- Examples → Preset Templates: demonstrates · Examples mirror template-driven extraction flows.
- Examples → ATOM: demonstrates · Examples show typical extraction usage.
- Examples → GraphRAG: demonstrates · Examples show RAG-based extraction usage.
- Examples → Provider Client: demonstrates · Examples show different provider backends.