Production-grade Fact Knowledge Layer built for the Superjoin Engineering Assignment. This system ingests arbitrary corporate filings and macroeconomic PDFs, extracts grounded facts with strict page and quote provenance, models multi-dimensional context bounding boxes, and deterministically reconciles cross-document relationships using Allen's 1D Interval Algebra with zero domain hardcoding.
π Demo Video Link: Click here to watch the full video walkthrough (3:00 min) Demonstrates live PDF ingestion, cross-document reconciliation, all 4 mandatory cases, and telemetry within the 3-minute limit.
Figure 1: Cross-Document Evidence Inspector displaying Grounded Facts & 1D Interval Projections.
Figure 2: Case 4 Anomaly Circuit Breaker isolating unanchored metrics and quote hallucinations.
Figure 3: Live System Telemetry, O(NK) partition scale metrics, and inverted SQLite fact directory.*
Instead of flattening facts into simple text strings or graph nodes, every fact is modeled as an N-Dimensional Hyper-Tuple:
- Temporal Interval: Bounded by ISO-8601
[start_date, end_date],granularity(EXACT_DATE,MONTH,QUARTER,YEAR,PERPETUAL,UNKNOWN), andraw_expression. - Scope: Explicit qualification boundary (e.g.,
GLOBAL,CONSOLIDATED,INDIA,EXPRESS_PARCEL). - Provenance: Atomic grounding tracking
source_doc_name,doc_hash,page_number,verbatim_quote, andprovenance_modality(TEXTvsVISUAL_CHART).
Relationships across documents are resolved deterministically without relying on probabilistic LLM judgements. The reconciler evaluates the 13 interval relations defined by James F. Allen:
| Interval Relation | Mathematical Condition | Engine Classification |
|---|---|---|
| Equals | Identical Time Horizon | |
| Disjoint (Before / After) | Case 3: Context-Reconciled (Temporal Progression) | |
| Overlaps / Meets | Intersecting Fiscal Period | |
| Contains / During | Nested Financial Scope |
When comparing two facts
-
Case 1 (Corroboration): Equivalent canonical values (
$V_A = V_B$ ), matching units, matching scope, and overlapping/equal temporal bounds. -
Case 2 (Genuine Contradiction): Conflicting values (
$V_A \neq V_B$ ), identical units, matching scope, and overlapping/equal temporal bounds. -
Case 3 (Context-Reconciled): Differing values (
$V_A \neq V_B$ ) explained by disjoint temporal intervals ($E_A < S_B$ ), unit scale variance ($\text{INR}$ vs$\text{USD}$ ), or scope variance ($\text{CONSOLIDATED}$ vs$\text{STANDALONE}$ ). - Case 4 (Quarantine): Isolated prior to reconciliation due to unanchored temporal bounds or quote hallucinations.
To generalize across financial prospectuses, annual reports, and macro datasets without regex dictionary maintenance:
-
Numeric Scale Normalization: Converts Indian numerical scales (
$\text{Crores}, \text{Lakhs}$ ) and international scales ($\text{Millions}, \text{Billions}$ ) into canonical floating-point numbers. -
Hybrid Similarity Metric: Merges 50% Token Jaccard overlap with 50% Character Levenshtein ratio (
SequenceMatcher) to compare attributes across corporate abbreviations (e.g."Limited"vs"Ltd").
google-genaiSDK (gemini-2.5-flash): Structured JSON fact extraction with Pydantic schema validation and multimodal image part attachment.PyMuPDF(fitz): Fast, layout-aware PDF page text extraction and 150 DPI page rendering.scikit-learn: Multi-class classification evaluation metrics (Precision, Recall, F1, Macro-F1).Streamlit: High-density engineering dashboard with custom Linear/Vercel-style CSS.
- Source Filings:
01-delhivery-prospectus-2022-excerpt.pdf(Pg 14) vs02-delhivery-annual-report-fy24-excerpt.pdf(Pg 2). - Extracted Facts:
- Fact A: Entity=
Delhivery Limited, Attribute=Incorporation Date, Raw="June 22, 2011", Canonical="2011-06-22". - Fact B: Entity=
Delhivery Limited, Attribute=Incorporation Date, Raw="22nd June 2011", Canonical="2011-06-22".
- Fact A: Entity=
- System Reasoning: Both date expressions normalize to ISO
2011-06-22with aPERPETUALtime horizon. Values, scope (GLOBAL), and units match exactly. - Classification:
CASE_1_CORROBORATION(Verified Equivalent).
- Source Filings: Prospectus excerpt (Pg 20) vs FY24 Annual Report excerpt (Pg 40).
-
Extracted Facts:
- Fact A: FY22 Total Workforce =
66,000 employees(Canonical:66000.0, Scope:CONSOLIDATED, Window:FY22). - Fact B: FY22 Total Workforce =
93,000 personnel(Canonical:93000.0, Scope:CONSOLIDATED, Window:FY22).
- Fact A: FY22 Total Workforce =
-
System Reasoning: Both facts share identical fiscal intervals (
2021-04-01to2022-03-31), scope (CONSOLIDATED), and unit (COUNT), but canonical values conflict ($66,000 \neq 93,000$ ). -
Classification:
CASE_2_GENUINE_CONTRADICTION(True Audited Conflict).
- Source Filings: Prospectus excerpt (Pg 35) vs FY24 Annual Report excerpt (Pg 10).
-
Extracted Facts:
- Fact A: Revenue from Services =
βΉ7,241 Crores(Canonical:7.241e10, Window:FY22). - Fact B: Revenue from Services =
βΉ8,142 Crores(Canonical:8.142e10, Window:FY24).
- Fact A: Revenue from Services =
-
System Reasoning: Allen's Interval Algebra evaluates temporal bounds:
$$\text{Interval}(\text{FY22}) = [2021\text{-}04\text{-}01, 2022\text{-}03\text{-}31] \quad \text{DISJOINT} \quad \text{Interval}(\text{FY24}) = [2023\text{-}04\text{-}01, 2024\text{-}03\text{-}31]$$ The value gap is resolved as legitimate business growth over time. -
Classification:
CASE_3_CONTEXT_RECONCILED(Disjoint Temporal Evolution).
- Scenario: Unanchored metric (
"Operating 86 active gateways"without time context) or LLM quote hallucination. - System Reasoning:
FactIntegrityGatechecks quote grounding and temporal bounds prior to storage. FlagsDEGENERATE_TEMPORAL_BOUNDorUNVERIFIED_SOURCE_QUOTE. - Classification:
CASE_4_QUARANTINED(Anomaly Blocked).
| Metric / Dimension | Empirical Result | Target Ceiling | Status |
|---|---|---|---|
| Peak Heap RAM (Streaming) | 12.94 MB | PASSED (91% Under Target) | |
| Incremental Ingestion Latency | 2.20 ms | PASSED | |
| Relative Scaling Error | 0.000000 | PERFECT PRECISION | |
| Reconciliation Macro-F1 | 1.0000 | PERFECT RECALL | |
| Quarantine F1-Score | 1.0000 | PERFECT ANOMALY BLOCK |
===========================================================================
EMPIRICAL EVALUATION SUITE: NLI RECONCILIATION & INTEGRITY GATE
===========================================================================
>>> 1. MULTI-CLASS RECONCILIATION BENCHMARK (CASES 1-3):
β’ CASE_1_CORROBORATION | Precision: 1.00 | Recall: 1.00 | F1: 1.00
β’ CASE_2_GENUINE_CONTRADICTION | Precision: 1.00 | Recall: 1.00 | F1: 1.00
β’ CASE_3_CONTEXT_RECONCILED | Precision: 1.00 | Recall: 1.00 | F1: 1.00
>> RECONCILIATION MACRO-F1: 1.0000
>>> 2. CIRCUIT BREAKER & QUARANTINE BENCHMARK (CASE 4):
β’ Quarantine Precision: 1.00
β’ Quarantine Recall: 1.00
β’ Quarantine F1-Score: 1.00
===========================================================================
FINAL AUDIT VERDICT: Macro-F1 = 1.00 | Quarantine-F1 = 1.00
===========================================================================
.
βββ app.py # Streamlit interactive audit & inspection dashboard
βββ fact_layer/
β βββ core/
β βββ models.py # GroundedFact hyper-tuple data contracts (s, p, o, Ο, Ο, ΞΌ)
β βββ parser.py # Memory-bounded streaming layout parser (PyMuPDF)
β βββ extractor.py # Dual-track LLM & opportunistic vision extractor
β βββ normalizer.py # Zero-hardcoding hybrid scale & entity normalizer
β βββ reconciler.py # Allen's 1D interval algebra deterministic engine
β βββ validator.py # Fact integrity gate & Case 4 anomaly circuit breaker
β βββ storage.py # Partitioned inverted SQLite store
βββ tests/
β βββ test_backend_rigorous.py # Complete system stress & memory benchmark suite
β βββ evaluate_nli_metrics.py # Automated Scikit-Learn NLI classification evaluator
βββ starter-datasets/ # Evaluation PDFs (Delhivery filings & India Macro)
βββ requirements.txt
βββ README.md
Building a production-ready Fact Knowledge Layer requires honest architectural trade-offs. Here is what we attempted, where naive approaches failed, and how we engineered solutions:
- Initial Attempt: Initially, we attempted to run full-page multimodal vision parsing (
gemini-2.5-flashimage inputs) across every PDF page to capture visual bar charts and plots. - Why It Failed: Memory heap spiked to 310+ MB RAM, and per-page latency jumped from 150ms to 8.2 seconds, violating the assignment's performance ceiling.
- Architectural Solution: Designed an Opportunistic Dual-Track Pipeline:
- Track A (Fast Path - PyMuPDF): 90%+ of standard digital text pages stream through PyMuPDF in milliseconds at 12.94 MB peak RAM.
- Track B (Vision Fallback): Activates 150 DPI image rendering ONLY when a page contains embedded raster images, vector graphic drawings (
page.get_drawings() > 4), or unanchored chart metrics.
- Initial Attempt: Tried pure word-level Jaccard similarity to match corporate entities and attributes.
-
Why It Failed: Failed on real-world filing variations like
"Delhivery Limited"vs"Delhivery Ltd", or"Revenue from Operations"vs"Op Revenue". -
Architectural Solution: Implemented a hybrid similarity metric in
GeneralizedNormalizer:$$\text{Similarity}(S_1, S_2) = 0.5 \times \text{Jaccard}(S_1, S_2) + 0.5 \times \text{LevenshteinRatio}(S_1, S_2)$$
- Initial Attempt: Tried string matching on fiscal period tags like
"FY22"and"2022". - Why It Failed: Could not distinguish between overlapping fiscal years (
FY22:2021-04-01to2022-03-31) and calendar years (2022:2022-01-01to2022-12-31), causing false contradiction alerts. - Architectural Solution: Explicitly map all temporal expressions into formal
[start_date, end_date]interval bounds, then evaluate Allen's 13 interval operators.
- Multi-Page Spanning Tables: Tables breaking across page boundaries currently process as separate chunks. A production extension would maintain a multi-page table buffer state.
-
Dynamic FX Currency Rates: Currently normalizes scale (
$\text{Crores} \rightarrow \text{Units}$ ), but currency conversions ($\text{USD} \leftrightarrow \text{INR}$ ) use static exchange rates rather than point-in-time spot FX rates.
While the system achieves 1.00 Macro-F1 on evaluation benchmarks, real-world edge cases present operational trade-offs:
- Multi-Page Spanning Tables: Tables breaking across page boundaries currently process as separate chunks. A production extension would maintain a multi-page table buffer state across document stream boundaries.
-
Dynamic FX Currency Conversion: The normalizer currently standardizes numeric scales (
$\text{Crores} \rightarrow \text{Units}$ ,$\text{Millions} \rightarrow \text{Units}$ ), but cross-currency comparisons ($\text{USD} \leftrightarrow \text{INR}$ ) rely on static exchange rates rather than point-in-time spot FX rates. - Complex Multi-Hop Inferential Graphs: The reconciler operates on pairwise fact attribute comparisons ($O(N_{\text{new}} \times K_{\text{match}})$). Higher-order multi-hop transitive inferences across 3+ documents are deferred to future graph expansion.
- Large PDF Streaming: Memory-bounded page streaming via PyMuPDF processes 100+ page filings at 12.94 MB peak RAM (limit: 150 MB).
- Multi-PDF Index Density: SQLite inverted index supporting multi-filing ingestion with zero cross-document data leakage.
- Dynamic Schema Evolution: 100% domain-agnostic pipeline extracts and reconciles facts across corporate prospectuses and macroeconomic reports (
starter-datasets/india-macroeconomy/) with zero hardcoded domain rules. - Incremental Ingestion: Partitioned fact store ingests new document batches in 2.20 ms without rebuilding prior knowledge. Deduplicates re-uploaded files via binary SHA-256 document hashing.
Ensure Python 3.12+ is installed.
Clone the repository and install dependencies:
git clone https://github.com/AdityaPanda0506/SuperJoin.git
cd SuperJoin
pip install -r requirements.txtSet your Gemini API key (optional; system runs in simulation fallback mode if omitted):
# Windows PowerShell
$env:GEMINI_API_KEY="your_api_key_here"
# Linux / macOS
export GEMINI_API_KEY="your_api_key_here"Run explicit test execution commands proving generalization across distinct domains:
# 1. Run empirical NLI metric evaluation (Macro-F1 & Quarantine-F1):
python tests/evaluate_nli_metrics.py
# 2. Verify zero-hardcoding generalization across distinct domains:
# Runs rigorous backend suite against Corporate Logistics filings & Macroeconomic PDFs:
python -m pytest tests/test_backend_rigorous.py -v
# 3. Launch the interactive inspection dashboard:
streamlit run app.pyOpen http://localhost:8501 in your browser to test drag-and-drop PDF ingestion, inspect side-by-side evidence cards, and test the Case 4 circuit breaker.
- Credential & Privacy Compliance: All API credentials and environment secrets are kept strictly out of the repository. Zero hardcoded keys exist in source code or commit history.
- Stand-alone Simulation & Off-line Resilience: The system features an automated fallback parser and extractor, ensuring full functionality and interactive UI demonstration even without active network access or API credentials.
- Continuous Integration Guarantee: Every commit is verified against multi-version Python matrices (
3.11,3.12),rufflinting standards, and automated pytest execution via GitHub Actions (.github/workflows/ci.yml).

