Skip to main content

Structure-Aware Document Chunking Algorithm for Retrieval-Augmented Generation Systems (SDCA)

Overview

This repository implements SDCA (Structure-Aware Document Chunking Algorithm), an M.Tech research project addressing chunk boundary degradation in PDF-based Retrieval-Augmented Generation (RAG) pipelines.

Standard naive chunking strategies (fixed-size windowing, simple character recursive splitting) often cleave paragraphs mid-sentence, ignore section hierarchies, and fragment semantic context, leading to degraded retrieval precision. SDCA provides a deterministic, layout-aware chunking pipeline that leverages PDF typography and document structure extracted via PyMuPDF.


5-Phase Implementation Plan

  1. Phase 1: PDF Extraction Foundation (COMPLETED)
    • Extract structured text blocks, bounding boxes, font sizes, flags, and page metadata via PyMuPDF (fitz).
  2. Phase 2: Baseline Chunking (COMPLETED)
    • Implement three standard RAG chunking baselines: Fixed-Size, Recursive, and Sentence-based Chunking.
  3. Phase 3: SDCA Proposed Algorithm (COMPLETED)
    • Implement the deterministic structure-aware chunking algorithm targeting ~400 tokens (range 200–600 tokens) with heading detection, paragraph preservation, and sentence-bounded splitting.
  4. Phase 4: Retrieval and Controlled Experiments (COMPLETED)
    • Generate embeddings using Sentence Transformers (all-MiniLM-L6-v2) and build FAISS vector indexes (IndexFlatIP) under strict Ceteris Paribus conditions.
  5. Phase 5 & 5.1: Evaluation Dashboard & Interactive Research Laboratory (COMPLETED)
    • Interactive viva research laboratory for visual inspection, multi-algorithm side-by-side chunking, multi-strategy live FAISS retrieval, and frozen official benchmark presentation.
  6. Phase V2: SDCA V2 Hierarchical Evolution & Controlled 5-Way Benchmark (COMPLETED)
    • Hierarchical section context (section_path), heading-content binding, structure-aware retrieval text (chunk.retrieval_text), small-chunk merging, and 5-strategy comparative benchmark.

Running the SDCA Research Laboratory

Launch the interactive Streamlit research laboratory:

# Direct run via virtual environment
.venv/bin/streamlit run src/app/streamlit_app.py

The application opens at http://localhost:8501 featuring 5 dedicated research views:

  1. Overview: Executive product landing page with capability cards and aggregate dataset metrics.
  2. SDCA Explorer: Deep visual inspection of both SDCA V1 and SDCA V2 (modal body font inference, hierarchical breadcrumbs, heading binding, and structure-aware retrieval text).
  3. Algorithm Comparison: Side-by-side multi-algorithm execution (Fixed, Recursive, Sentence, SDCA V1, SDCA V2) on the same PDF with token statistics, distribution charts, and sequential position chunk inspection.
  4. Live Retrieval Lab: Multi-algorithm semantic search under identical embedding and FAISS conditions with side-by-side cosine similarity scoring and vector text inspection.
  5. Official Benchmark: Tabbed evaluation featuring the full 5-way V2 benchmark, the frozen Phase 4 baseline, and direct head-to-head SDCA V1 vs SDCA V2 evolution analysis.
  6. About SDCA: Algorithmic pipeline, typography heuristics, and viva examination defense notes.

Running the Automated Test Suite

Execute the full 100-test automated test suite across all project phases:

.venv/bin/pytest -v tests/

Expected result: 100 passed, 0 failures (100% pass rate).


Research Controls (Ceteris Paribus)

To ensure scientific validity, all retrieval benchmarks hold constant:

  • Document corpus (3 landmark academic papers: Attention, RAG, BERT; 50 pages total)
  • Benchmark query set & ground truth (15 verified technical queries)
  • Embedding model (sentence-transformers/all-MiniLM-L6-v2, 384 dimensions)
  • Subword tokenizer (injected model tokenizer across all 4 chunkers)
  • Vector index algorithm (FAISS IndexFlatIP)
  • Similarity metric (Exact Cosine Similarity via unit $L_2$-normalized inner product)
  • Retrieval depth ($K = 5$)
  • Evaluation metrics (Precision@5, Recall@5, Hit Rate@5, MRR, NDCG@5)

The only independent variable is the chunking algorithm.


Technical Documentation


Governance Documents

  • RULES.md: Research rules, algorithmic boundaries, and coding standards.
  • PROJECT_STATE.md: Current phase, deliverable tracker, and experiment states.
  • DECISIONS.md: Architectural Decision Records (ADRs).
  • ERROR_CHANGE_LOG.md: Historical log of errors, refactorings, and changes.

Metadata

Release files for sdca-rag 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sdca-rag 0.1.0
File Size Uploaded Provenance Actions
sdca_rag-0.1.0.tar.gz 76.6 kB Without provenance Details for sdca_rag-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sdca-rag 0.1.0
File Interpreter ABI Platform Actions
sdca_rag-0.1.0-py3-none-any.whl Python 3 none any Details for sdca_rag-0.1.0-py3-none-any.whl

Total release size: 150.7 kB

Release files / sdca_rag-0.1.0.tar.gz

Download URL sdca_rag-0.1.0.tar.gz
Size 76.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ef2b8328e579f3ab78be46388c6dca0eac7f9432b12f13da450580118f4aa1a2
BLAKE2b-256 checksum
How to use checksums
9464ccc2309e1ac97538e383f653b56c208fa8a389e244471b1be8ee0c4a1199
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / sdca_rag-0.1.0-py3-none-any.whl

Download URL sdca_rag-0.1.0-py3-none-any.whl
Size 74.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ecec3ed8113317404ba3e43aa2de7ff4686d4991d03bc6076349045edfadc4b
BLAKE2b-256 checksum
How to use checksums
1566286bd38efd35b82d007b936fb9458689d56f582e5cb441282e981cef0d0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for sdca-rag 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page