rag-ingestion-preflight 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. rag_ingestion_preflight-0.1.0/CHANGELOG.md +95 -0
  2. rag_ingestion_preflight-0.1.0/CONTRIBUTING.md +22 -0
  3. rag_ingestion_preflight-0.1.0/LICENSE +21 -0
  4. rag_ingestion_preflight-0.1.0/MANIFEST.in +6 -0
  5. rag_ingestion_preflight-0.1.0/PKG-INFO +461 -0
  6. rag_ingestion_preflight-0.1.0/README.md +422 -0
  7. rag_ingestion_preflight-0.1.0/docs/adoption.md +114 -0
  8. rag_ingestion_preflight-0.1.0/docs/api.md +279 -0
  9. rag_ingestion_preflight-0.1.0/docs/check-to-pipeline.md +38 -0
  10. rag_ingestion_preflight-0.1.0/docs/compatibility.md +33 -0
  11. rag_ingestion_preflight-0.1.0/docs/corpus-results.json +68 -0
  12. rag_ingestion_preflight-0.1.0/docs/existing-index.md +96 -0
  13. rag_ingestion_preflight-0.1.0/docs/export-recipes.md +205 -0
  14. rag_ingestion_preflight-0.1.0/docs/failures.md +119 -0
  15. rag_ingestion_preflight-0.1.0/docs/integration-validation.md +72 -0
  16. rag_ingestion_preflight-0.1.0/docs/messy-documents.md +31 -0
  17. rag_ingestion_preflight-0.1.0/docs/production.md +290 -0
  18. rag_ingestion_preflight-0.1.0/docs/quickstart.md +115 -0
  19. rag_ingestion_preflight-0.1.0/docs/validation.md +317 -0
  20. rag_ingestion_preflight-0.1.0/examples/chunks.json +5 -0
  21. rag_ingestion_preflight-0.1.0/examples/cumulative_deletion.py +23 -0
  22. rag_ingestion_preflight-0.1.0/examples/embeddings.json +1 -0
  23. rag_ingestion_preflight-0.1.0/examples/first_run.py +14 -0
  24. rag_ingestion_preflight-0.1.0/examples/indexed_reingestion.py +26 -0
  25. rag_ingestion_preflight-0.1.0/examples/ingestion.json +52 -0
  26. rag_ingestion_preflight-0.1.0/examples/langgraph_gate.py +53 -0
  27. rag_ingestion_preflight-0.1.0/examples/quickstart.py +14 -0
  28. rag_ingestion_preflight-0.1.0/examples/safe_reingestion.py +60 -0
  29. rag_ingestion_preflight-0.1.0/examples/source_to_ledger.py +28 -0
  30. rag_ingestion_preflight-0.1.0/pyproject.toml +55 -0
  31. rag_ingestion_preflight-0.1.0/scripts/corpus_trial.py +143 -0
  32. rag_ingestion_preflight-0.1.0/scripts/messy_document_acceptance.py +181 -0
  33. rag_ingestion_preflight-0.1.0/setup.cfg +4 -0
  34. rag_ingestion_preflight-0.1.0/src/rag_ingestion_preflight.egg-info/PKG-INFO +461 -0
  35. rag_ingestion_preflight-0.1.0/src/rag_ingestion_preflight.egg-info/SOURCES.txt +70 -0
  36. rag_ingestion_preflight-0.1.0/src/rag_ingestion_preflight.egg-info/dependency_links.txt +1 -0
  37. rag_ingestion_preflight-0.1.0/src/rag_ingestion_preflight.egg-info/entry_points.txt +2 -0
  38. rag_ingestion_preflight-0.1.0/src/rag_ingestion_preflight.egg-info/requires.txt +17 -0
  39. rag_ingestion_preflight-0.1.0/src/rag_ingestion_preflight.egg-info/top_level.txt +1 -0
  40. rag_ingestion_preflight-0.1.0/src/rag_preflight/__init__.py +40 -0
  41. rag_ingestion_preflight-0.1.0/src/rag_preflight/__main__.py +4 -0
  42. rag_ingestion_preflight-0.1.0/src/rag_preflight/adapters.py +60 -0
  43. rag_ingestion_preflight-0.1.0/src/rag_preflight/baseline.py +110 -0
  44. rag_ingestion_preflight-0.1.0/src/rag_preflight/cli.py +225 -0
  45. rag_ingestion_preflight-0.1.0/src/rag_preflight/core.py +220 -0
  46. rag_ingestion_preflight-0.1.0/src/rag_preflight/cost.py +88 -0
  47. rag_ingestion_preflight-0.1.0/src/rag_preflight/evidence.py +52 -0
  48. rag_ingestion_preflight-0.1.0/src/rag_preflight/existing.py +207 -0
  49. rag_ingestion_preflight-0.1.0/src/rag_preflight/extract.py +169 -0
  50. rag_ingestion_preflight-0.1.0/src/rag_preflight/folder.py +306 -0
  51. rag_ingestion_preflight-0.1.0/src/rag_preflight/ingestion.py +506 -0
  52. rag_ingestion_preflight-0.1.0/src/rag_preflight/py.typed +0 -0
  53. rag_ingestion_preflight-0.1.0/src/rag_preflight/quality.py +82 -0
  54. rag_ingestion_preflight-0.1.0/src/rag_preflight/reconcile.py +71 -0
  55. rag_ingestion_preflight-0.1.0/src/rag_preflight/reingestion.py +360 -0
  56. rag_ingestion_preflight-0.1.0/src/rag_preflight/runs.py +72 -0
  57. rag_ingestion_preflight-0.1.0/src/rag_preflight/storage.py +323 -0
  58. rag_ingestion_preflight-0.1.0/tests/test_adoption.py +201 -0
  59. rag_ingestion_preflight-0.1.0/tests/test_audit.py +116 -0
  60. rag_ingestion_preflight-0.1.0/tests/test_cli_discovery.py +67 -0
  61. rag_ingestion_preflight-0.1.0/tests/test_export_recipes.py +96 -0
  62. rag_ingestion_preflight-0.1.0/tests/test_folder_check.py +216 -0
  63. rag_ingestion_preflight-0.1.0/tests/test_frameworks.py +30 -0
  64. rag_ingestion_preflight-0.1.0/tests/test_history.py +145 -0
  65. rag_ingestion_preflight-0.1.0/tests/test_ingestion.py +174 -0
  66. rag_ingestion_preflight-0.1.0/tests/test_ledger_inspection.py +114 -0
  67. rag_ingestion_preflight-0.1.0/tests/test_messy_documents.py +43 -0
  68. rag_ingestion_preflight-0.1.0/tests/test_reingestion.py +214 -0
  69. rag_ingestion_preflight-0.1.0/tests/test_review_fixes.py +263 -0
  70. rag_ingestion_preflight-0.1.0/tests/test_taxonomy.py +58 -0
  71. rag_ingestion_preflight-0.1.0/tests/test_update.py +383 -0
  72. rag_ingestion_preflight-0.1.0/tests/test_workflow.py +93 -0
