Document Ingestion & Chunking Pipelines
Overview
The document ingestion pipeline (src/ingestion/) converts unstructured and semi-structured Life Sciences documents into synchronized entries across PostgreSQL, Qdrant, and Memgraph.
Ingestion Architecture
[ Input Document (Markdown / Text / PDF / DOCX) ] | v [ Document Structure Parser ] Extracts Header, Section Hierarchy, Tables, Metadata | v [ GxP Context-Preserving Chunker ] Chunks by Section Boundaries (500-1000 tokens) Prepends Document Breadcrumbs & Section Title | v [ Cryptographic Hashing Engine ] Computes SHA-256 for Document and each Chunk | +---------------+---------------+ | | | v v v [ PostgreSQL ] [ Qdrant ] [ Memgraph ] Canonical Store Dense/Sparse Knowledge Graph Row & Hashes Embedding Sync Entity Nodes & EdgesChunking Strategy
Standard character-count chunking splits sentences arbitrarily, destroying regulatory meaning and breaking numerical criteria away from their requirements. The platform uses Context-Preserving Structural Chunking:
- Section-Boundary Splitting: Splits documents along markdown headings (
##,###,####), XML section tags, or paragraph breaks. - Contextual Breadcrumb Injection: Every chunk is prepended with its hierarchical origin:
This ensures that even when a chunk is retrieved in isolation, the embedding vector and LLM context retain document identity and section context.Document: SOP-QA-012 (Rev 3.0) | Section 4.2: Audit Trail Review Procedures---------------------------------------------------------------------------[Chunk Content...]
- Table & Formula Protection: Markdown tables, acceptance criteria ranges, and mathematical equations are preserved intact within a single chunk rather than fractured.
Synchronized Multi-Store Persistence
When a document is ingested:
- PostgreSQL: Stores the raw document in
controlled_documentsand inserts chunk records intodocument_chunkswithchunk_hash = SHA256(content). - Embeddings Engine: Generates dense embeddings (via Ollama
qwen3-embedding:8bor OpenAI) and sparse token frequency vectors. - Qdrant: Upserts vector points with full payload attributes.
- Memgraph: Creates the
:Documentnode, creates:Chunknodes, and creates:CONTAINS_CHUNKrelationships.