How dgg32/helms works
Purpose and entry points
HELMS builds schema-driven, typed knowledge graphs from PDF/Markdown documents. It extracts candidate triples with an LLM, validates and reviews them, persists approved facts, and exposes graph/document retrieval to AI clients.
• CLI pipeline: pipeline.py, convert_pdf.py, extract.py, apply_graph.py
• Web workflow: htmx_app/main.py
• MCP read/query and ingest endpoints: mcp_server.py, mcp_ingest_server.py
Schema and project boundary
A project supplies the human-authored graph contract and document scope; runtime output is organized into project run folders. The schema determines node types, relationship types, primary keys, extraction prompts, and resolver constraints, avoiding domain-specific code changes.
• projects/drug/schema.yaml, projects/drug/meta.yaml
• projects/supplychain/schema.yaml, projects/supplychain/meta.yaml
• schema_raw.py, pipeline_meta.py
Document-to-candidate extraction
PDF conversion produces Markdown sidecars, then extraction semantically chunks Markdown and makes structured LLM calls per chunk. It retains immutable raw triples and document text, while quote grounding re-anchors LLM-provided evidence to exact source spans. Extraction is cacheable and supports multiple LLM providers through one structured-output interface.
• convert_pdf.py, extract.py, grounding.py
• llm_client.py, prompts.yaml
Flow: PDF → Markdown → chunks → LLM triples/evidence → grounded <stem>_raw.json. Metadata instructions and page filters cross the conversion/extraction boundary.
Safeguards and human review
External entity resolution occurs after extraction: UMLS for medical concepts and GLEIF for organizations. A semantic-check agent is the sole authority for green/yellow/red verdicts, applying LLM relation-support checks plus deterministic schema, type, duplicate, and fabricated-quote validators. Human actions remain separate as an event log; materialization overlays edits onto immutable raw output before graph writes.
• agents/node_agent.py, agents/umls_resolver.py, agents/gleif_resolver.py
• agents/semantic_check_agent.py, review_layer.py
• agents/extraction_agent.py
The targeted agentic retry path can add/re-resolve one relationship type, then re-runs semantic checking.
Learning loop and orchestration
Approved, overridden, agent-retry, and rejected review outcomes are harvested into per-relationship examples. Future extraction injects positive examples and document-specific rejection reminders. The orchestration layer supports CLI, UI-runner, and background ingestion paths while preserving run artifacts and statistics.
• agents/harvest.py, pipeline.py, pipeline_runner.py
• mcp_ingest_server.py, kg_logging.py
Graph persistence and query serving
apply_graph.py materializes reviews, filters by verdict, and writes nodes/edges through a backend abstraction. Node identity is primary-key based; edges are source-document-scoped, enabling incremental multi-document provenance and same-document replacement.
• apply_graph.py, backends/base.py
• backends/ladybug_backend.py, backends/neo4j_backend.py
LadybugDB is the default embedded openCypher store; Neo4j is supported over Bolt. mcp_server.py serves read-only Cypher plus just-in-time retrieval from raw document text, with FastMCP as the integration runtime.
External services and runtimes
The Python application uses LiteLLM for Azure OpenAI, OpenAI-compatible, Anthropic, Ollama, and Gemini structured calls; UMLS and GLEIF REST APIs for authority grounding; pymupdf4llm or LlamaParse for conversion; FastAPI/HTMX for the optional UI; SQLite caching for registry lookups.
• lookup_cache.py, lookups.py
• htmx_app/main.py, mcp_server.py
Main entry points: pipeline_meta.py Schema loader · semantic_check_agent.py Semantic check agent · extract.py Candidate extraction · apply_graph.py Graph materialization
Components 20
Project contract
Schema and metadata define each graph domain and document scope.
- Project schemas · Defines types, keys, relations, prompts, and resolver constraints.
projects/drug/schema.yaml - Project metadata · Supplies document metadata and pipeline instructions.
projects/drug/meta.yaml - Schema loader
pipeline_meta.py
Extraction pipeline
Documents become grounded immutable candidate facts.
- PDF conversion · Produces Markdown sidecars with metadata and page filtering.
convert_pdf.py - Candidate extraction · Chunks Markdown and emits raw triples plus evidence.
extract.py - Structured LLM client · Supports multiple providers through one structured-output interface.
llm_client.py - Quote grounding · Re-anchors evidence to exact document spans.
grounding.py - Raw run artifacts · Stores source text and grounded raw triples per document run.
Resolution and review
Candidates are resolved, checked, and edited before approval.
- Entity resolution · Resolves medical concepts and organizations through external registries.
agents/node_agent.py - Lookup cache · Caches registry lookups.
lookup_cache.py - Semantic check agent · Assigns green, yellow, or red using LLM and deterministic validators.
agents/semantic_check_agent.py - Review event log · Keeps human actions separate from immutable extraction output.
review_layer.py - Example harvesting · Builds relationship examples and rejection reminders from outcomes.
agents/harvest.py
Graph serving
Approved facts are materialized into queryable graph storage.
- Graph materialization · Overlays review edits, filters verdicts, and writes graph changes.
apply_graph.py - Graph backend abstraction · Supports embedded LadybugDB and Neo4j graph persistence.
backends/base.py - MCP query server · Serves read-only Cypher and just-in-time document retrieval.
mcp_server.py
Runtimes and integrations
CLI, web, and MCP paths invoke the shared workflow.
- Pipeline orchestrator · Preserves run artifacts and statistics across execution modes.
pipeline_runner.py - CLI pipeline
pipeline.py - HTMX web workflow
htmx_app/main.py - MCP ingest server
mcp_ingest_server.py
Connections 25
- Project schemas → Schema loader: loaded as contract
- Project metadata → Schema loader: loads scope
- Schema loader → PDF conversion: instructions and filters
- Schema loader → Candidate extraction: types and prompts
- PDF conversion → Candidate extraction: Markdown sidecars
- Candidate extraction → Structured LLM client: structured calls
- Structured LLM client → Quote grounding: triples and evidence
- Quote grounding → Raw run artifacts: grounded raw output
- Raw run artifacts → Entity resolution: candidate entities
- Entity resolution → Lookup cache: caches registry results
- Entity resolution → Semantic check agent: resolved candidates
- Raw run artifacts → Semantic check agent: triples and source evidence
- Semantic check agent → Review event log: verdicts for review
- Review event log → Graph materialization: edits and overrides
- Raw run artifacts → Graph materialization: immutable source facts
- Semantic check agent → Graph materialization: approved verdicts
- Review event log → Example harvesting: outcomes
- Example harvesting → Candidate extraction: examples and reminders
- Graph materialization → Graph backend abstraction: nodes and scoped edges
- Graph backend abstraction → MCP query server: Cypher reads
- Raw run artifacts → MCP query server: document retrieval
- CLI pipeline → Pipeline orchestrator: invokes
- HTMX web workflow → Pipeline orchestrator: runs workflow
- MCP ingest server → Pipeline orchestrator: background ingestion
- Pipeline orchestrator → PDF conversion: coordinates pipeline