ragrock 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 (105) hide show
  1. ragrock-0.1.0/.gitignore +26 -0
  2. ragrock-0.1.0/LICENSE +21 -0
  3. ragrock-0.1.0/PKG-INFO +193 -0
  4. ragrock-0.1.0/README.md +145 -0
  5. ragrock-0.1.0/docs/_static/custom.css +13 -0
  6. ragrock-0.1.0/docs/_templates/.gitkeep +0 -0
  7. ragrock-0.1.0/docs/architecture/concurrency.rst +754 -0
  8. ragrock-0.1.0/docs/architecture/evaluation.rst +267 -0
  9. ragrock-0.1.0/docs/architecture/extraction.rst +212 -0
  10. ragrock-0.1.0/docs/architecture/index.rst +109 -0
  11. ragrock-0.1.0/docs/architecture/pipeline.rst +215 -0
  12. ragrock-0.1.0/docs/architecture/registry.rst +262 -0
  13. ragrock-0.1.0/docs/architecture/stages.rst +180 -0
  14. ragrock-0.1.0/docs/conf.py +90 -0
  15. ragrock-0.1.0/docs/getting_started.rst +76 -0
  16. ragrock-0.1.0/docs/index.rst +57 -0
  17. ragrock-0.1.0/docs/reference/cli.rst +120 -0
  18. ragrock-0.1.0/docs/reference/config.rst +159 -0
  19. ragrock-0.1.0/docs/reference/evaluation.rst +158 -0
  20. ragrock-0.1.0/docs/reference/extractor.rst +42 -0
  21. ragrock-0.1.0/docs/reference/extractors.rst +124 -0
  22. ragrock-0.1.0/docs/reference/index.rst +68 -0
  23. ragrock-0.1.0/docs/reference/llm.rst +46 -0
  24. ragrock-0.1.0/docs/reference/logging.rst +20 -0
  25. ragrock-0.1.0/docs/reference/models.rst +131 -0
  26. ragrock-0.1.0/docs/reference/pipeline.rst +56 -0
  27. ragrock-0.1.0/docs/reference/stages.rst +145 -0
  28. ragrock-0.1.0/docs/reference/utils.rst +31 -0
  29. ragrock-0.1.0/docs/tutorials/evaluation.rst +235 -0
  30. ragrock-0.1.0/docs/tutorials/index.rst +82 -0
  31. ragrock-0.1.0/docs/tutorials/new_format.rst +331 -0
  32. ragrock-0.1.0/docs/tutorials/pdf_01_first_extraction.rst +176 -0
  33. ragrock-0.1.0/docs/tutorials/pdf_02_strategies.rst +164 -0
  34. ragrock-0.1.0/docs/tutorials/pdf_03_llm.rst +178 -0
  35. ragrock-0.1.0/docs/tutorials/pdf_04_cleaning.rst +100 -0
  36. ragrock-0.1.0/docs/tutorials/pdf_05_batch.rst +202 -0
  37. ragrock-0.1.0/docs/tutorials/pdf_06_custom_pipeline.rst +231 -0
  38. ragrock-0.1.0/docs/tutorials/pdf_07_from_internet.rst +199 -0
  39. ragrock-0.1.0/examples/async_pipeline.py +118 -0
  40. ragrock-0.1.0/examples/custom_extractors.py +226 -0
  41. ragrock-0.1.0/examples/epub_extractor.py +213 -0
  42. ragrock-0.1.0/examples/evaluation_01_sync_pipeline.py +120 -0
  43. ragrock-0.1.0/examples/evaluation_02_async_retrieval.py +199 -0
  44. ragrock-0.1.0/examples/evaluation_03_parallel_replay.py +144 -0
  45. ragrock-0.1.0/examples/evaluation_04_custom_reporters.py +153 -0
  46. ragrock-0.1.0/examples/evaluation_05_ragas.py +116 -0
  47. ragrock-0.1.0/examples/evaluation_corpus.py +85 -0
  48. ragrock-0.1.0/examples/git_repo_extractor.py +284 -0
  49. ragrock-0.1.0/examples/html_url_pipeline.py +100 -0
  50. ragrock-0.1.0/examples/parallel_pipeline.py +139 -0
  51. ragrock-0.1.0/examples/pdf_parallel_extract.py +129 -0
  52. ragrock-0.1.0/examples/pdf_url_pipeline.py +251 -0
  53. ragrock-0.1.0/examples/sync_pipeline.py +81 -0
  54. ragrock-0.1.0/pyproject.toml +130 -0
  55. ragrock-0.1.0/src/ragrock/__init__.py +52 -0
  56. ragrock-0.1.0/src/ragrock/__main__.py +7 -0
  57. ragrock-0.1.0/src/ragrock/cli.py +308 -0
  58. ragrock-0.1.0/src/ragrock/config.py +119 -0
  59. ragrock-0.1.0/src/ragrock/evaluation/__init__.py +64 -0
  60. ragrock-0.1.0/src/ragrock/evaluation/evaluator.py +263 -0
  61. ragrock-0.1.0/src/ragrock/evaluation/options.py +117 -0
  62. ragrock-0.1.0/src/ragrock/evaluation/replay.py +160 -0
  63. ragrock-0.1.0/src/ragrock/evaluation/reporter.py +124 -0
  64. ragrock-0.1.0/src/ragrock/evaluation/session.py +115 -0
  65. ragrock-0.1.0/src/ragrock/evaluation/summary.py +274 -0
  66. ragrock-0.1.0/src/ragrock/extractor.py +192 -0
  67. ragrock-0.1.0/src/ragrock/extractors/__init__.py +14 -0
  68. ragrock-0.1.0/src/ragrock/extractors/base.py +286 -0
  69. ragrock-0.1.0/src/ragrock/extractors/docx.py +228 -0
  70. ragrock-0.1.0/src/ragrock/extractors/html.py +356 -0
  71. ragrock-0.1.0/src/ragrock/extractors/pdf.py +703 -0
  72. ragrock-0.1.0/src/ragrock/extractors/registry.py +236 -0
  73. ragrock-0.1.0/src/ragrock/extractors/xml.py +222 -0
  74. ragrock-0.1.0/src/ragrock/llm.py +137 -0
  75. ragrock-0.1.0/src/ragrock/log.py +132 -0
  76. ragrock-0.1.0/src/ragrock/metrics.py +206 -0
  77. ragrock-0.1.0/src/ragrock/models.py +173 -0
  78. ragrock-0.1.0/src/ragrock/pipeline.py +547 -0
  79. ragrock-0.1.0/src/ragrock/py.typed +0 -0
  80. ragrock-0.1.0/src/ragrock/stage/__init__.py +49 -0
  81. ragrock-0.1.0/src/ragrock/stage/clean.py +138 -0
  82. ragrock-0.1.0/src/ragrock/stage/detect.py +53 -0
  83. ragrock-0.1.0/src/ragrock/stage/extract.py +131 -0
  84. ragrock-0.1.0/src/ragrock/stage/job.py +39 -0
  85. ragrock-0.1.0/src/ragrock/stage/load.py +47 -0
  86. ragrock-0.1.0/src/ragrock/stage/stage.py +183 -0
  87. ragrock-0.1.0/src/ragrock/utils.py +117 -0
  88. ragrock-0.1.0/tests/__init__.py +0 -0
  89. ragrock-0.1.0/tests/conftest.py +305 -0
  90. ragrock-0.1.0/tests/test_async_extract.py +280 -0
  91. ragrock-0.1.0/tests/test_base.py +177 -0
  92. ragrock-0.1.0/tests/test_clean.py +78 -0
  93. ragrock-0.1.0/tests/test_cli.py +245 -0
  94. ragrock-0.1.0/tests/test_docx.py +162 -0
  95. ragrock-0.1.0/tests/test_evaluation.py +714 -0
  96. ragrock-0.1.0/tests/test_extractor.py +154 -0
  97. ragrock-0.1.0/tests/test_html.py +153 -0
  98. ragrock-0.1.0/tests/test_llm.py +131 -0
  99. ragrock-0.1.0/tests/test_log.py +56 -0
  100. ragrock-0.1.0/tests/test_models_config.py +104 -0
  101. ragrock-0.1.0/tests/test_pdf.py +448 -0
  102. ragrock-0.1.0/tests/test_pipeline.py +260 -0
  103. ragrock-0.1.0/tests/test_registry.py +104 -0
  104. ragrock-0.1.0/tests/test_utils.py +124 -0
  105. ragrock-0.1.0/tests/test_xml.py +128 -0
