Collected sources and patterns will appear here. Add from search or the patterns library.
Layout-preserving document-intelligence pipeline. Two ingestion lanes (web markdown; layout-rich docs that keep their 2D bounding-box geometry) feed a rate-budgeted embedding stage, write to an entity-relation knowledge graph, and answer via hybrid graph+vector retrieval. Differentiator: table/form structure survives ingestion. Star atom: spatial-coordinate text embedding (LayoutLM).
Ingest a web source and a two-token invoice ("TotalDue:" beside "$5,000") with side-by-side bounding boxes; assert the tokens and their layout-adjacency edge land in the graph and that hybrid retrieval returns them.# Layout-Preserving Document-Intelligence Pipeline (LP-DIP)
A dual-lane ingestion and retrieval pipeline that preserves table/form geometry through embedding instead of flattening it, then retrieves over a knowledge graph with hybrid vector+graph search.
## Overview
Generic RAG flattens structured files (government forms, multi-column PDFs, nested tables) into sequential text, destroying spatial context. LP-DIP keeps 2D word bounding-box geometry through the embedding so the system can answer questions that depend on where information sits on the page, not just which words are near each other.
## Architecture (two lanes, one spine)
Lane 1: web pages -> web-to-llm markdown. Lane 2: layout-rich documents -> text tokens + bounding boxes -> spatial-coordinate embedding. Both lanes feed rate-budgeted embedding generation (TPM/RPM limits with backoff). Embedded facts are written incrementally into an entity-relation knowledge graph. Queries run hybrid graph+vector retrieval, merging semantic vector matches with keyword-indexed graph traversal into a single context subgraph.
## Components
1. web-to-llm-format-conversion — URL -> LLMOptimizedMarkdown. Source: modelcontextprotocol/servers.
2. spatial-coordinate text embedding — TextTokens + BoundingBoxes -> SpatialTextEmbeddings. Source: microsoft/unilm (LayoutLM).
3. rate-budgeted-embedding-generation — List<ChunkText> -> List<Embedding>. Source: Eslzzyl/docs-mcp-rs.
4. knowledge-graph-persistent-memory-write — EntityRelationFact -> UpdatedKnowledgeGraph. Source: modelcontextprotocol/servers.
5. hybrid-graph-vector-retrieval — (Keywords, VectorQuery) -> ContextSubgraph. Source: HKUDS/LightRAG.
## Build
A Python reference (pipeline.py) implements each atom as a class and a LayoutPreservingDocIntelPipeline orchestrator with ingest_web_source, ingest_layout_document, and query methods over a networkx graph.
## Acceptance Check
Ingest a web source and a two-token invoice ("TotalDue:" beside "$5,000") with side-by-side bounding boxes; assert the tokens and their layout-adjacency edge land in the graph and that hybrid retrieval returns them.
## Honest status
Architecture and atom boundaries are sound, but this needs more before production than a pure-wiring scaffold. Caller must supply a real PDF/OCR parser (PyMuPDF/Tesseract) for token bounding boxes and a real entity-relation extractor. Two toy stand-ins in the reference build: coordinates are injected additively into the first four embedding dims (real LayoutLM uses learned 2D positional embeddings), and KG edges link each token to the next in reading order rather than by true geometric adjacency. Star atom: spatial-coordinate text embedding.Generated with Gerolamo — competitive technical intelligence
gerolamo.org