ragpages 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.
- ragpages-0.1.0/LICENSE +21 -0
- ragpages-0.1.0/PKG-INFO +197 -0
- ragpages-0.1.0/README.md +164 -0
- ragpages-0.1.0/pyproject.toml +46 -0
- ragpages-0.1.0/ragpages/__init__.py +16 -0
- ragpages-0.1.0/ragpages/chapter.py +68 -0
- ragpages-0.1.0/ragpages/cli.py +513 -0
- ragpages-0.1.0/ragpages/config.py +103 -0
- ragpages-0.1.0/ragpages/ingest.py +312 -0
- ragpages-0.1.0/ragpages/meta.py +80 -0
- ragpages-0.1.0/ragpages/ocr/__init__.py +1 -0
- ragpages-0.1.0/ragpages/ocr/base.py +63 -0
- ragpages-0.1.0/ragpages/ocr/kraken_engine.py +59 -0
- ragpages-0.1.0/ragpages/ocr/rapidocr_engine.py +56 -0
- ragpages-0.1.0/ragpages/ocr/registry.py +25 -0
- ragpages-0.1.0/ragpages/parser.py +122 -0
- ragpages-0.1.0/ragpages/parser_compare.py +142 -0
- ragpages-0.1.0/ragpages/pipeline.yaml +37 -0
- ragpages-0.1.0/ragpages/toc_store.py +59 -0
- ragpages-0.1.0/ragpages.egg-info/PKG-INFO +197 -0
- ragpages-0.1.0/ragpages.egg-info/SOURCES.txt +24 -0
- ragpages-0.1.0/ragpages.egg-info/dependency_links.txt +1 -0
- ragpages-0.1.0/ragpages.egg-info/entry_points.txt +2 -0
- ragpages-0.1.0/ragpages.egg-info/requires.txt +16 -0
- ragpages-0.1.0/ragpages.egg-info/top_level.txt +1 -0
- ragpages-0.1.0/setup.cfg +4 -0
ragpages-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ragpages 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.
|
ragpages-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ragpages
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: One command turns a PDF/scan library into a citation-grade SQLite database for agents: every chunk keeps its page, locator and provenance.
|
|
5
|
+
Author: ragpages contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Icefox12138/ragpages
|
|
8
|
+
Project-URL: Repository, https://github.com/Icefox12138/ragpages
|
|
9
|
+
Project-URL: Issues, https://github.com/Icefox12138/ragpages/issues
|
|
10
|
+
Keywords: rag,pdf,ocr,sqlite,citation,provenance,pipeline,agent,fts
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Database
|
|
17
|
+
Classifier: Topic :: Text Processing
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: PyYAML>=6.0
|
|
22
|
+
Provides-Extra: pdfium
|
|
23
|
+
Requires-Dist: pypdfium2>=4.30; extra == "pdfium"
|
|
24
|
+
Provides-Extra: mupdf
|
|
25
|
+
Requires-Dist: pymupdf>=1.24; extra == "mupdf"
|
|
26
|
+
Provides-Extra: rapid
|
|
27
|
+
Requires-Dist: rapidocr-onnxruntime; extra == "rapid"
|
|
28
|
+
Provides-Extra: kraken
|
|
29
|
+
Requires-Dist: kraken; extra == "kraken"
|
|
30
|
+
Provides-Extra: paddle
|
|
31
|
+
Requires-Dist: paddleocr; extra == "paddle"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# ragpages
|
|
35
|
+
|
|
36
|
+
**PDF (+ OCR) → data contract → database for agents.** One command on one machine.
|
|
37
|
+
|
|
38
|
+
ragpages is a lightweight, single-machine producer pipeline. It eats PDFs (with a text
|
|
39
|
+
layer, or via a pluggable OCR stage) and emits SQLite artifacts that follow the classic
|
|
40
|
+
RAG database contract — `documents` / `chunks` / `chunks_fts` / `toc` — ready to be served
|
|
41
|
+
by any RAG runtime. No services, no daemons, no cloud: `ragpages build` and you are done.
|
|
42
|
+
|
|
43
|
+
## Positioning vs MinerU
|
|
44
|
+
|
|
45
|
+
| | ragpages | MinerU-style service pipelines |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Shape | One CLI, one process, one command | Heavy service pipeline (layout models, server components, model downloads) |
|
|
48
|
+
| Input | PDF directory + a probe CSV (+ optional OCR models) | PDF (or batches through its service) |
|
|
49
|
+
| Output | Plain SQLite (`documents`/`chunks`/`chunks_fts`/`toc`) + manifests | Markdown/JSON content plus its own serving stack |
|
|
50
|
+
| OCR | Optional stage, engine-swappable (RapidOCR / Kraken) | Built-in (large models, big downloads) |
|
|
51
|
+
| Parser | pypdfium2 (BSD/Apache) by default; PyMuPDF optional | Its own stack |
|
|
52
|
+
| License story | MIT code; pypdfium2 is permissively licensed | AGPL / model licenses to review |
|
|
53
|
+
| Fit | "I have PDFs and want a searchable database for my agent" | "I want full document understanding at scale" |
|
|
54
|
+
|
|
55
|
+
ragpages deliberately stays at the *retrieval layer*: it turns books into searchable,
|
|
56
|
+
page-anchored chunks with provenance. MinerU targets *document understanding* (formulas,
|
|
57
|
+
tables, reading order). If you need heavy layout analysis, use MinerU; if you need a
|
|
58
|
+
portable, auditable index for an agent, use ragpages.
|
|
59
|
+
|
|
60
|
+
### Why not a vector-database ingestion toolkit
|
|
61
|
+
|
|
62
|
+
Three PyPI packages already use the old name (`ragpipe`, `ragpipe-ai`, `ragpipe-lite`);
|
|
63
|
+
all of them end at "chunks → embeddings → vector store". ragpages ends somewhere else:
|
|
64
|
+
a **citation-grade SQLite database** where every chunk keeps its `page`, locator and
|
|
65
|
+
`sha256` provenance, so an answer can always be checked against the page it came from.
|
|
66
|
+
If vectors are all you need, those packages are fine; if you need auditable page
|
|
67
|
+
citations, that is exactly what ragpages is for.
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# editable install for development
|
|
73
|
+
uv venv .venv
|
|
74
|
+
uv pip install -e ".[pdfium]"
|
|
75
|
+
|
|
76
|
+
# or from PyPI (once published)
|
|
77
|
+
# pip install "ragpages[pdfium]"
|
|
78
|
+
|
|
79
|
+
# prove the wiring without any real data
|
|
80
|
+
ragpages selftest
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Real corpus:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
cd my-corpus
|
|
87
|
+
# 1. copy the profile template and edit it
|
|
88
|
+
copy <path-to-package>/pipeline.yaml . # Windows
|
|
89
|
+
# cp $(python -c "import ragpages,os;print(os.path.dirname(ragpages.__file__))")/../pipeline.yaml . # POSIX
|
|
90
|
+
|
|
91
|
+
# 2. a probe CSV decides which books have a text layer:
|
|
92
|
+
# catalog/probe.csv -> rel,cpp
|
|
93
|
+
# books/a.pdf,900 (cpp = chars per page)
|
|
94
|
+
|
|
95
|
+
# 3. build: extract per profile, then fuse into search.db
|
|
96
|
+
ragpages build --profiles books --out data/
|
|
97
|
+
|
|
98
|
+
# or stage by stage (handy for re-runs and debugging)
|
|
99
|
+
ragpages extract --profile books --out data/ --limit 1
|
|
100
|
+
ragpages search --out data/ --sources books
|
|
101
|
+
ragpages validate --out data/
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Configuration
|
|
105
|
+
|
|
106
|
+
`pipeline.yaml` is the only place a corpus directory is named; code always takes a
|
|
107
|
+
profile, never a machine path.
|
|
108
|
+
|
|
109
|
+
| Setting | Meaning |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `defaults.data` | output root, relative to the config file |
|
|
112
|
+
| `defaults.parser` | `pypdfium2` (default, BSD/Apache) or `pymupdf` (AGPL) — never mix parsers in one database |
|
|
113
|
+
| `defaults.chunk` | `size` / `overlap` / `min_len` for chunking |
|
|
114
|
+
| `defaults.min_cpp` | books below this chars-per-page average are treated as scans |
|
|
115
|
+
| `ocr.models` | local ONNX/`.mlmodel` paths — models never enter the repository, only their sha256 enters provenance |
|
|
116
|
+
| `profiles.<name>` | `root` (PDF dir), `source` (the id written into `chunks.source`), `layout`, `probe` CSV, per-profile `ocr`/`parser`/`chunk` overrides |
|
|
117
|
+
|
|
118
|
+
Environment variables:
|
|
119
|
+
|
|
120
|
+
| Variable | Effect |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `RAGPAGES_CONFIG` | path of the `pipeline.yaml` to load |
|
|
123
|
+
| `RAGPAGES_DATA` | override the output data root |
|
|
124
|
+
|
|
125
|
+
## Output contract
|
|
126
|
+
|
|
127
|
+
Everything lands under `<data>/` (config `defaults.data`, or `--out`):
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
data/
|
|
131
|
+
├── indexes/<source>.db per-source: documents + chunks + chunks_fts (trigram)
|
|
132
|
+
├── indexes/<source>-manifest.json
|
|
133
|
+
├── indexes/search.db fused chunks (source column) + chunks_fts (unicode61, pre-tokenized)
|
|
134
|
+
├── indexes/search-eval.json smoke-query evaluation + canary isolation check
|
|
135
|
+
├── book_meta.json copied by `ragpages meta` (validated input, never generated)
|
|
136
|
+
└── ocr/<book_id>/pages.jsonl OCR stage output (page text + boxes + confidence + provenance)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The tables follow the classic RAG-DB-SCHEMA concept — `documents` (per-book provenance),
|
|
140
|
+
`chunks` (page-anchored text with `visibility`), `chunks_fts` (`rowid == chunks.id`),
|
|
141
|
+
and `toc` (`source, book, ord, level, title, page_start, page_end, volume, pages, meta`,
|
|
142
|
+
written by `ragpages chapter`). A downstream runtime needs no more than these to serve
|
|
143
|
+
search, citations and page images.
|
|
144
|
+
|
|
145
|
+
- `visibility` is enforced at SQL level (`tutor` vs `answer_key`); the fused `search.db`
|
|
146
|
+
carries a canary `answer_key` row and the smoke eval proves it never surfaces to students.
|
|
147
|
+
- CJK text is pre-tokenized into bigrams for the `unicode61` FTS, per the downstream contract.
|
|
148
|
+
|
|
149
|
+
## Stages
|
|
150
|
+
|
|
151
|
+
| Command | Stage | Idempotency |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| `ragpages ocr` | PDF → per-page OCR text + boxes + confidence + provenance | per book, resumable |
|
|
154
|
+
| `ragpages extract` | text layer (or OCR fallback) → per-source db + manifest | overwrites the source db |
|
|
155
|
+
| `ragpages chapter` | header/回 OCR JSONL → `toc` rows (via the public `classics-index` package) | per source+book |
|
|
156
|
+
| `ragpages meta` | validate + copy `book_meta.json` (never generates it) | overwrites the copy |
|
|
157
|
+
| `ragpages search` | per-source dbs → `search.db` + FTS + eval | overwrites |
|
|
158
|
+
| `ragpages validate` | artifacts vs contract | read-only |
|
|
159
|
+
| `ragpages build` | extract + search | overall re-run |
|
|
160
|
+
| `ragpages selftest` | synthetic PDF → extract → search → validate | scratch only |
|
|
161
|
+
|
|
162
|
+
### OCR engines
|
|
163
|
+
|
|
164
|
+
`ocr.engine` picks an adapter at runtime; a missing package/model is a readable error,
|
|
165
|
+
not an ImportError traceback.
|
|
166
|
+
|
|
167
|
+
| Engine | Extra | Notes |
|
|
168
|
+
|---|---|---|
|
|
169
|
+
| `rapidocr` | `pip install ragpages[rapid]` | PP-OCRv4 ONNX, cpu/dml; the default |
|
|
170
|
+
| `kraken` | `pip install ragpages[kraken]` | polytonic Greek / Latin scans (own venv recommended) |
|
|
171
|
+
| `paddle` | `pip install ragpages[paddle]` | comparison use only, not wired |
|
|
172
|
+
| `deepseek-api` | — | network OCR, opt-in only |
|
|
173
|
+
|
|
174
|
+
### Chapter stage
|
|
175
|
+
|
|
176
|
+
`ragpages chapter` builds the `toc` table from header/回 OCR JSONL. The pure chapter
|
|
177
|
+
logic lives in the public [`classics-index`](https://pypi.org/project/classics-index/)
|
|
178
|
+
package (>= 0.1): install it next to ragpages (`pip install classics-index`) when you
|
|
179
|
+
use this stage.
|
|
180
|
+
|
|
181
|
+
## License notes
|
|
182
|
+
|
|
183
|
+
- ragpages code: MIT.
|
|
184
|
+
- `pypdfium2`: BSD/Apache — the default parser is freely distributable.
|
|
185
|
+
- `pymupdf`: AGPL — opt-in extra; only enable where your deployment accepts that.
|
|
186
|
+
- OCR models are local artifacts: they never ship with the package, only their sha256
|
|
187
|
+
enters the provenance records.
|
|
188
|
+
|
|
189
|
+
## 中文摘要
|
|
190
|
+
|
|
191
|
+
ragpages 是一条**单机一条命令**的轻量管线:输入 PDF 目录(有文本层直接抽取,无文本层走可插拔
|
|
192
|
+
OCR 阶段),输出符合经典 RAG 数据库契约的 SQLite 产物(`documents` / `chunks` /
|
|
193
|
+
`chunks_fts` / `toc` 表 + manifest 与评测文件),可直接交给下游 Agent 运行时做检索、
|
|
194
|
+
引用与回页。对比 MinerU 这类服务化重型管线,ragpages 只有 CLI、零服务、零云端依赖,
|
|
195
|
+
模型不进仓库只记 sha256;默认解析器 pypdfium2(BSD/Apache),PyMuPDF(AGPL)仅作可选。
|
|
196
|
+
配置全部走 `pipeline.yaml` profile + `RAGPAGES_CONFIG` / `RAGPAGES_DATA` 环境变量,
|
|
197
|
+
代码中不含任何机器/私有路径。
|
ragpages-0.1.0/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# ragpages
|
|
2
|
+
|
|
3
|
+
**PDF (+ OCR) → data contract → database for agents.** One command on one machine.
|
|
4
|
+
|
|
5
|
+
ragpages is a lightweight, single-machine producer pipeline. It eats PDFs (with a text
|
|
6
|
+
layer, or via a pluggable OCR stage) and emits SQLite artifacts that follow the classic
|
|
7
|
+
RAG database contract — `documents` / `chunks` / `chunks_fts` / `toc` — ready to be served
|
|
8
|
+
by any RAG runtime. No services, no daemons, no cloud: `ragpages build` and you are done.
|
|
9
|
+
|
|
10
|
+
## Positioning vs MinerU
|
|
11
|
+
|
|
12
|
+
| | ragpages | MinerU-style service pipelines |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| Shape | One CLI, one process, one command | Heavy service pipeline (layout models, server components, model downloads) |
|
|
15
|
+
| Input | PDF directory + a probe CSV (+ optional OCR models) | PDF (or batches through its service) |
|
|
16
|
+
| Output | Plain SQLite (`documents`/`chunks`/`chunks_fts`/`toc`) + manifests | Markdown/JSON content plus its own serving stack |
|
|
17
|
+
| OCR | Optional stage, engine-swappable (RapidOCR / Kraken) | Built-in (large models, big downloads) |
|
|
18
|
+
| Parser | pypdfium2 (BSD/Apache) by default; PyMuPDF optional | Its own stack |
|
|
19
|
+
| License story | MIT code; pypdfium2 is permissively licensed | AGPL / model licenses to review |
|
|
20
|
+
| Fit | "I have PDFs and want a searchable database for my agent" | "I want full document understanding at scale" |
|
|
21
|
+
|
|
22
|
+
ragpages deliberately stays at the *retrieval layer*: it turns books into searchable,
|
|
23
|
+
page-anchored chunks with provenance. MinerU targets *document understanding* (formulas,
|
|
24
|
+
tables, reading order). If you need heavy layout analysis, use MinerU; if you need a
|
|
25
|
+
portable, auditable index for an agent, use ragpages.
|
|
26
|
+
|
|
27
|
+
### Why not a vector-database ingestion toolkit
|
|
28
|
+
|
|
29
|
+
Three PyPI packages already use the old name (`ragpipe`, `ragpipe-ai`, `ragpipe-lite`);
|
|
30
|
+
all of them end at "chunks → embeddings → vector store". ragpages ends somewhere else:
|
|
31
|
+
a **citation-grade SQLite database** where every chunk keeps its `page`, locator and
|
|
32
|
+
`sha256` provenance, so an answer can always be checked against the page it came from.
|
|
33
|
+
If vectors are all you need, those packages are fine; if you need auditable page
|
|
34
|
+
citations, that is exactly what ragpages is for.
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# editable install for development
|
|
40
|
+
uv venv .venv
|
|
41
|
+
uv pip install -e ".[pdfium]"
|
|
42
|
+
|
|
43
|
+
# or from PyPI (once published)
|
|
44
|
+
# pip install "ragpages[pdfium]"
|
|
45
|
+
|
|
46
|
+
# prove the wiring without any real data
|
|
47
|
+
ragpages selftest
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Real corpus:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
cd my-corpus
|
|
54
|
+
# 1. copy the profile template and edit it
|
|
55
|
+
copy <path-to-package>/pipeline.yaml . # Windows
|
|
56
|
+
# cp $(python -c "import ragpages,os;print(os.path.dirname(ragpages.__file__))")/../pipeline.yaml . # POSIX
|
|
57
|
+
|
|
58
|
+
# 2. a probe CSV decides which books have a text layer:
|
|
59
|
+
# catalog/probe.csv -> rel,cpp
|
|
60
|
+
# books/a.pdf,900 (cpp = chars per page)
|
|
61
|
+
|
|
62
|
+
# 3. build: extract per profile, then fuse into search.db
|
|
63
|
+
ragpages build --profiles books --out data/
|
|
64
|
+
|
|
65
|
+
# or stage by stage (handy for re-runs and debugging)
|
|
66
|
+
ragpages extract --profile books --out data/ --limit 1
|
|
67
|
+
ragpages search --out data/ --sources books
|
|
68
|
+
ragpages validate --out data/
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
`pipeline.yaml` is the only place a corpus directory is named; code always takes a
|
|
74
|
+
profile, never a machine path.
|
|
75
|
+
|
|
76
|
+
| Setting | Meaning |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `defaults.data` | output root, relative to the config file |
|
|
79
|
+
| `defaults.parser` | `pypdfium2` (default, BSD/Apache) or `pymupdf` (AGPL) — never mix parsers in one database |
|
|
80
|
+
| `defaults.chunk` | `size` / `overlap` / `min_len` for chunking |
|
|
81
|
+
| `defaults.min_cpp` | books below this chars-per-page average are treated as scans |
|
|
82
|
+
| `ocr.models` | local ONNX/`.mlmodel` paths — models never enter the repository, only their sha256 enters provenance |
|
|
83
|
+
| `profiles.<name>` | `root` (PDF dir), `source` (the id written into `chunks.source`), `layout`, `probe` CSV, per-profile `ocr`/`parser`/`chunk` overrides |
|
|
84
|
+
|
|
85
|
+
Environment variables:
|
|
86
|
+
|
|
87
|
+
| Variable | Effect |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `RAGPAGES_CONFIG` | path of the `pipeline.yaml` to load |
|
|
90
|
+
| `RAGPAGES_DATA` | override the output data root |
|
|
91
|
+
|
|
92
|
+
## Output contract
|
|
93
|
+
|
|
94
|
+
Everything lands under `<data>/` (config `defaults.data`, or `--out`):
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
data/
|
|
98
|
+
├── indexes/<source>.db per-source: documents + chunks + chunks_fts (trigram)
|
|
99
|
+
├── indexes/<source>-manifest.json
|
|
100
|
+
├── indexes/search.db fused chunks (source column) + chunks_fts (unicode61, pre-tokenized)
|
|
101
|
+
├── indexes/search-eval.json smoke-query evaluation + canary isolation check
|
|
102
|
+
├── book_meta.json copied by `ragpages meta` (validated input, never generated)
|
|
103
|
+
└── ocr/<book_id>/pages.jsonl OCR stage output (page text + boxes + confidence + provenance)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The tables follow the classic RAG-DB-SCHEMA concept — `documents` (per-book provenance),
|
|
107
|
+
`chunks` (page-anchored text with `visibility`), `chunks_fts` (`rowid == chunks.id`),
|
|
108
|
+
and `toc` (`source, book, ord, level, title, page_start, page_end, volume, pages, meta`,
|
|
109
|
+
written by `ragpages chapter`). A downstream runtime needs no more than these to serve
|
|
110
|
+
search, citations and page images.
|
|
111
|
+
|
|
112
|
+
- `visibility` is enforced at SQL level (`tutor` vs `answer_key`); the fused `search.db`
|
|
113
|
+
carries a canary `answer_key` row and the smoke eval proves it never surfaces to students.
|
|
114
|
+
- CJK text is pre-tokenized into bigrams for the `unicode61` FTS, per the downstream contract.
|
|
115
|
+
|
|
116
|
+
## Stages
|
|
117
|
+
|
|
118
|
+
| Command | Stage | Idempotency |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `ragpages ocr` | PDF → per-page OCR text + boxes + confidence + provenance | per book, resumable |
|
|
121
|
+
| `ragpages extract` | text layer (or OCR fallback) → per-source db + manifest | overwrites the source db |
|
|
122
|
+
| `ragpages chapter` | header/回 OCR JSONL → `toc` rows (via the public `classics-index` package) | per source+book |
|
|
123
|
+
| `ragpages meta` | validate + copy `book_meta.json` (never generates it) | overwrites the copy |
|
|
124
|
+
| `ragpages search` | per-source dbs → `search.db` + FTS + eval | overwrites |
|
|
125
|
+
| `ragpages validate` | artifacts vs contract | read-only |
|
|
126
|
+
| `ragpages build` | extract + search | overall re-run |
|
|
127
|
+
| `ragpages selftest` | synthetic PDF → extract → search → validate | scratch only |
|
|
128
|
+
|
|
129
|
+
### OCR engines
|
|
130
|
+
|
|
131
|
+
`ocr.engine` picks an adapter at runtime; a missing package/model is a readable error,
|
|
132
|
+
not an ImportError traceback.
|
|
133
|
+
|
|
134
|
+
| Engine | Extra | Notes |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `rapidocr` | `pip install ragpages[rapid]` | PP-OCRv4 ONNX, cpu/dml; the default |
|
|
137
|
+
| `kraken` | `pip install ragpages[kraken]` | polytonic Greek / Latin scans (own venv recommended) |
|
|
138
|
+
| `paddle` | `pip install ragpages[paddle]` | comparison use only, not wired |
|
|
139
|
+
| `deepseek-api` | — | network OCR, opt-in only |
|
|
140
|
+
|
|
141
|
+
### Chapter stage
|
|
142
|
+
|
|
143
|
+
`ragpages chapter` builds the `toc` table from header/回 OCR JSONL. The pure chapter
|
|
144
|
+
logic lives in the public [`classics-index`](https://pypi.org/project/classics-index/)
|
|
145
|
+
package (>= 0.1): install it next to ragpages (`pip install classics-index`) when you
|
|
146
|
+
use this stage.
|
|
147
|
+
|
|
148
|
+
## License notes
|
|
149
|
+
|
|
150
|
+
- ragpages code: MIT.
|
|
151
|
+
- `pypdfium2`: BSD/Apache — the default parser is freely distributable.
|
|
152
|
+
- `pymupdf`: AGPL — opt-in extra; only enable where your deployment accepts that.
|
|
153
|
+
- OCR models are local artifacts: they never ship with the package, only their sha256
|
|
154
|
+
enters the provenance records.
|
|
155
|
+
|
|
156
|
+
## 中文摘要
|
|
157
|
+
|
|
158
|
+
ragpages 是一条**单机一条命令**的轻量管线:输入 PDF 目录(有文本层直接抽取,无文本层走可插拔
|
|
159
|
+
OCR 阶段),输出符合经典 RAG 数据库契约的 SQLite 产物(`documents` / `chunks` /
|
|
160
|
+
`chunks_fts` / `toc` 表 + manifest 与评测文件),可直接交给下游 Agent 运行时做检索、
|
|
161
|
+
引用与回页。对比 MinerU 这类服务化重型管线,ragpages 只有 CLI、零服务、零云端依赖,
|
|
162
|
+
模型不进仓库只记 sha256;默认解析器 pypdfium2(BSD/Apache),PyMuPDF(AGPL)仅作可选。
|
|
163
|
+
配置全部走 `pipeline.yaml` profile + `RAGPAGES_CONFIG` / `RAGPAGES_DATA` 环境变量,
|
|
164
|
+
代码中不含任何机器/私有路径。
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ragpages"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "One command turns a PDF/scan library into a citation-grade SQLite database for agents: every chunk keeps its page, locator and provenance."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [{name = "ragpages contributors"}]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
keywords = ["rag", "pdf", "ocr", "sqlite", "citation", "provenance", "pipeline", "agent", "fts"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Database",
|
|
21
|
+
"Topic :: Text Processing",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"PyYAML>=6.0",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
pdfium = ["pypdfium2>=4.30"]
|
|
29
|
+
mupdf = ["pymupdf>=1.24"]
|
|
30
|
+
rapid = ["rapidocr-onnxruntime"]
|
|
31
|
+
kraken = ["kraken"]
|
|
32
|
+
paddle = ["paddleocr"]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/Icefox12138/ragpages"
|
|
36
|
+
Repository = "https://github.com/Icefox12138/ragpages"
|
|
37
|
+
Issues = "https://github.com/Icefox12138/ragpages/issues"
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
ragpages = "ragpages.cli:main"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools]
|
|
43
|
+
packages = ["ragpages", "ragpages.ocr"]
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.package-data]
|
|
46
|
+
ragpages = ["pipeline.yaml"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""ragpages: PDF (+ OCR) -> data contract -> database for agents.
|
|
2
|
+
|
|
3
|
+
A lightweight, single-machine producer pipeline. It consumes PDFs (with a text
|
|
4
|
+
layer, or via an OCR stage) and emits SQLite artifacts that follow a classic
|
|
5
|
+
RAG database contract:
|
|
6
|
+
|
|
7
|
+
<data>/indexes/<source>.db documents + chunks + chunks_fts (per source)
|
|
8
|
+
<data>/indexes/search.db fused chunks (with `source` column) + chunks_fts
|
|
9
|
+
<data>/indexes/*-manifest.json
|
|
10
|
+
<data>/ocr/<book_id>/pages.jsonl OCR stage output (optional)
|
|
11
|
+
|
|
12
|
+
Everything is driven by `pipeline.yaml` profiles; no code path names a corpus
|
|
13
|
+
directory. See README.md.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Chapter stage: header / 回 OCR -> `toc` rows, via `classics-index` only.
|
|
2
|
+
|
|
3
|
+
No runtime import: the pure logic is the published package `classics-index`
|
|
4
|
+
(PyPI, >= 0.1), the storage is `ragpages.toc_store`. A downstream RAG runtime
|
|
5
|
+
keeps reading the same `toc` table.
|
|
6
|
+
|
|
7
|
+
Inputs (JSONL, one record per page):
|
|
8
|
+
headers: {"page": 12, "vol": 3} or {"page": 12, "lines": [{"text": ...}]}
|
|
9
|
+
hui: {"page": 12, "texts": ["第五十九回", "唐三藏路阻火焰山"]}
|
|
10
|
+
"""
|
|
11
|
+
import json
|
|
12
|
+
|
|
13
|
+
from classics_index import core, hui
|
|
14
|
+
|
|
15
|
+
from . import toc_store
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _vol(rec):
|
|
19
|
+
vol = rec.get("vol")
|
|
20
|
+
if vol is not None:
|
|
21
|
+
return core.cn2int(vol) if isinstance(vol, str) else int(vol)
|
|
22
|
+
lines = rec.get("lines") or ([{"text": rec["text"]}] if rec.get("text") else [])
|
|
23
|
+
return core.volume_of(lines)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _lines(rec):
|
|
27
|
+
return rec.get("lines") or ([{"text": rec["text"]}] if rec.get("text") else [])
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def rows_from_headers(records, min_run=5):
|
|
31
|
+
"""卷/篇 rows: contiguous page ranges, 篇 names attached where a page has one."""
|
|
32
|
+
records = [r for r in records if r.get("page")]
|
|
33
|
+
pages = {int(r["page"]): _lines(r) for r in records}
|
|
34
|
+
vols = {int(r["page"]): _vol(r) for r in records}
|
|
35
|
+
chapters = core.build_from_volumes(core.clean_volumes(vols, min_run=min_run))
|
|
36
|
+
chapters = core.enrich(chapters, pages)
|
|
37
|
+
return chapters, {"pages": len(records), "min_run": min_run}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def rows_from_hui(records, names=None):
|
|
41
|
+
"""回 rows for one or more novels; `names` maps book number -> title."""
|
|
42
|
+
books = hui.build(records, names=names or {})
|
|
43
|
+
rows = []
|
|
44
|
+
for book_no, part in enumerate(books, 1):
|
|
45
|
+
for r in part:
|
|
46
|
+
rows.append({
|
|
47
|
+
"ord": len(rows), "level": 2,
|
|
48
|
+
"title": r.get("title_text") or r.get("title") or "回%d" % r["num"],
|
|
49
|
+
"page_start": r["page_start"], "page_end": r["page_end"],
|
|
50
|
+
"volume": None, "pages": r["page_end"] - r["page_start"] + 1,
|
|
51
|
+
"book": book_no, "num": r["num"],
|
|
52
|
+
})
|
|
53
|
+
return rows, {"pages": len(records), "books": len(books), "replies": len(rows)}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def rows_from_toc(data):
|
|
57
|
+
"""Import an already-built toc JSON ({"chapters": [...]} or a list)."""
|
|
58
|
+
rows = data.get("chapters") if isinstance(data, dict) else data
|
|
59
|
+
rows = list(rows or [])
|
|
60
|
+
for i, row in enumerate(rows):
|
|
61
|
+
row.setdefault("ord", i)
|
|
62
|
+
row.setdefault("level", 1)
|
|
63
|
+
row.setdefault("pages", row["page_end"] - row["page_start"] + 1)
|
|
64
|
+
return rows, {"rows": len(rows)}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def write(db, source, book, rows, meta=None):
|
|
68
|
+
return toc_store.save(source, book, rows, meta=meta, path=db)
|