@@ -0,0 +1,26 @@
1
+ .pytest_cache
2
+ .venv
3
+ __pycache__
4
+ *.pyc
5
+
6
+ # test / coverage artifacts
7
+ .coverage
8
+ .coverage.*
9
+ htmlcov/
10
+ coverage.xml
11
+
12
+ # build
13
+ dist/
14
+ build/
15
+ *.egg-info/
16
+ .DS_Store
17
+ .vscode
18
+
19
+ # docs
20
+ docs/_build/
21
+ /.idea/inspectionProfiles/profiles_settings.xml
22
+ /.idea/.gitignore
23
+ /.idea/misc.xml
24
+ /.idea/modules.xml
25
+ /.idea/ragrock.iml
26
+ /.idea/vcs.xml
ragrock-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vishesh Panchal
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.
ragrock-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,193 @@
1
+ Metadata-Version: 2.5
2
+ Name: ragrock
3
+ Version: 0.1.0
4
+ Summary: PDF / DOCX / HTML / XML -> clean markdown + text for RAG pipelines.
5
+ Project-URL: Homepage, https://github.com/visheshpanchal/ragrock
6
+ Project-URL: Source, https://github.com/visheshpanchal/ragrock
7
+ Project-URL: Issues, https://github.com/visheshpanchal/ragrock/issues
8
+ Author: Vishesh Panchal
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: docx,extraction,html,llm,markdown,ocr,pdf,rag,xml
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Text Processing
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: beautifulsoup4>=4.12
25
+ Requires-Dist: defusedxml>=0.7
26
+ Requires-Dist: loguru>=0.7
27
+ Requires-Dist: lxml>=5.0
28
+ Requires-Dist: pillow>=10.0
29
+ Requires-Dist: pydantic>=2.5
30
+ Requires-Dist: pymupdf>=1.24
31
+ Requires-Dist: pytesseract>=0.3.10
32
+ Requires-Dist: python-docx>=1.1
33
+ Provides-Extra: dev
34
+ Requires-Dist: coverage[toml]>=7.4; extra == 'dev'
35
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
36
+ Requires-Dist: pytest>=8.0; extra == 'dev'
37
+ Requires-Dist: ruff>=0.6; extra == 'dev'
38
+ Provides-Extra: docs
39
+ Requires-Dist: httpx>=0.27; extra == 'docs'
40
+ Requires-Dist: pydata-sphinx-theme>=0.16; extra == 'docs'
41
+ Requires-Dist: sphinx-copybutton>=0.5; extra == 'docs'
42
+ Requires-Dist: sphinx-design>=0.6; extra == 'docs'
43
+ Requires-Dist: sphinx>=8.1; extra == 'docs'
44
+ Requires-Dist: sphinxcontrib-mermaid>=1.0; extra == 'docs'
45
+ Provides-Extra: llm
46
+ Requires-Dist: openrouter>=1.3; extra == 'llm'
47
+ Description-Content-Type: text/markdown
48
+
49
+ <h1 align="center">ragrock</h1>
50
+
51
+ <h3 align="center">
52
+ An end-to-end framework for building RAG systems: from document extraction to retrieval, generation and evaluation
53
+ </h3>
54
+
55
+ <p align="center">
56
+ <img alt="Python" src="https://img.shields.io/badge/python-3.11%2B-blue">
57
+ <img alt="Pydantic v2" src="https://img.shields.io/badge/pydantic-v2-e92063">
58
+ <img alt="Tests" src="https://img.shields.io/badge/tests-pytest-0a9edc">
59
+ </p>
60
+
61
+ <p align="center">
62
+ | <a href="#installation"><b>Installation</b></a>
63
+ | <a href="#quickstart"><b>Quickstart</b></a>
64
+ | <a href="#development"><b>Development</b></a> |
65
+ </p>
66
+
67
+ ---
68
+
69
+ ragrock is an end-to-end framework for building retrieval-augmented generation (RAG) systems. Document extraction (PDF, DOCX, HTML and XML to clean Markdown and text) is available today; chunking, retrieval, generation and evaluation metrics are on the way.
70
+
71
+ ## Installation
72
+
73
+ ragrock needs Python 3.11 or newer. Install it from PyPI:
74
+
75
+ ```bash
76
+ pip install ragrock # core
77
+ pip install "ragrock[llm]" # + OpenRouter vision client
78
+ ```
79
+
80
+ To work on ragrock itself, install it from source:
81
+
82
+ ```bash
83
+ git clone https://github.com/visheshpanchal/ragrock.git
84
+ cd ragrock
85
+ pip install -e ".[dev]"
86
+ ```
87
+
88
+ To OCR scanned pages you also need the Tesseract binary:
89
+
90
+ ```bash
91
+ brew install tesseract # macOS
92
+ sudo apt install tesseract-ocr # Debian / Ubuntu
93
+ sudo apt install tesseract-ocr-hin # extra language packs as needed
94
+ ```
95
+
96
+ Without Tesseract, digital PDFs and the other formats still work. Scanned pages go to the LLM if one is configured. Otherwise they come back empty with a warning.
97
+
98
+ ## Quickstart
99
+
100
+ ```python
101
+ from ragrock import DocumentExtractor
102
+
103
+ extractor = DocumentExtractor()
104
+ doc = extractor.extract("report.pdf")
105
+
106
+ doc.markdown # whole document as Markdown
107
+ doc.text # plain text
108
+ doc.confidence # 0-1, character-weighted over pages
109
+ doc.metadata.title # title, author, dates, page_count, sha256, ...
110
+
111
+ for page in doc.pages:
112
+ print(page.page_number, page.method, page.confidence)
113
+
114
+ for el in doc.elements: # reading order, ready for chunking
115
+ print(el.type, el.level, el.page_number, el.markdown[:60])
116
+ ```
117
+
118
+ Paths, raw `bytes` and binary file objects are all accepted:
119
+
120
+ ```python
121
+ with open("policy.docx", "rb") as fh:
122
+ doc = extractor.extract(fh.read(), file_name="policy.docx", extra_metadata={"tenant": "acme"})
123
+
124
+ docs = extractor.extract_directory("./data", recursive=True, max_workers=4)
125
+ ```
126
+
127
+ More examples are in [examples/](https://github.com/visheshpanchal/ragrock/tree/main/examples).
128
+
129
+ ## Evaluation
130
+
131
+ Evaluation is off by default. When you turn it on, every stage reports its
132
+ own stats and evaluators score each item after the last stage. Stage code is
133
+ the same with evaluation on or off:
134
+
135
+ ```python
136
+ from ragrock.evaluation import EvalOptions, Evaluator, Labeled, capture, record
137
+
138
+ class Retrieve(AsyncStage):
139
+ async def process(self, q):
140
+ hits = await index.search(q["text"], k=5)
141
+ record("top_score", hits[0].score) # no-op when evaluation is off
142
+ capture("retrieved_ids", [h.id for h in hits]) # kept only in mode="full"
143
+ return hits
144
+
145
+ class RecallAtK(Evaluator):
146
+ requires = {"Retrieve": ["retrieved_ids"]}
147
+ def evaluate(self, item, trace): # may also be async (LLM judge, ragas)
148
+ got, want = set(trace.captured("Retrieve", "retrieved_ids")), set(trace.labels["relevant"])
149
+ return {"recall": len(got & want) / len(want)}
150
+
151
+ pipe = Pipeline(Embed(), Retrieve(), evaluators=[RecallAtK()], reporters=[MyDashboard()])
152
+ pipe.collect_sync(queries) # off (or RAGROCK_EVAL=1)
153
+ pipe.collect_sync([Labeled(q, {"relevant": [...]}) for q in queries], EvalOptions(evaluate=True))
154
+ print(pipe.last_summary.table())
155
+ ```
156
+
157
+ This works the same with sync, async and parallel stages. Reporters (log,
158
+ JSONL, or your own CSV, dashboard or webhook) receive the summary, and a
159
+ saved run can be re-scored later with `replay()` or from the terminal:
160
+
161
+ ```bash
162
+ ragrock show runs/base.jsonl
163
+ ragrock eval runs/base.jsonl -e mypkg.evals:RecallAtK --min-score RecallAtK.recall=0.8 # exit 1 if below
164
+ ```
165
+
166
+ See
167
+ `examples/evaluation_*.py` and the *Evaluating a pipeline* tutorial.
168
+
169
+ ## Format notes
170
+
171
+ | Format | Notes |
172
+ |---|---|
173
+ | **PDF** | Headings come from font size and bold text. Ruled tables become Markdown tables. Repeated headers, footers and page numbers are removed. The outline goes to `metadata.extra["toc"]`. Encrypted files need `pdf_password`. |
174
+ | **DOCX** | Paragraphs and tables stay in body order. Title and Heading styles, list numbering (ordered or bulleted), bold, italic, quote and code styles are mapped. Merged cells are handled. Embedded images are counted but not OCR'd. |
175
+ | **HTML** | Boilerplate is removed. `<main>` or `<article>` content is preferred. Nested lists, tables (`colspan`, `<thead>`, captions), code blocks with their language and `<meta>` tags are handled. |
176
+ | **XML** | Parsed with `defusedxml`. Container elements become headings, and runs of repeated record-like elements become tables. XHTML is passed to the HTML extractor. |
177
+
178
+ ## Known limitations
179
+
180
+ - Tables **without drawn borders** are not detected as tables in the native or OCR paths. Their cells come out as plain text. Use `llm` mode for table-heavy scans.
181
+ - An LLM's self-reported confidence is an estimate. Check it against `page.metadata["agreement_with_previous"]`.
182
+ - DOCX embedded images are not OCR'd.
183
+
184
+ ## Development
185
+
186
+ ```bash
187
+ pip install -e ".[dev]" # pytest, pytest-cov, coverage
188
+ pytest # runs the suite with coverage (term + htmlcov/ + coverage.xml)
189
+ pytest --no-cov -q # faster, no coverage
190
+ open htmlcov/index.html # browse line-by-line coverage
191
+ ```
192
+
193
+ The test suite builds its PDFs, DOCX files and markup in memory, so there are no binary fixtures. OCR is faked by default. Tests marked `@pytest.mark.tesseract` run against the real Tesseract binary and are skipped when it isn't installed. The build fails if coverage drops below the `fail_under` value in `pyproject.toml`.
@@ -0,0 +1,145 @@
1
+ <h1 align="center">ragrock</h1>
2
+
3
+ <h3 align="center">
4
+ An end-to-end framework for building RAG systems: from document extraction to retrieval, generation and evaluation
5
+ </h3>
6
+
7
+ <p align="center">
8
+ <img alt="Python" src="https://img.shields.io/badge/python-3.11%2B-blue">
9
+ <img alt="Pydantic v2" src="https://img.shields.io/badge/pydantic-v2-e92063">
10
+ <img alt="Tests" src="https://img.shields.io/badge/tests-pytest-0a9edc">
11
+ </p>
12
+
13
+ <p align="center">
14
+ | <a href="#installation"><b>Installation</b></a>
15
+ | <a href="#quickstart"><b>Quickstart</b></a>
16
+ | <a href="#development"><b>Development</b></a> |
17
+ </p>
18
+
19
+ ---
20
+
21
+ ragrock is an end-to-end framework for building retrieval-augmented generation (RAG) systems. Document extraction (PDF, DOCX, HTML and XML to clean Markdown and text) is available today; chunking, retrieval, generation and evaluation metrics are on the way.
22
+
23
+ ## Installation
24
+
25
+ ragrock needs Python 3.11 or newer. Install it from PyPI:
26
+
27
+ ```bash
28
+ pip install ragrock # core
29
+ pip install "ragrock[llm]" # + OpenRouter vision client
30
+ ```
31
+
32
+ To work on ragrock itself, install it from source:
33
+
34
+ ```bash
35
+ git clone https://github.com/visheshpanchal/ragrock.git
36
+ cd ragrock
37
+ pip install -e ".[dev]"
38
+ ```
39
+
40
+ To OCR scanned pages you also need the Tesseract binary:
41
+
42
+ ```bash
43
+ brew install tesseract # macOS
44
+ sudo apt install tesseract-ocr # Debian / Ubuntu
45
+ sudo apt install tesseract-ocr-hin # extra language packs as needed
46
+ ```
47
+
48
+ Without Tesseract, digital PDFs and the other formats still work. Scanned pages go to the LLM if one is configured. Otherwise they come back empty with a warning.
49
+
50
+ ## Quickstart
51
+
52
+ ```python
53
+ from ragrock import DocumentExtractor
54
+
55
+ extractor = DocumentExtractor()
56
+ doc = extractor.extract("report.pdf")
57
+
58
+ doc.markdown # whole document as Markdown
59
+ doc.text # plain text
60
+ doc.confidence # 0-1, character-weighted over pages
61
+ doc.metadata.title # title, author, dates, page_count, sha256, ...
62
+
63
+ for page in doc.pages:
64
+ print(page.page_number, page.method, page.confidence)
65
+
66
+ for el in doc.elements: # reading order, ready for chunking
67
+ print(el.type, el.level, el.page_number, el.markdown[:60])
68
+ ```
69
+
70
+ Paths, raw `bytes` and binary file objects are all accepted:
71
+
72
+ ```python
73
+ with open("policy.docx", "rb") as fh:
74
+ doc = extractor.extract(fh.read(), file_name="policy.docx", extra_metadata={"tenant": "acme"})
75
+
76
+ docs = extractor.extract_directory("./data", recursive=True, max_workers=4)
77
+ ```
78
+
79
+ More examples are in [examples/](https://github.com/visheshpanchal/ragrock/tree/main/examples).
80
+
81
+ ## Evaluation
82
+
83
+ Evaluation is off by default. When you turn it on, every stage reports its
84
+ own stats and evaluators score each item after the last stage. Stage code is
85
+ the same with evaluation on or off:
86
+
87
+ ```python
88
+ from ragrock.evaluation import EvalOptions, Evaluator, Labeled, capture, record
89
+
90
+ class Retrieve(AsyncStage):
91
+ async def process(self, q):
92
+ hits = await index.search(q["text"], k=5)
93
+ record("top_score", hits[0].score) # no-op when evaluation is off
94
+ capture("retrieved_ids", [h.id for h in hits]) # kept only in mode="full"
95
+ return hits
96
+
97
+ class RecallAtK(Evaluator):
98
+ requires = {"Retrieve": ["retrieved_ids"]}
99
+ def evaluate(self, item, trace): # may also be async (LLM judge, ragas)
100
+ got, want = set(trace.captured("Retrieve", "retrieved_ids")), set(trace.labels["relevant"])
101
+ return {"recall": len(got & want) / len(want)}
102
+
103
+ pipe = Pipeline(Embed(), Retrieve(), evaluators=[RecallAtK()], reporters=[MyDashboard()])
104
+ pipe.collect_sync(queries) # off (or RAGROCK_EVAL=1)
105
+ pipe.collect_sync([Labeled(q, {"relevant": [...]}) for q in queries], EvalOptions(evaluate=True))
106
+ print(pipe.last_summary.table())
107
+ ```
108
+
109
+ This works the same with sync, async and parallel stages. Reporters (log,
110
+ JSONL, or your own CSV, dashboard or webhook) receive the summary, and a
111
+ saved run can be re-scored later with `replay()` or from the terminal:
112
+
113
+ ```bash
114
+ ragrock show runs/base.jsonl
115
+ ragrock eval runs/base.jsonl -e mypkg.evals:RecallAtK --min-score RecallAtK.recall=0.8 # exit 1 if below
116
+ ```
117
+
118
+ See
119
+ `examples/evaluation_*.py` and the *Evaluating a pipeline* tutorial.
120
+
121
+ ## Format notes
122
+
123
+ | Format | Notes |
124
+ |---|---|
125
+ | **PDF** | Headings come from font size and bold text. Ruled tables become Markdown tables. Repeated headers, footers and page numbers are removed. The outline goes to `metadata.extra["toc"]`. Encrypted files need `pdf_password`. |
126
+ | **DOCX** | Paragraphs and tables stay in body order. Title and Heading styles, list numbering (ordered or bulleted), bold, italic, quote and code styles are mapped. Merged cells are handled. Embedded images are counted but not OCR'd. |
127
+ | **HTML** | Boilerplate is removed. `<main>` or `<article>` content is preferred. Nested lists, tables (`colspan`, `<thead>`, captions), code blocks with their language and `<meta>` tags are handled. |
128
+ | **XML** | Parsed with `defusedxml`. Container elements become headings, and runs of repeated record-like elements become tables. XHTML is passed to the HTML extractor. |
129
+
130
+ ## Known limitations
131
+
132
+ - Tables **without drawn borders** are not detected as tables in the native or OCR paths. Their cells come out as plain text. Use `llm` mode for table-heavy scans.
133
+ - An LLM's self-reported confidence is an estimate. Check it against `page.metadata["agreement_with_previous"]`.
134
+ - DOCX embedded images are not OCR'd.
135
+
136
+ ## Development
137
+
138
+ ```bash
139
+ pip install -e ".[dev]" # pytest, pytest-cov, coverage
140
+ pytest # runs the suite with coverage (term + htmlcov/ + coverage.xml)
141
+ pytest --no-cov -q # faster, no coverage
142
+ open htmlcov/index.html # browse line-by-line coverage
143
+ ```
144
+
145
+ The test suite builds its PDFs, DOCX files and markup in memory, so there are no binary fixtures. OCR is faked by default. Tests marked `@pytest.mark.tesseract` run against the real Tesseract binary and are skipped when it isn't installed. The build fails if coverage drops below the `fail_under` value in `pyproject.toml`.
@@ -0,0 +1,13 @@
1
+ /* Keep Mermaid diagrams centred and readable in light and dark mode. */
2
+ .mermaid {
3
+ display: flex;
4
+ justify-content: center;
5
+ margin: 1.5rem 0;
6
+ }
7
+ html[data-theme="dark"] .mermaid svg {
8
+ filter: invert(0.88) hue-rotate(180deg);
9
+ }
10
+ /* Slightly tighter API tables. */
11
+ table.autosummary td {
12
+ padding: 0.25rem 0.5rem;
13
+ }
File without changes