How ai4wa/docs2kg works
Main Components
a. Command Line Interface (CLI) – Represented by the Docs2KG command line entry (cli.py) that offers multiple commands (process-document, batch-process, neo4j, etc.).
b. Digitization Module – Shown by the “digitization” folder with submodules for image-based (e.g., PDF OCR via pdf_docling) and native digital document parsing (e.g., ebook and HTML parsing).
c. Agents Module – Under the “agents” directory, include both the base agents and specialized ones (e.g., cloud, hf, ollama, function agents). These are responsible for tasks such as Named Entity Recognition (NER) and other LLM interactions.
d. Knowledge Graph Construction – Split into:
• MetaKG (metadata extraction) found in kg_construction/metadata_kg.
• LayoutKG (layout extraction) found in kg_construction/layout_kg.
• SemanticKG (content/NER extraction) in kg_construction/semantic_kg.
e. Utility and Configuration – Components like config management, constants, timers, and neo4j loader (in utils) that support underlying operations.
f. External Integrations – Such as the integration with external LLM services (e.g., the agent “ollama” and possibly “hf” for Hugging Face) and database operations (Neo4j via docs2kg neo4j command).
Relationships and Data Flow
• From the CLI, branch the process into two parallel pathways:
• Document Ingestion & Digitization:
→ Documents enter the digitization module where different paths are applied based on document type (image-based or native).
• Agent Processing:
→ Once digitization is completed, documents (or their extracted content) are passed to the appropriate agent modules for NER and further language model-based processing.
• These streams then converge into the Knowledge Graph Construction component, where the MetaKG, LayoutKG, and SemanticKG modules process the outputs to form a unified knowledge graph.
• Optionally, note the human-LLM collaborative interface (illustrated by the provided screenshots in the README) as an adjunct component that allows human review and enhancement of the generated graph.
Architectural Patterns & Design Principles
• Modularity and separation of concerns: Each major function (digitization, agent-based processing, and KG construction) is encapsulated in its own module/subsystem.
• That the design supports both bottom-up (document parsing) and top-down (LLM-driven graph refinement) processing flows.
• Dependencies with configuration management (via config files like config.example.yml and setup scripts) and CI/CD elements (e.g., GitHub workflows for linting and docs) which keep the codebase integrated and tested.
Technologies and Frameworks
• Use of Python as the main programming language.
• External libraries and dependencies such as SpaCy (for language processing, as indicated by the spaCy download command) and possibly libraries related to LLM integration.
• Mention containerization support (as shown in the “docker-compose.yml” under examples/compose) and CI workflows which further support deployment and testing strategies.