@@ -0,0 +1,95 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ ### Current-source adoption update
6
+
7
+ - Add Linux/Windows messy-document acceptance using generated real PDF, DOCX,
8
+ PPTX, HTML, and text edge cases; classify encrypted PDFs explicitly.
9
+ - Make the text footer list only checks actually left unverified; with
10
+ `--expected`, expected-file absence is no longer described as unchecked.
11
+ - Declare public finding-code/default-policy compatibility and stored-format
12
+ migration rules; newer snapshot versions now fail with their version number.
13
+ - Classify `check` setup/incomplete outcomes separately from audited failures;
14
+ explain common read errors in plain language without hiding diagnostic types.
15
+ - Add independent minimum-file inventory to `check --expected` and Python API;
16
+ show excluded files and provide a path to guarded integration.
17
+ - Added read-only `check_source_folder()` and `rag-preflight check DIR`, with
18
+ current file/page/slide inventory, bounded plain-language examples and explicit
19
+ unverified historical index coverage.
20
+ - Added static UTF-8 HTML/text readers and optional Word/PowerPoint receipt
21
+ subsets; empty PDF pages with image objects get a heuristic warning.
22
+ - Kept core runtime dependencies empty.
23
+
24
+ ### CLI and operator updates
25
+
26
+ - Exit 2 on missing CLI arguments while explicit help remains exit 0.
27
+ - Add paginated read-only export recipes and qualify deployment responsibility/evidence.
28
+
29
+ - List all workflows in top-level CLI help, add explicit chunks command, and diagnose
30
+ unknown bare commands while retaining legacy JSON/JSONL file invocation.
31
+
32
+ ### Operator review fixes
33
+
34
+ - Adjust young-ledger summary windows to exclude initial setup/population when
35
+ needed for a nonzero comparison; expose actual window/baseline metadata.
36
+ - Preserve null ratios for genuine zero baselines and retain later retirement/re-population.
37
+ - Add read-only ledger summary/history JSON CLI and optional read_only store access.
38
+ - Reject missing files and legacy schemas during inspection without creating/migrating.
39
+ - Attribute independent Python 3.10.12 verification of the preceding 162-test build.
40
+
41
+ ### Final review fixes
42
+
43
+ - Make Python AuditReport JSON compact by default; detailed=True retains all findings.
44
+ - Add transactional SQLite commit history and identity-free rolling deletion summaries,
45
+ separating gross ID removals, net shrinkage and ordinary/scoped/retired removals.
46
+ - Migrate SQLite inventory schema 1 to 2 atomically; report prior history as unverified.
47
+ Portable JSON schema 1 remains unchanged; history adds visibility, not a hard gate.
48
+ - Enforce finding taxonomy coverage with source extraction tests and legacy unit aliases.
49
+ - Add an existing-index evidence ladder and separate real-integration validation contract.
50
+ - Record user-reported independent Python 3.10.12 verification with attribution.
51
+
52
+ ### Scale and evidence update
53
+
54
+ - Add exact code/severity aggregation, bounded samples, compact CLI JSON/text and metrics.
55
+ - Add full-corpus 15% deletion guards with 25% per-document defaults, optional absolute
56
+ budgets, full-inventory SQL counts and recorded effective policies.
57
+ - Add schema-2 strict/text warning baselines; schema-1 files retain strict semantics.
58
+ - Support canonical multi-unit ordinal keys while preserving single-unit outputs.
59
+ - Add read-only source-directory / existing-index JSONL API and CLI audits.
60
+ - Add explicit token-evidence embedding cost estimates and bounded run receipts.
61
+ - Enforce supplied namespace consistency and optional required metadata policy.
62
+ - Add regression coverage, API/migration guides and a complete finding taxonomy.
63
+
64
+ ### Earlier prepublication review fixes
65
+
66
+ - Add independent plan-local chunk/document
67
+ deletion budgets (now optional, alongside corpus-relative protection); deterministic per-document-first errors shared by both APIs.
68
+ - Add whole-ledger ID enumeration, streamed chunk IDs and verification.
69
+ - Add source-driven PDF/generic receipt producers and unit-scoped ordinal keys.
70
+ - Add dependency-free LangChain/LlamaIndex text converters and a LangGraph gate example.
71
+ - Add chunk length statistics, configurable short/low-distinctiveness warnings,
72
+ and conservative unit-yield warnings with explicit skipped checks and limitations.
73
+ - Add bounded-report, disk-backed ID reconciliation and warning-only baseline files.
74
+ - Recommend SQLite operational state and JSON interchange; document evidence,
75
+ ID-only apply limits, source requirements and framework cleanup ownership.
76
+
77
+
78
+ All changes above are included in the initial 0.1.0 release.
79
+
80
+ - Added chunk validation, source-unit completeness, explicit blank/unknown coverage,
81
+ and compatibility aliases for existing PDF page manifests.
82
+ - Fixed named retirement to preserve other documents' deletion guards.
83
+ - Added scoped shrink allowances without relaxing unrelated document limits.
84
+ - Fixed safe import of the command-line entry module.
85
+ - Added duplicate-vector/norm warnings, optional NumPy backend, and plan-linked
86
+ checks of declared embedding model, pipeline and exact input fingerprint.
87
+ - Added document-indexed SQLite state, touched-scope planning, stale-commit checks
88
+ and transactional ledger updates. Portable JSON snapshot schema 1 remains supported.
89
+ - Added typed package marker, checked annotations, author/keyword/classifier metadata,
90
+ version-independent CI wheel selection, and separated downloadable build artifacts.
91
+ - Added regression tests and a reproducible trial using an RFC PDF and pandas README.
92
+
93
+ Project metadata points to the repository, documentation, issue tracker and this
94
+ changelog. Publication uses the tag-gated Trusted Publishing workflow documented
95
+ in the repository release checklist.
@@ -0,0 +1,22 @@
1
+ # Contributing
2
+
3
+ Install with `python -m pip install -e '.[dev,numpy]'` and run:
4
+
5
+ ```bash
6
+ python -m unittest discover -s tests -v
7
+ python -m mypy src/rag_preflight
8
+ python -m build
9
+ ```
10
+
11
+ Use synthetic or public test data only. For a bug, provide a minimal input, package
12
+ and Python version, expected/actual report, and any source/state schema involved.
13
+ Add a regression test for changes to deletion guards, source coverage, identity,
14
+ provenance or state updates. Keep core imports independent of third-party services.
15
+ Changes to hashes, schemas and state semantics require explicit compatibility review.
16
+
17
+ Build output belongs in ignored dist/ locally and release attachments when published,
18
+ not in tracked source. The delivered ZIP separates source from downloadable artifacts.
19
+
20
+ Before publishing: verify the PyPI name, add real repository/docs/issue URLs when
21
+ available, review author metadata, run the supported-platform CI, and validate the
22
+ actual parser/provider/vector-store integration. No release is published automatically.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RAG Preflight contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include LICENSE README.md CHANGELOG.md CONTRIBUTING.md
2
+ recursive-include docs *.md *.json
3
+ recursive-include examples *.py *.json
4
+ recursive-include tests *.py
5
+ recursive-include scripts *.py
6
+ include src/rag_preflight/py.typed
@@ -0,0 +1,461 @@
1
+ Metadata-Version: 2.4
2
+ Name: rag-ingestion-preflight
3
+ Version: 0.1.0
4
+ Summary: Validate RAG source completeness, embeddings, and safe document re-ingestion
5
+ Author: Shyam Sundar Domakonda
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/ShyamSundar29/rag-preflight
8
+ Project-URL: Documentation, https://github.com/ShyamSundar29/rag-preflight/tree/main/rag-preflight/docs
9
+ Project-URL: Issues, https://github.com/ShyamSundar29/rag-preflight/issues
10
+ Project-URL: Changelog, https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/CHANGELOG.md
11
+ Keywords: rag,ingestion,embeddings,validation,vector-database
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: numpy
27
+ Requires-Dist: numpy>=1.24; extra == "numpy"
28
+ Provides-Extra: trial
29
+ Requires-Dist: pypdf>=5; extra == "trial"
30
+ Provides-Extra: pdf
31
+ Requires-Dist: pypdf>=5; extra == "pdf"
32
+ Provides-Extra: office
33
+ Requires-Dist: python-docx>=1.2; extra == "office"
34
+ Requires-Dist: python-pptx>=1.0; extra == "office"
35
+ Provides-Extra: dev
36
+ Requires-Dist: build>=1; extra == "dev"
37
+ Requires-Dist: mypy>=1.10; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # RAG Preflight
41
+
42
+ Catch missing documents and pages, and block unsafe re-ingestion before your
43
+ application writes to its vector store. **Version 0.1.0.** Python 3.10+. MIT license.
44
+ The core has no third-party runtime dependencies and makes no network calls.
45
+
46
+ RAG Preflight validates source coverage, chunk integrity, embedding declarations,
47
+ and proposed ingestion changes. It produces reports and guarded update plans;
48
+ your application controls embedding, retrieval, and vector-store writes.
49
+
50
+ See the [quickstart](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/quickstart.md), [API and migration notes](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/api.md),
51
+ [existing-index JSONL workflow](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/existing-index.md), [failure taxonomy](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/failures.md),
52
+ and [public API, policy and stored-format commitments](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/compatibility.md).
53
+ Included workflows cover compact reports, text-scoped baselines, embedding cost estimates,
54
+ structured metrics, and bounded receipts for rows/APIs/crawlers.
55
+
56
+ ## Why use it?
57
+
58
+ The highest-value moment is updating an existing index: an extraction regression
59
+ can turn missing output into unintended deletion of live indexed material.
60
+
61
+ An ingestion job can finish while some source material never becomes searchable.
62
+ An update can leave stale chunks behind; a retry can repeat work. This library
63
+ compares an independent source inventory with extracted chunks and produces a
64
+ repeatable, guarded update plan. It works with ordinary Python data.
65
+
66
+ **Build the expected inventory from the source system, not successful parser output.**
67
+
68
+ ## Try it
69
+
70
+ Install with the PDF and Office extras, then point the CLI at a folder to
71
+ check **current source extraction**:
72
+
73
+ ```sh
74
+ python -m pip install 'rag-ingestion-preflight[pdf,office]'
75
+ rag-preflight check ./documents
76
+ rag-preflight check ./documents --json --max-examples 3
77
+ rag-preflight check ./documents --expected expected-files.txt
78
+ ```
79
+
80
+ `check` discovers supported files and builds an in-memory source/page-or-slide
81
+ inventory before chunking. It needs no handwritten manifest or index export.
82
+ Without an external expected-file list it **cannot discover a document already
83
+ missing from the folder**; it checks the files that are present. `--expected`
84
+ accepts independently maintained UTF-8 root-relative supported paths, one per
85
+ line. It checks this minimum inventory only after a complete directory walk;
86
+ additional files are allowed. An empty folder or missing optional reader is an
87
+ input/incomplete outcome (exit 2), audited findings exit 1, and a clean supported
88
+ scope exits 0. A partial read never passes.
89
+ Supported files are UTF-8 `.txt`, `.md`, `.rst`, static `.html`/`.htm`, PDFs,
90
+ and optional `.docx`/`.pptx`. Missing optional readers and unreadable files fail
91
+ the check; paths outside the root are not followed. A PDF page with image objects
92
+ but no extractable text gets a **likely** image-only warning and may need OCR.
93
+ Word checks body paragraphs and table cells as one file unit; PowerPoint checks
94
+ slide text and table cells. Headers, footers, notes, text boxes, images, charts,
95
+ scripts and within-unit truncation are not fully validated. The report explicitly
96
+ marks **historical indexing unverified**: use `existing-index` with a complete
97
+ export or managed ingestion receipts to check what reached a vector store. Working
98
+ memory grows with the extracted corpus; batch large folders. The user reported
99
+ 36 PDFs/804 pages in 30 seconds at 71 MB peak and 300 text files in 0.1 seconds;
100
+ these are local observations, not a general memory bound or performance promise.
101
+ File sizes, parser behavior and measurement method were not supplied.
102
+ See [check to guarded ingestion](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/check-to-pipeline.md) for a path from this
103
+ diagnostic to a maintained pipeline.
104
+
105
+ ### Messy-document acceptance
106
+
107
+ The repository includes a reproducible, generated real-format acceptance suite:
108
+
109
+ ```sh
110
+ python -m pip install -e '.[pdf,office]'
111
+ python scripts/messy_document_acceptance.py
112
+ ```
113
+
114
+ It exercises invalid UTF-8, empty/damaged/encrypted PDFs, an image-only PDF, a
115
+ 1,000-paragraph DOCX, an image-heavy PPTX, static HTML, a missing expected file,
116
+ and an unsupported file. Linux and Windows CI run the suite with the real optional
117
+ readers. These license-safe fixtures test known failure handling; they are not
118
+ evidence from an external production corpus. See
119
+ [messy-document acceptance](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/messy-documents.md).
120
+
121
+ Open a terminal in the extracted `rag-preflight` source directory:
122
+
123
+ ```bash
124
+ python3 -m venv .venv
125
+ source .venv/bin/activate
126
+ python -m pip install -e .
127
+ python examples/safe_reingestion.py
128
+ python examples/indexed_reingestion.py
129
+ python -m unittest discover -s tests -v
130
+ ```
131
+
132
+ Windows activation: `.venv\Scripts\activate`.
133
+ Release archives are not committed to this source repository. To build a local
134
+ wheel explicitly:
135
+
136
+ ```bash
137
+ python -m pip install build
138
+ python -m build --outdir ../artifacts
139
+ python -m pip install ../artifacts/rag_ingestion_preflight-0.1.0-py3-none-any.whl
140
+ ```
141
+
142
+ The ignored `artifacts` directory is created by that command; it is not part of
143
+ the source repository. Until the first PyPI upload, use this source-build path.
144
+ The repository must be publicly readable when the release is published so the
145
+ package's Repository, Documentation, Issues and Changelog links resolve for users.
146
+
147
+ ## Capabilities
148
+
149
+ | Area | Behavior |
150
+ | --- | --- |
151
+ | Completeness | Missing documents, receipts, units, failed extraction, version mismatches, explicit blank units |
152
+ | Source types | Caller units such as pages, Markdown sections, transcript segments, message IDs and record keys; folder check supports PDF/text/HTML and optional Office subset |
153
+ | Chunk checks | Empty text, metadata, duplicates, boilerplate, length distribution, optional short/low-distinctiveness warnings and token limits |
154
+ | Update planning | Stable IDs; added, changed, unchanged and removed chunks; metadata-only updates skip embedding |
155
+ | Deletion protection | Explicit retirement; narrowly scoped shrink allowances; unrelated documents stay protected |
156
+ | Embeddings | IDs, dimensions, finite values, zero vectors, duplicate-vector warnings, configurable norm warnings |
157
+ | Plan-linked validation | Coverage and declared model, pipeline and embedding-input fingerprints |
158
+ | State | Portable JSON snapshots or document-indexed SQLite storage with revision-checked ledger commits |
159
+ | Integration | Python API, JSON CLI, PDF/generic receipt producers, key helper, thin framework converters, optional NumPy |
160
+ | Operations | Full ledger verification, ID reconciliation, warning baselines, per-unit text-yield warnings |
161
+
162
+ ## Useful on the first run
163
+
164
+ ```python
165
+ from rag_preflight import audit_chunks
166
+ report = audit_chunks(
167
+ [{"text": "Home help contact", "metadata": {"source": "help.html"}}],
168
+ min_chars=40, distinctive_term_fraction=.8,
169
+ )
170
+ print(report.to_dict())
171
+ ```
172
+
173
+ No manifest is needed for chunk checks. This example warns about a short chunk;
174
+ lexical analysis needs at least five chunks. See [adoption](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/adoption.md) for
175
+ PDF extraction receipts, generic extraction, chunk keys, framework converters,
176
+ warning baselines and a runnable LangGraph validation gate.
177
+
178
+ ## How it fits existing frameworks
179
+
180
+ LangChain indexing already tracks records and supports cleanup modes. Its
181
+ [API documentation](https://reference.langchain.com/python/langchain-core/indexing/api)
182
+ warns that full cleanup can remove wanted documents when the loader returns only
183
+ a subset. LlamaIndex's [ingestion pipeline](https://developers.llamaindex.ai/python/framework/module_guides/loading/ingestion_pipeline/)
184
+ already skips unchanged documents and reprocesses changed ones using a docstore.
185
+ RAG Preflight adds an independent source-completeness audit and explicit deletion
186
+ budgets before applying changes. Diffing alone is not its distinguishing feature.
187
+ Keep a single owner for deletion decisions: another cleanup pass can bypass the
188
+ approved plan. Converters do not automatically integrate the two indexing engines.
189
+
190
+ ## Source units instead of fake pages
191
+
192
+ ```python
193
+ from rag_preflight import DocumentSpec, ExtractionReceipt, audit_ingestion
194
+
195
+ documents = [DocumentSpec(
196
+ "handbook", "etag-123",
197
+ expected_units=("section:leave", "section:approval"),
198
+ )]
199
+ receipts = [ExtractionReceipt(
200
+ "handbook", "etag-123",
201
+ processed_units=("section:leave", "section:approval"), completed=True,
202
+ )]
203
+ chunks = [
204
+ {"chunk_key": "leave", "text": "Employees receive 20 days of leave.",
205
+ "metadata": {"document_id": "handbook", "source_version": "etag-123",
206
+ "source": "handbook.md", "units": ["section:leave"]}},
207
+ {"chunk_key": "approval", "text": "Managers approve leave requests.",
208
+ "metadata": {"document_id": "handbook", "source_version": "etag-123",
209
+ "source": "handbook.md", "units": ["section:approval"]}},
210
+ ]
211
+ report = audit_ingestion(documents, receipts, chunks)
212
+ report.raise_for_errors()
213
+ ```
214
+
215
+ Units are canonical strings. Positive integers are convenience aliases: `1` becomes
216
+ `"page:1"`; literal `"1"` is a different unit. Duplicate canonical IDs are rejected.
217
+ Whitespace and case in string identifiers are preserved. Unit IDs must come from
218
+ source structure; adding fake unit IDs does not establish meaningful completeness.
219
+
220
+ The earlier `expected_pages`, `processed_pages`, `empty_pages`, `failed_pages`,
221
+ `allowed_empty_pages` and chunk metadata `pages` remain accepted for PDFs. Do not
222
+ supply both page and unit forms for the same object. `DocumentSpec.to_dict()` and
223
+ `ExtractionReceipt.to_dict()` export the canonical unit representation, including
224
+ when constructed with page aliases.
225
+
226
+ For approved blank content, declare `allowed_empty_units` on the specification and
227
+ `empty_units` on the receipt. They remain part of `processed_units`. A source known
228
+ to contain no units can declare `expected_units=()` with `min_chunks=0`.
229
+ Omitting `expected_units` means coverage is unknown: the audit reports
230
+ `completeness_unverified` and a skipped check. **It cannot produce a replacement
231
+ snapshot**, even if warnings are otherwise allowed.
232
+
233
+ ## Policies and exact token counts
234
+
235
+ ```python
236
+ from rag_preflight import AcceptancePolicy
237
+ policy = AcceptancePolicy(required_metadata=("source",), max_warnings=0)
238
+ ```
239
+
240
+ The ingestion API always requires valid identity, version and unit information
241
+ when coverage is declared. Metadata must use finite JSON-native data. Findings
242
+ include document ID, chunk key/index where available, a code and a suggested action.
243
+ Use `report.to_dict()` or `report.by_document()`.
244
+
245
+ Supply both `max_tokens` and `token_counter` to `audit_ingestion` or `build_snapshot`
246
+ for exact limits, using the actual embedding pipeline's tokenizer. Without them,
247
+ `token_limit` is explicitly skipped. Model-specific prefixes/special tokens must be
248
+ included in your counter. The CLI does not guess token counts.
249
+
250
+ ## Build and compare snapshots
251
+
252
+ ```python
253
+ from rag_preflight import build_snapshot, plan_update
254
+ candidate = build_snapshot(documents, receipts, chunks,
255
+ namespace="tenant-a/kb", pipeline_id="parser-v1/chunker-v1",
256
+ embedding_model="provider/model-revision/dimensions-1536")
257
+ plan = plan_update(None, candidate) # First ingestion
258
+ ```
259
+
260
+ For updates, pass the committed previous snapshot as the first argument. Stable
261
+ chunk IDs depend on namespace, document ID and chunk_key. Same identity with changed
262
+ text requests embedding; changed metadata requests an upsert but no new embedding.
263
+ Keep keys stable across retries. Documents omitted from the candidate are preserved.
264
+
265
+ ```python
266
+ # Retire only this named document. Other documents keep their deletion guards.
267
+ plan = plan_update(previous, candidate, retire_documents=["obsolete-doc"])
268
+
269
+ # Allow removal of up to 80% of this document's previous chunk IDs only.
270
+ plan = plan_update(previous, candidate, allow_shrink={"handbook": 0.8})
271
+ ```
272
+
273
+ Default `max_delete_fraction=0.25` applies per document. Independent batch guards
274
+ use `max_corpus_delete_fraction=0.15` over the full committed ordinary inventory.
275
+ Absolute `max_removed_chunks` and `max_shrinking_documents` budgets are optional
276
+ (default `None`). Both retired and scoped-exempt documents are excluded from the
277
+ ordinary numerator and denominator. Review these configurable initial policies,
278
+ and configure the independent corpus threshold when raising document limits.
279
+ A replacement that changes IDs counts even if its net chunk count does not shrink.
280
+ Per-document checks run first in sorted ID order, then optional absolute budgets,
281
+ then the corpus fraction. JSON and SQLite use shared logic and matching errors.
282
+
283
+ The 300-document case (20 chunks each, reduced to 16) now fails: 300 documents lose
284
+ 1,200 chunks even though every document is below 25%. Exact configured limits pass;
285
+ exceeding them fails. Configure the independent limits for your workload; absolute budgets set to `None`
286
+ disables one batch limit in Python. Budgets apply to one plan, not accumulated jobs.
287
+
288
+ Named retirements are excluded. Documents with validated scoped shrink allowances
289
+ use their own per-document limit and are excluded from ordinary batch budgets.
290
+ Invalid, unknown, retired or non-updated allowance targets are rejected. Exceptions
291
+ never relax guards for other documents or completeness requirements. The plan records
292
+ the allowances; applications should log their configured batch budgets alongside it.
293
+
294
+ Changing a model/pipeline identifier requires every retained document in the batch
295
+ and requests re-embedding. Include actual model revision, dimension and preprocessing
296
+ changes in these identifiers. The library does not create/migrate database indexes.
297
+
298
+ ## Validate embeddings against the plan
299
+
300
+ ```python
301
+ from rag_preflight import audit_plan_embeddings
302
+ # embedding_records come from your producer, including its recorded provenance:
303
+ # {"chunk_id": ..., "vector": [...], "embedding_model": ...,
304
+ # "pipeline_id": ..., "input_hash": ...}
305
+ report = audit_plan_embeddings(plan, embedding_records, dimensions=1536, mode="embed")
306
+ report.raise_for_errors()
307
+ ```
308
+
309
+ `input_hash` is the exact text fingerprint stored in the corresponding target
310
+ ChunkState.text_hash. `mode="embed"` covers exactly `plan.embed_ids`;
311
+ `mode="upsert"` covers all `plan.upsert_ids`, including reused vectors. The latter
312
+ must also be validated before uploading. These checks validate producer declarations,
313
+ not mathematical proof of which model created a vector. Capture provenance where
314
+ the embedding request is made; do not relabel vectors to make checks pass.
315
+
316
+ The lower-level `audit_embeddings` remains available. Identical vectors across
317
+ IDs warn by default; they can be legitimate for identical inputs. Set
318
+ `detect_duplicates=False` to disable the check. Configure `norm_range=(low, high)`
319
+ for your model; no universal norm threshold is assumed. `max_warnings=0` turns
320
+ warnings into rejection under the acceptance policy.
321
+
322
+ For optional acceleration: install `.[numpy]` and pass `backend="numpy"` to either
323
+ embedding audit. The backend works one vector at a time, including direct NumPy
324
+ arrays. No whole-corpus vector matrix is allocated by the validator.
325
+
326
+ ## Recommended state: SQLite ledger
327
+
328
+ ```python
329
+ from rag_preflight import SQLiteSnapshotStore
330
+ with SQLiteSnapshotStore("ingestion.db") as store:
331
+ stored_plan = store.plan(candidate, allow_shrink={})
332
+ update = stored_plan.update
333
+ # Validate embeddings/payloads, acquire your application lock, recheck base,
334
+ # and confirm vector-store upserts/deletes before committing the ledger.
335
+ store.assert_base(stored_plan)
336
+ # ... external writes, with concurrency protection ...
337
+ store.commit(stored_plan)
338
+ ```
339
+
340
+ **Use SQLite for operational state; use JSON for portable export/interchange.**
341
+ The SQLite backend loads only touched documents; its nested UpdatePlan.target is
342
+ **the touched scope**, not the whole corpus. Never use that subset to replace the
343
+ full ledger outside `store.commit`. The store applies touched documents and explicit
344
+ retirements transactionally while preserving other rows. A stale commit is rejected;
345
+ a no-op keeps the revision. `document_ids()` enumerates the ledger without loading
346
+ payloads. `load_documents(ids)` exports selected documents; exporting all IDs to one
347
+ JSON snapshot still requires whole-corpus memory. `verify()` scans every stored
348
+ revision, identity and chunk count plus SQLite integrity. `chunk_ids()` streams
349
+ verified IDs one document at a time. See [operator and apply checks](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/production.md)
350
+ for `reconcile()` and its complete-namespace requirements.
351
+
352
+ Portable JSON snapshots still use schema version 1; existing hash-only snapshots
353
+ remain loadable. SQLite storage uses schema version 2, migrated from version 1, with per-document
354
+ snapshot blobs and an indexed document table. Import a JSON snapshot by planning and
355
+ committing it as an initial batch. Large initial imports can commit whole documents
356
+ in successive batches without constructing a full-corpus Snapshot.
357
+
358
+ SQLite protects the ledger, not a vector database transaction. Hold an application
359
+ lock across base verification, external writes and ledger commit, or use a generation
360
+ switch. See [production integration](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/production.md).
361
+
362
+ ## Cumulative deletion visibility
363
+
364
+ ```python
365
+ # After successful external writes and ledger.commit(stored_plan):
366
+ print(ledger.deletion_summary())
367
+ # Detailed bounded commit records are explicitly available:
368
+ print(ledger.commit_history(limit=4))
369
+ ```
370
+
371
+ The summary exposes repeated-batch shrinkage with full-corpus window counts, gross
372
+ ID removals, net shrinkage and exempt removal categories. It does not impose a
373
+ cumulative hard gate or verify external writes. SQLite schema 1 migrates to 2;
374
+ pre-tracking history remains explicitly unverified. Young-ledger windows explicitly
375
+ exclude initial population when necessary for a meaningful nonzero baseline. See [window and migration
376
+ rules](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/api.md#cumulative-deletion-visibility-sqlite).
377
+
378
+ Python `AuditReport.to_dict()` now defaults to compact output; `.issues` and
379
+ `to_dict(detailed=True)` retain debugging detail. This pre-1.0 change makes the
380
+ Python JSON shape match the CLI. Taxonomy coverage is tested against source.
381
+ For adoption validation, use the separate [Chroma/FAISS integration contract](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/integration-validation.md).
382
+
383
+ ## CLI
384
+
385
+ Read-only scheduled ledger inspection:
386
+
387
+ ```sh
388
+ rag-preflight ledger summary ledger.db --json
389
+ rag-preflight ledger history ledger.db --limit 4 --json
390
+ ```
391
+
392
+ Missing files fail rather than being created; legacy schemas require an explicit
393
+ writable upgrade. The summary identifies its actual comparison window and baseline.
394
+
395
+
396
+ ```bash
397
+ rag-preflight examples/chunks.json --json --min-chars 40 --distinctive-term-fraction .8
398
+ rag-preflight ingestion examples/ingestion.json --snapshot candidate.json
399
+ rag-preflight plan - candidate.json
400
+ rag-preflight plan committed.json candidate.json --retire obsolete-doc
401
+ rag-preflight plan committed.json candidate.json --allow-shrink '{"handbook": 0.8}'
402
+ rag-preflight embeddings vectors.json
403
+ ```
404
+
405
+ The last input contains `expected_chunk_ids`, `embeddings`, `dimensions`. CLI plans
406
+ are advisory JSON; SQLite and plan-linked embedding validation use the Python API.
407
+ Exit codes: 0 accepted, 1 validation rejection, 2 invalid input or unsafe plan.
408
+ A failed audit leaves an existing candidate file unchanged: check exit status.
409
+
410
+ ## Evidence and limits
411
+
412
+ The included [public-corpus trial](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/corpus-results.json) covers an RFC PDF and
413
+ pandas Markdown README, 210 source units and 701 chunks, plus eleven injected scenarios. The unmodified Markdown source produces one
414
+ low-yield warning for a short license section; see the recorded finding.
415
+ It is a small real-source trial with dummy vectors, not a production load test.
416
+ Reproduce with `pip install '.[trial,numpy]'` followed by
417
+ `python scripts/corpus_trial.py --output results.json` (downloads public sources).
418
+ Source hashes are recorded; upstream files can change.
419
+
420
+ The library does not parse source files in its core, detect semantic correctness,
421
+ PII/prompt injection, or prove within-unit content completeness. It relies on trusted
422
+ source manifests and receipts. Batch validation and individual-document snapshots
423
+ still use memory proportional to their input. A single enormous document remains
424
+ an in-memory unit even with SQLite.
425
+
426
+ See [validation](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/validation.md), [changelog](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/CHANGELOG.md),
427
+ [contributing](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/CONTRIBUTING.md), and [license](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/LICENSE). GitHub Actions exercises
428
+ Python 3.10 through 3.14 on Linux plus Python 3.12 on macOS and Windows; separate
429
+ jobs cover optional integrations, messy documents and clean-clone reference apps.
430
+
431
+ CLI discovery: `rag-preflight --help` lists every workflow;
432
+ `rag-preflight existing-index --help` shows export/scope options.
433
+ Use `rag-preflight chunks INPUT.jsonl` for explicit chunk auditing; the legacy
434
+ `rag-preflight INPUT.jsonl` form remains supported. Unknown bare command names
435
+ return status 2; extensionless files can be passed with `chunks INPUT` or `./INPUT`.
436
+
437
+
438
+ ## Deployment evidence and responsibility
439
+
440
+ RAG Preflight produces validation reports and guarded update plans. It does not
441
+ write to your vector store; your application performs embedding requests, vector
442
+ writes, read-back checks and recovery. Explicit ledger commits do write to the
443
+ library's SQLite inventory. Ledger transactions do not make external writes atomic.
444
+
445
+ The mechanisms and tests provide evidence of capability, not a guarantee that the
446
+ library is safe in every pipeline. Validate source mapping, completeness evidence,
447
+ namespace policy, locking, write visibility and recovery against your deployment.
448
+ The project has a reproducible limited corpus trial and independent reviewer checks,
449
+ not established operational history across independent production deployments.
450
+ External users and deployments must supply that operational evidence after release.
451
+
452
+ Its strongest use case is the next ingestion of a changing corpus: loader omissions
453
+ can otherwise become unintended index deletions. Initial ingestion also benefits
454
+ from source coverage, chunk integrity and embedding checks; retrieval quality and
455
+ prompt design remain outside scope. “Second ingestion” describes updating an index,
456
+ not prompt injection or model training.
457
+
458
+ For existing pipelines, start with the [store export recipes](https://github.com/ShyamSundar29/rag-preflight/blob/main/rag-preflight/docs/export-recipes.md).
459
+
460
+ CLI invocation requires a command or chunk input file. No arguments return exit
461
+ status 2 with usage on stderr; explicit `--help` and `-h` return status 0.