Feat: Implement Vector-Semantic PDF Alignment to replace brittle geometric mapping#393
Open
NEHAJAKATE wants to merge 1 commit intofireform-core:mainfrom
Open
Feat: Implement Vector-Semantic PDF Alignment to replace brittle geometric mapping#393NEHAJAKATE wants to merge 1 commit intofireform-core:mainfrom
NEHAJAKATE wants to merge 1 commit intofireform-core:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, the document generation logic in
src/filler.pyrelies heavily on geometric Y/X coordinate sorting or exact matching with internal PDF/T(Title) metadata. This creates a brittle dependency. Government agency PDFs frequently contain malformed or auto-generated widget names (e.g.,TextField_42instead ofIncident_Address). If a new agency uploads a PDF with a slightly different visual layout or generic metadata, the current coordinate mapping will silently inject the wrong JSON data into the wrong legal boxes.Changes Proposed
This PR introduces a Vector-Semantic PDF Alignment engine to mathematically align extracted JSON data with the visual PDF fields.
Visual Context Extraction: Integrated
PyMuPDF (fitz)to scan the Document Object Model (DOM) and extract the visible printed text located immediately adjacent to interactive PDF widgets.Quantized Embeddings:** Integrated the edge-optimized
<100MBall-MiniLM-L6-v2embedding model to generate vectors for both the JSON keys and the extracted visual text.Cosine Similarity Mapping:** Replaced rigid coordinate mapping with a mathematical threshold (e.g.,
similarity > 0.75), allowing the system to logically pair extracted data with the correct PDF box regardless of internal metadata names.Impact
Zero-Config Onboarding:** Eliminates the need for custom YAML mapping scripts for every new agency.
Fault Tolerance:** Grants FireForm immunity to lazily formatted or heterogenous government PDFs, scaling the platform toward a true Digital Public Good.
(Note: I am submitting this architectural exploration as part of my active research and contribution for GSoC 2026. I would love the maintainers' feedback on this vector-based approach!)