kreuzberg 4.0.0.pre.rc.29 → 4.0.0.rc1

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 (321) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.rubocop.yaml +534 -1
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +28 -116
  6. data/README.md +269 -629
  7. data/Rakefile +0 -9
  8. data/Steepfile +4 -8
  9. data/examples/async_patterns.rb +58 -1
  10. data/ext/kreuzberg_rb/extconf.rb +5 -35
  11. data/ext/kreuzberg_rb/native/Cargo.toml +16 -55
  12. data/ext/kreuzberg_rb/native/build.rs +14 -12
  13. data/ext/kreuzberg_rb/native/include/ieeefp.h +1 -1
  14. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +1 -1
  15. data/ext/kreuzberg_rb/native/include/strings.h +2 -2
  16. data/ext/kreuzberg_rb/native/include/unistd.h +1 -1
  17. data/ext/kreuzberg_rb/native/src/lib.rs +34 -897
  18. data/extconf.rb +6 -38
  19. data/kreuzberg.gemspec +20 -114
  20. data/lib/kreuzberg/api_proxy.rb +18 -2
  21. data/lib/kreuzberg/cache_api.rb +0 -22
  22. data/lib/kreuzberg/cli.rb +10 -2
  23. data/lib/kreuzberg/cli_proxy.rb +10 -0
  24. data/lib/kreuzberg/config.rb +22 -274
  25. data/lib/kreuzberg/errors.rb +7 -73
  26. data/lib/kreuzberg/extraction_api.rb +8 -237
  27. data/lib/kreuzberg/mcp_proxy.rb +11 -2
  28. data/lib/kreuzberg/ocr_backend_protocol.rb +73 -0
  29. data/lib/kreuzberg/post_processor_protocol.rb +71 -0
  30. data/lib/kreuzberg/result.rb +33 -151
  31. data/lib/kreuzberg/setup_lib_path.rb +2 -22
  32. data/lib/kreuzberg/validator_protocol.rb +73 -0
  33. data/lib/kreuzberg/version.rb +1 -1
  34. data/lib/kreuzberg.rb +13 -27
  35. data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
  36. data/sig/kreuzberg.rbs +12 -105
  37. data/spec/binding/cache_spec.rb +22 -22
  38. data/spec/binding/cli_proxy_spec.rb +4 -2
  39. data/spec/binding/cli_spec.rb +11 -12
  40. data/spec/binding/config_spec.rb +0 -74
  41. data/spec/binding/config_validation_spec.rb +6 -100
  42. data/spec/binding/error_handling_spec.rb +97 -283
  43. data/spec/binding/plugins/ocr_backend_spec.rb +8 -8
  44. data/spec/binding/plugins/postprocessor_spec.rb +11 -11
  45. data/spec/binding/plugins/validator_spec.rb +13 -12
  46. data/spec/examples.txt +104 -0
  47. data/spec/fixtures/config.toml +1 -0
  48. data/spec/fixtures/config.yaml +1 -0
  49. data/spec/fixtures/invalid_config.toml +1 -0
  50. data/spec/smoke/package_spec.rb +3 -2
  51. data/spec/spec_helper.rb +3 -1
  52. data/vendor/kreuzberg/Cargo.toml +67 -192
  53. data/vendor/kreuzberg/README.md +9 -97
  54. data/vendor/kreuzberg/build.rs +194 -516
  55. data/vendor/kreuzberg/src/api/handlers.rs +9 -130
  56. data/vendor/kreuzberg/src/api/mod.rs +3 -18
  57. data/vendor/kreuzberg/src/api/server.rs +71 -236
  58. data/vendor/kreuzberg/src/api/types.rs +7 -43
  59. data/vendor/kreuzberg/src/bin/profile_extract.rs +455 -0
  60. data/vendor/kreuzberg/src/cache/mod.rs +3 -27
  61. data/vendor/kreuzberg/src/chunking/mod.rs +79 -1705
  62. data/vendor/kreuzberg/src/core/batch_mode.rs +0 -60
  63. data/vendor/kreuzberg/src/core/config.rs +23 -905
  64. data/vendor/kreuzberg/src/core/extractor.rs +106 -403
  65. data/vendor/kreuzberg/src/core/io.rs +2 -4
  66. data/vendor/kreuzberg/src/core/mime.rs +12 -2
  67. data/vendor/kreuzberg/src/core/mod.rs +3 -22
  68. data/vendor/kreuzberg/src/core/pipeline.rs +78 -395
  69. data/vendor/kreuzberg/src/embeddings.rs +21 -169
  70. data/vendor/kreuzberg/src/error.rs +2 -2
  71. data/vendor/kreuzberg/src/extraction/archive.rs +31 -36
  72. data/vendor/kreuzberg/src/extraction/docx.rs +1 -365
  73. data/vendor/kreuzberg/src/extraction/email.rs +11 -12
  74. data/vendor/kreuzberg/src/extraction/excel.rs +129 -138
  75. data/vendor/kreuzberg/src/extraction/html.rs +170 -1447
  76. data/vendor/kreuzberg/src/extraction/image.rs +14 -138
  77. data/vendor/kreuzberg/src/extraction/libreoffice.rs +3 -13
  78. data/vendor/kreuzberg/src/extraction/mod.rs +5 -21
  79. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +0 -2
  80. data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +275 -0
  81. data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +178 -0
  82. data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +491 -0
  83. data/vendor/kreuzberg/src/extraction/pandoc/server.rs +496 -0
  84. data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +1188 -0
  85. data/vendor/kreuzberg/src/extraction/pandoc/version.rs +162 -0
  86. data/vendor/kreuzberg/src/extraction/pptx.rs +94 -196
  87. data/vendor/kreuzberg/src/extraction/structured.rs +4 -5
  88. data/vendor/kreuzberg/src/extraction/table.rs +1 -2
  89. data/vendor/kreuzberg/src/extraction/text.rs +10 -18
  90. data/vendor/kreuzberg/src/extractors/archive.rs +0 -22
  91. data/vendor/kreuzberg/src/extractors/docx.rs +148 -69
  92. data/vendor/kreuzberg/src/extractors/email.rs +9 -37
  93. data/vendor/kreuzberg/src/extractors/excel.rs +40 -81
  94. data/vendor/kreuzberg/src/extractors/html.rs +173 -182
  95. data/vendor/kreuzberg/src/extractors/image.rs +8 -32
  96. data/vendor/kreuzberg/src/extractors/mod.rs +10 -171
  97. data/vendor/kreuzberg/src/extractors/pandoc.rs +201 -0
  98. data/vendor/kreuzberg/src/extractors/pdf.rs +64 -329
  99. data/vendor/kreuzberg/src/extractors/pptx.rs +34 -79
  100. data/vendor/kreuzberg/src/extractors/structured.rs +0 -16
  101. data/vendor/kreuzberg/src/extractors/text.rs +7 -30
  102. data/vendor/kreuzberg/src/extractors/xml.rs +8 -27
  103. data/vendor/kreuzberg/src/keywords/processor.rs +1 -9
  104. data/vendor/kreuzberg/src/keywords/rake.rs +1 -0
  105. data/vendor/kreuzberg/src/language_detection/mod.rs +51 -94
  106. data/vendor/kreuzberg/src/lib.rs +5 -17
  107. data/vendor/kreuzberg/src/mcp/mod.rs +1 -4
  108. data/vendor/kreuzberg/src/mcp/server.rs +21 -145
  109. data/vendor/kreuzberg/src/ocr/mod.rs +0 -2
  110. data/vendor/kreuzberg/src/ocr/processor.rs +8 -19
  111. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +0 -2
  112. data/vendor/kreuzberg/src/pdf/error.rs +1 -93
  113. data/vendor/kreuzberg/src/pdf/metadata.rs +100 -263
  114. data/vendor/kreuzberg/src/pdf/mod.rs +2 -33
  115. data/vendor/kreuzberg/src/pdf/rendering.rs +12 -12
  116. data/vendor/kreuzberg/src/pdf/table.rs +64 -61
  117. data/vendor/kreuzberg/src/pdf/text.rs +24 -416
  118. data/vendor/kreuzberg/src/plugins/extractor.rs +8 -40
  119. data/vendor/kreuzberg/src/plugins/mod.rs +0 -3
  120. data/vendor/kreuzberg/src/plugins/ocr.rs +14 -22
  121. data/vendor/kreuzberg/src/plugins/processor.rs +1 -10
  122. data/vendor/kreuzberg/src/plugins/registry.rs +0 -15
  123. data/vendor/kreuzberg/src/plugins/validator.rs +8 -20
  124. data/vendor/kreuzberg/src/stopwords/mod.rs +2 -2
  125. data/vendor/kreuzberg/src/text/mod.rs +0 -8
  126. data/vendor/kreuzberg/src/text/quality.rs +15 -28
  127. data/vendor/kreuzberg/src/text/string_utils.rs +10 -22
  128. data/vendor/kreuzberg/src/text/token_reduction/core.rs +50 -86
  129. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +16 -37
  130. data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +1 -2
  131. data/vendor/kreuzberg/src/types.rs +67 -907
  132. data/vendor/kreuzberg/src/utils/mod.rs +0 -14
  133. data/vendor/kreuzberg/src/utils/quality.rs +3 -12
  134. data/vendor/kreuzberg/tests/api_tests.rs +0 -506
  135. data/vendor/kreuzberg/tests/archive_integration.rs +0 -2
  136. data/vendor/kreuzberg/tests/batch_orchestration.rs +12 -57
  137. data/vendor/kreuzberg/tests/batch_processing.rs +8 -32
  138. data/vendor/kreuzberg/tests/chunking_offset_demo.rs +92 -0
  139. data/vendor/kreuzberg/tests/concurrency_stress.rs +8 -40
  140. data/vendor/kreuzberg/tests/config_features.rs +1 -33
  141. data/vendor/kreuzberg/tests/config_loading_tests.rs +39 -16
  142. data/vendor/kreuzberg/tests/core_integration.rs +9 -35
  143. data/vendor/kreuzberg/tests/csv_integration.rs +81 -71
  144. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +25 -23
  145. data/vendor/kreuzberg/tests/email_integration.rs +1 -3
  146. data/vendor/kreuzberg/tests/error_handling.rs +34 -43
  147. data/vendor/kreuzberg/tests/format_integration.rs +1 -7
  148. data/vendor/kreuzberg/tests/helpers/mod.rs +0 -60
  149. data/vendor/kreuzberg/tests/image_integration.rs +0 -2
  150. data/vendor/kreuzberg/tests/mime_detection.rs +16 -17
  151. data/vendor/kreuzberg/tests/ocr_configuration.rs +0 -4
  152. data/vendor/kreuzberg/tests/ocr_errors.rs +0 -22
  153. data/vendor/kreuzberg/tests/ocr_quality.rs +0 -2
  154. data/vendor/kreuzberg/tests/pandoc_integration.rs +503 -0
  155. data/vendor/kreuzberg/tests/pdf_integration.rs +0 -2
  156. data/vendor/kreuzberg/tests/pipeline_integration.rs +2 -36
  157. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +0 -5
  158. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +1 -17
  159. data/vendor/kreuzberg/tests/plugin_system.rs +0 -6
  160. data/vendor/kreuzberg/tests/registry_integration_tests.rs +22 -2
  161. data/vendor/kreuzberg/tests/security_validation.rs +1 -13
  162. data/vendor/kreuzberg/tests/test_fastembed.rs +23 -45
  163. metadata +25 -171
  164. data/.rubocop.yml +0 -543
  165. data/ext/kreuzberg_rb/native/.cargo/config.toml +0 -23
  166. data/ext/kreuzberg_rb/native/Cargo.lock +0 -7619
  167. data/lib/kreuzberg/error_context.rb +0 -136
  168. data/lib/kreuzberg/types.rb +0 -170
  169. data/lib/libpdfium.so +0 -0
  170. data/spec/binding/async_operations_spec.rb +0 -473
  171. data/spec/binding/batch_operations_spec.rb +0 -595
  172. data/spec/binding/batch_spec.rb +0 -359
  173. data/spec/binding/config_result_spec.rb +0 -377
  174. data/spec/binding/embeddings_spec.rb +0 -816
  175. data/spec/binding/error_recovery_spec.rb +0 -488
  176. data/spec/binding/font_config_spec.rb +0 -220
  177. data/spec/binding/images_spec.rb +0 -738
  178. data/spec/binding/keywords_extraction_spec.rb +0 -600
  179. data/spec/binding/metadata_types_spec.rb +0 -1228
  180. data/spec/binding/pages_extraction_spec.rb +0 -471
  181. data/spec/binding/tables_spec.rb +0 -641
  182. data/spec/unit/config/chunking_config_spec.rb +0 -213
  183. data/spec/unit/config/embedding_config_spec.rb +0 -343
  184. data/spec/unit/config/extraction_config_spec.rb +0 -438
  185. data/spec/unit/config/font_config_spec.rb +0 -285
  186. data/spec/unit/config/hierarchy_config_spec.rb +0 -314
  187. data/spec/unit/config/image_extraction_config_spec.rb +0 -209
  188. data/spec/unit/config/image_preprocessing_config_spec.rb +0 -249
  189. data/spec/unit/config/keyword_config_spec.rb +0 -229
  190. data/spec/unit/config/language_detection_config_spec.rb +0 -258
  191. data/spec/unit/config/ocr_config_spec.rb +0 -171
  192. data/spec/unit/config/page_config_spec.rb +0 -221
  193. data/spec/unit/config/pdf_config_spec.rb +0 -267
  194. data/spec/unit/config/postprocessor_config_spec.rb +0 -290
  195. data/spec/unit/config/tesseract_config_spec.rb +0 -181
  196. data/spec/unit/config/token_reduction_config_spec.rb +0 -251
  197. data/test/metadata_types_test.rb +0 -959
  198. data/vendor/Cargo.toml +0 -61
  199. data/vendor/kreuzberg/examples/bench_fixes.rs +0 -71
  200. data/vendor/kreuzberg/examples/test_pdfium_fork.rs +0 -62
  201. data/vendor/kreuzberg/src/chunking/processor.rs +0 -219
  202. data/vendor/kreuzberg/src/core/batch_optimizations.rs +0 -385
  203. data/vendor/kreuzberg/src/core/config_validation.rs +0 -949
  204. data/vendor/kreuzberg/src/core/formats.rs +0 -235
  205. data/vendor/kreuzberg/src/core/server_config.rs +0 -1220
  206. data/vendor/kreuzberg/src/extraction/capacity.rs +0 -263
  207. data/vendor/kreuzberg/src/extraction/markdown.rs +0 -216
  208. data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +0 -284
  209. data/vendor/kreuzberg/src/extractors/bibtex.rs +0 -470
  210. data/vendor/kreuzberg/src/extractors/docbook.rs +0 -504
  211. data/vendor/kreuzberg/src/extractors/epub.rs +0 -696
  212. data/vendor/kreuzberg/src/extractors/fictionbook.rs +0 -492
  213. data/vendor/kreuzberg/src/extractors/jats.rs +0 -1054
  214. data/vendor/kreuzberg/src/extractors/jupyter.rs +0 -368
  215. data/vendor/kreuzberg/src/extractors/latex.rs +0 -653
  216. data/vendor/kreuzberg/src/extractors/markdown.rs +0 -701
  217. data/vendor/kreuzberg/src/extractors/odt.rs +0 -628
  218. data/vendor/kreuzberg/src/extractors/opml.rs +0 -635
  219. data/vendor/kreuzberg/src/extractors/orgmode.rs +0 -529
  220. data/vendor/kreuzberg/src/extractors/rst.rs +0 -577
  221. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -809
  222. data/vendor/kreuzberg/src/extractors/security.rs +0 -484
  223. data/vendor/kreuzberg/src/extractors/security_tests.rs +0 -367
  224. data/vendor/kreuzberg/src/extractors/typst.rs +0 -651
  225. data/vendor/kreuzberg/src/language_detection/processor.rs +0 -218
  226. data/vendor/kreuzberg/src/ocr/language_registry.rs +0 -520
  227. data/vendor/kreuzberg/src/panic_context.rs +0 -154
  228. data/vendor/kreuzberg/src/pdf/bindings.rs +0 -306
  229. data/vendor/kreuzberg/src/pdf/bundled.rs +0 -408
  230. data/vendor/kreuzberg/src/pdf/fonts.rs +0 -358
  231. data/vendor/kreuzberg/src/pdf/hierarchy.rs +0 -903
  232. data/vendor/kreuzberg/src/text/quality_processor.rs +0 -231
  233. data/vendor/kreuzberg/src/text/utf8_validation.rs +0 -193
  234. data/vendor/kreuzberg/src/utils/pool.rs +0 -503
  235. data/vendor/kreuzberg/src/utils/pool_sizing.rs +0 -364
  236. data/vendor/kreuzberg/src/utils/string_pool.rs +0 -761
  237. data/vendor/kreuzberg/tests/api_embed.rs +0 -360
  238. data/vendor/kreuzberg/tests/api_extract_multipart.rs +0 -52
  239. data/vendor/kreuzberg/tests/api_large_pdf_extraction.rs +0 -471
  240. data/vendor/kreuzberg/tests/api_large_pdf_extraction_diagnostics.rs +0 -289
  241. data/vendor/kreuzberg/tests/batch_pooling_benchmark.rs +0 -154
  242. data/vendor/kreuzberg/tests/bibtex_parity_test.rs +0 -421
  243. data/vendor/kreuzberg/tests/config_integration_test.rs +0 -753
  244. data/vendor/kreuzberg/tests/data/hierarchy_ground_truth.json +0 -294
  245. data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +0 -500
  246. data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +0 -370
  247. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +0 -275
  248. data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +0 -228
  249. data/vendor/kreuzberg/tests/html_table_test.rs +0 -551
  250. data/vendor/kreuzberg/tests/instrumentation_test.rs +0 -139
  251. data/vendor/kreuzberg/tests/jats_extractor_tests.rs +0 -639
  252. data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +0 -704
  253. data/vendor/kreuzberg/tests/latex_extractor_tests.rs +0 -496
  254. data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +0 -490
  255. data/vendor/kreuzberg/tests/ocr_language_registry.rs +0 -191
  256. data/vendor/kreuzberg/tests/odt_extractor_tests.rs +0 -674
  257. data/vendor/kreuzberg/tests/opml_extractor_tests.rs +0 -616
  258. data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +0 -822
  259. data/vendor/kreuzberg/tests/page_markers.rs +0 -297
  260. data/vendor/kreuzberg/tests/pdf_hierarchy_detection.rs +0 -301
  261. data/vendor/kreuzberg/tests/pdf_hierarchy_quality.rs +0 -589
  262. data/vendor/kreuzberg/tests/pdf_ocr_triggering.rs +0 -301
  263. data/vendor/kreuzberg/tests/pdf_text_merging.rs +0 -475
  264. data/vendor/kreuzberg/tests/pdfium_linking.rs +0 -340
  265. data/vendor/kreuzberg/tests/rst_extractor_tests.rs +0 -694
  266. data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +0 -775
  267. data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +0 -1260
  268. data/vendor/kreuzberg/tests/typst_extractor_tests.rs +0 -648
  269. data/vendor/kreuzberg-ffi/Cargo.toml +0 -67
  270. data/vendor/kreuzberg-ffi/README.md +0 -851
  271. data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +0 -227
  272. data/vendor/kreuzberg-ffi/build.rs +0 -168
  273. data/vendor/kreuzberg-ffi/cbindgen.toml +0 -37
  274. data/vendor/kreuzberg-ffi/kreuzberg-ffi.pc.in +0 -12
  275. data/vendor/kreuzberg-ffi/kreuzberg.h +0 -3012
  276. data/vendor/kreuzberg-ffi/src/batch_streaming.rs +0 -588
  277. data/vendor/kreuzberg-ffi/src/config.rs +0 -1341
  278. data/vendor/kreuzberg-ffi/src/error.rs +0 -901
  279. data/vendor/kreuzberg-ffi/src/extraction.rs +0 -555
  280. data/vendor/kreuzberg-ffi/src/helpers.rs +0 -879
  281. data/vendor/kreuzberg-ffi/src/lib.rs +0 -977
  282. data/vendor/kreuzberg-ffi/src/memory.rs +0 -493
  283. data/vendor/kreuzberg-ffi/src/mime.rs +0 -329
  284. data/vendor/kreuzberg-ffi/src/panic_shield.rs +0 -265
  285. data/vendor/kreuzberg-ffi/src/plugins/document_extractor.rs +0 -442
  286. data/vendor/kreuzberg-ffi/src/plugins/mod.rs +0 -14
  287. data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +0 -628
  288. data/vendor/kreuzberg-ffi/src/plugins/post_processor.rs +0 -438
  289. data/vendor/kreuzberg-ffi/src/plugins/validator.rs +0 -329
  290. data/vendor/kreuzberg-ffi/src/result.rs +0 -510
  291. data/vendor/kreuzberg-ffi/src/result_pool.rs +0 -639
  292. data/vendor/kreuzberg-ffi/src/result_view.rs +0 -773
  293. data/vendor/kreuzberg-ffi/src/string_intern.rs +0 -568
  294. data/vendor/kreuzberg-ffi/src/types.rs +0 -363
  295. data/vendor/kreuzberg-ffi/src/util.rs +0 -210
  296. data/vendor/kreuzberg-ffi/src/validation.rs +0 -848
  297. data/vendor/kreuzberg-ffi/tests.disabled/README.md +0 -48
  298. data/vendor/kreuzberg-ffi/tests.disabled/config_loading_tests.rs +0 -299
  299. data/vendor/kreuzberg-ffi/tests.disabled/config_tests.rs +0 -346
  300. data/vendor/kreuzberg-ffi/tests.disabled/extractor_tests.rs +0 -232
  301. data/vendor/kreuzberg-ffi/tests.disabled/plugin_registration_tests.rs +0 -470
  302. data/vendor/kreuzberg-tesseract/.commitlintrc.json +0 -13
  303. data/vendor/kreuzberg-tesseract/.crate-ignore +0 -2
  304. data/vendor/kreuzberg-tesseract/Cargo.lock +0 -2933
  305. data/vendor/kreuzberg-tesseract/Cargo.toml +0 -57
  306. data/vendor/kreuzberg-tesseract/LICENSE +0 -22
  307. data/vendor/kreuzberg-tesseract/README.md +0 -399
  308. data/vendor/kreuzberg-tesseract/build.rs +0 -1127
  309. data/vendor/kreuzberg-tesseract/patches/README.md +0 -71
  310. data/vendor/kreuzberg-tesseract/patches/tesseract.diff +0 -199
  311. data/vendor/kreuzberg-tesseract/src/api.rs +0 -1371
  312. data/vendor/kreuzberg-tesseract/src/choice_iterator.rs +0 -77
  313. data/vendor/kreuzberg-tesseract/src/enums.rs +0 -297
  314. data/vendor/kreuzberg-tesseract/src/error.rs +0 -81
  315. data/vendor/kreuzberg-tesseract/src/lib.rs +0 -145
  316. data/vendor/kreuzberg-tesseract/src/monitor.rs +0 -57
  317. data/vendor/kreuzberg-tesseract/src/mutable_iterator.rs +0 -197
  318. data/vendor/kreuzberg-tesseract/src/page_iterator.rs +0 -253
  319. data/vendor/kreuzberg-tesseract/src/result_iterator.rs +0 -286
  320. data/vendor/kreuzberg-tesseract/src/result_renderer.rs +0 -183
  321. data/vendor/kreuzberg-tesseract/tests/integration_test.rs +0 -211
@@ -8,26 +8,13 @@ use crate::{ExtractionConfig, types::ExtractionResult};
8
8
  /// API server size limit configuration.
9
9
  ///
10
10
  /// Controls maximum sizes for request bodies and multipart uploads.
11
- /// Default limits are set to 100 MB to accommodate typical document processing workloads.
11
+ /// Default limits are designed for typical document processing workloads.
12
12
  ///
13
13
  /// # Default Values
14
14
  ///
15
15
  /// - `max_request_body_bytes`: 100 MB (104,857,600 bytes)
16
16
  /// - `max_multipart_field_bytes`: 100 MB (104,857,600 bytes)
17
17
  ///
18
- /// # Configuration via Environment Variables
19
- ///
20
- /// You can override the defaults using these environment variables:
21
- ///
22
- /// ```bash
23
- /// # Modern approach (in bytes):
24
- /// export KREUZBERG_MAX_REQUEST_BODY_BYTES=104857600 # 100 MB
25
- /// export KREUZBERG_MAX_MULTIPART_FIELD_BYTES=104857600 # 100 MB
26
- ///
27
- /// # Legacy approach (in MB, applies to both limits):
28
- /// export KREUZBERG_MAX_UPLOAD_SIZE_MB=100 # 100 MB
29
- /// ```
30
- ///
31
18
  /// # Examples
32
19
  ///
33
20
  /// ```
@@ -36,16 +23,16 @@ use crate::{ExtractionConfig, types::ExtractionResult};
36
23
  /// // Default limits (100 MB)
37
24
  /// let limits = ApiSizeLimits::default();
38
25
  ///
39
- /// // Custom limits (5 GB for both)
26
+ /// // Custom limits (50 MB for both)
40
27
  /// let limits = ApiSizeLimits {
41
- /// max_request_body_bytes: 5 * 1024 * 1024 * 1024,
42
- /// max_multipart_field_bytes: 5 * 1024 * 1024 * 1024,
28
+ /// max_request_body_bytes: 50 * 1024 * 1024,
29
+ /// max_multipart_field_bytes: 50 * 1024 * 1024,
43
30
  /// };
44
31
  ///
45
- /// // Very large documents (100 GB total, 50 GB per file)
32
+ /// // Very large documents (500 MB)
46
33
  /// let limits = ApiSizeLimits {
47
- /// max_request_body_bytes: 100 * 1024 * 1024 * 1024,
48
- /// max_multipart_field_bytes: 50 * 1024 * 1024 * 1024,
34
+ /// max_request_body_bytes: 500 * 1024 * 1024,
35
+ /// max_multipart_field_bytes: 500 * 1024 * 1024,
49
36
  /// };
50
37
  /// ```
51
38
  #[derive(Debug, Clone, Copy)]
@@ -181,26 +168,3 @@ pub struct CacheClearResponse {
181
168
  /// Space freed in MB
182
169
  pub freed_mb: f64,
183
170
  }
184
-
185
- /// Embedding request for generating embeddings from text.
186
- #[derive(Debug, Clone, Serialize, Deserialize)]
187
- pub struct EmbedRequest {
188
- /// Text strings to generate embeddings for
189
- pub texts: Vec<String>,
190
- /// Optional embedding configuration (model, batch size, etc.)
191
- #[serde(skip_serializing_if = "Option::is_none")]
192
- pub config: Option<crate::core::config::EmbeddingConfig>,
193
- }
194
-
195
- /// Embedding response containing generated embeddings.
196
- #[derive(Debug, Clone, Serialize, Deserialize)]
197
- pub struct EmbedResponse {
198
- /// Generated embeddings (one per input text)
199
- pub embeddings: Vec<Vec<f32>>,
200
- /// Model used for embedding generation
201
- pub model: String,
202
- /// Dimensionality of the embeddings
203
- pub dimensions: usize,
204
- /// Number of embeddings generated
205
- pub count: usize,
206
- }
@@ -0,0 +1,455 @@
1
+ //! Profile memory usage for extracting documents.
2
+ //!
3
+ //! This utility can run against a single file or a batch of files (via `--input-list`).
4
+ //! For each input it prints or writes a JSON object containing duration, peak RSS,
5
+ //! optional flamegraph path, and the top hot functions when CPU profiling is enabled.
6
+
7
+ use std::env;
8
+ use std::fs::{File, create_dir_all};
9
+ use std::io::{BufRead, BufReader};
10
+ use std::path::{Path, PathBuf};
11
+ use std::time::Instant;
12
+
13
+ use kreuzberg::core::config::ExtractionConfig;
14
+ use kreuzberg::core::extractor::extract_file_sync;
15
+ use serde::Serialize;
16
+
17
+ #[cfg(feature = "profiling")]
18
+ use pprof::{ProfilerGuardBuilder, Report};
19
+
20
+ #[cfg(feature = "profiling")]
21
+ use std::collections::HashMap;
22
+
23
+ #[cfg(target_os = "macos")]
24
+ fn normalize_rss(value: i64) -> i64 {
25
+ value / 1024
26
+ }
27
+
28
+ #[cfg(all(unix, not(target_os = "macos")))]
29
+ fn normalize_rss(value: i64) -> i64 {
30
+ value
31
+ }
32
+
33
+ #[cfg(not(unix))]
34
+ fn normalize_rss(value: i64) -> i64 {
35
+ value
36
+ }
37
+
38
+ #[cfg(unix)]
39
+ fn max_rss_kb() -> Option<i64> {
40
+ use std::mem::MaybeUninit;
41
+
42
+ let mut usage = MaybeUninit::<libc::rusage>::uninit();
43
+ let rc = unsafe { libc::getrusage(libc::RUSAGE_SELF, usage.as_mut_ptr()) };
44
+ if rc != 0 {
45
+ return None;
46
+ }
47
+ let usage = unsafe { usage.assume_init() };
48
+ Some(normalize_rss(usage.ru_maxrss))
49
+ }
50
+
51
+ #[cfg(not(unix))]
52
+ fn max_rss_kb() -> Option<i64> {
53
+ None
54
+ }
55
+
56
+ #[derive(Debug)]
57
+ struct Options {
58
+ inputs: Vec<PathBuf>,
59
+ input_list: Option<PathBuf>,
60
+ flamegraph: Option<PathBuf>,
61
+ flamegraph_dir: Option<PathBuf>,
62
+ output_json: Option<PathBuf>,
63
+ output_dir: Option<PathBuf>,
64
+ }
65
+
66
+ #[derive(Serialize, Clone)]
67
+ struct FunctionSample {
68
+ function: String,
69
+ samples: i64,
70
+ percentage: f64,
71
+ }
72
+
73
+ #[derive(Serialize, Clone)]
74
+ struct ProfileOutput {
75
+ input: String,
76
+ duration_secs: f64,
77
+ peak_rss_kb: Option<i64>,
78
+ delta_rss_kb: Option<i64>,
79
+ flamegraph: Option<String>,
80
+ top_functions: Option<Vec<FunctionSample>>,
81
+ }
82
+
83
+ fn print_usage() {
84
+ eprintln!(
85
+ "Usage: profile_extract [options] <file ...>\n\nOptions:\n --flamegraph <path> Write flamegraph SVG (single input)\n --flamegraph-dir <dir> Write flamegraph SVGs for each input\n --output-json <path> Write JSON output (single input)\n --output-dir <dir> Write per-file JSON outputs to directory\n --input-list <path> File with newline-separated input paths\n -h, --help Show this help message"
86
+ );
87
+ }
88
+
89
+ fn parse_options() -> Options {
90
+ let mut args = env::args().skip(1);
91
+ let mut inputs = Vec::new();
92
+ let mut input_list = None;
93
+ let mut flamegraph = None;
94
+ let mut flamegraph_dir = None;
95
+ let mut output_json = None;
96
+ let mut output_dir = None;
97
+
98
+ while let Some(arg) = args.next() {
99
+ match arg.as_str() {
100
+ "--flamegraph" => {
101
+ let path = args.next().unwrap_or_else(|| {
102
+ print_usage();
103
+ std::process::exit(64);
104
+ });
105
+ flamegraph = Some(PathBuf::from(path));
106
+ }
107
+ "--flamegraph-dir" => {
108
+ let path = args.next().unwrap_or_else(|| {
109
+ print_usage();
110
+ std::process::exit(64);
111
+ });
112
+ flamegraph_dir = Some(PathBuf::from(path));
113
+ }
114
+ "--output-json" => {
115
+ let path = args.next().unwrap_or_else(|| {
116
+ print_usage();
117
+ std::process::exit(64);
118
+ });
119
+ output_json = Some(PathBuf::from(path));
120
+ }
121
+ "--output-dir" => {
122
+ let path = args.next().unwrap_or_else(|| {
123
+ print_usage();
124
+ std::process::exit(64);
125
+ });
126
+ output_dir = Some(PathBuf::from(path));
127
+ }
128
+ "--input-list" => {
129
+ let path = args.next().unwrap_or_else(|| {
130
+ print_usage();
131
+ std::process::exit(64);
132
+ });
133
+ input_list = Some(PathBuf::from(path));
134
+ }
135
+ "-h" | "--help" => {
136
+ print_usage();
137
+ std::process::exit(0);
138
+ }
139
+ _ if arg.starts_with("--") => {
140
+ eprintln!("Unknown option: {arg}");
141
+ print_usage();
142
+ std::process::exit(64);
143
+ }
144
+ _ => inputs.push(PathBuf::from(arg)),
145
+ }
146
+ }
147
+
148
+ Options {
149
+ inputs,
150
+ input_list,
151
+ flamegraph,
152
+ flamegraph_dir,
153
+ output_json,
154
+ output_dir,
155
+ }
156
+ }
157
+
158
+ fn sanitize_file_name(path: &Path) -> String {
159
+ let name_owned;
160
+ let name = match path.file_name().and_then(|n| n.to_str()) {
161
+ Some(value) => value,
162
+ None => {
163
+ name_owned = path.to_string_lossy().into_owned();
164
+ &name_owned
165
+ }
166
+ };
167
+ let sanitized: String = name
168
+ .chars()
169
+ .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' })
170
+ .collect();
171
+ if sanitized.is_empty() {
172
+ "output".to_string()
173
+ } else {
174
+ sanitized
175
+ }
176
+ }
177
+
178
+ fn read_inputs_from_file(list_path: &Path) -> Result<Vec<PathBuf>, String> {
179
+ let file = File::open(list_path).map_err(|e| format!("Failed to open input list {}: {e}", list_path.display()))?;
180
+ let reader = BufReader::new(file);
181
+ let mut inputs = Vec::new();
182
+ for line in reader.lines() {
183
+ let line = line.map_err(|e| format!("Failed to read line from {}: {e}", list_path.display()))?;
184
+ let trimmed = line.trim();
185
+ if trimmed.is_empty() || trimmed.starts_with('#') {
186
+ continue;
187
+ }
188
+ inputs.push(PathBuf::from(trimmed));
189
+ }
190
+ Ok(inputs)
191
+ }
192
+
193
+ fn main() {
194
+ let options = parse_options();
195
+
196
+ let mut targets = options.inputs.clone();
197
+ if let Some(list_path) = &options.input_list {
198
+ match read_inputs_from_file(list_path) {
199
+ Ok(mut list_inputs) => targets.append(&mut list_inputs),
200
+ Err(err) => {
201
+ eprintln!("{err}");
202
+ std::process::exit(66);
203
+ }
204
+ }
205
+ }
206
+
207
+ if targets.is_empty() {
208
+ eprintln!("No input files specified");
209
+ print_usage();
210
+ std::process::exit(64);
211
+ }
212
+
213
+ let multiple = targets.len() > 1;
214
+
215
+ if multiple && options.flamegraph.is_some() && options.flamegraph_dir.is_none() {
216
+ eprintln!("Note: --flamegraph applies to a single input. Use --flamegraph-dir for batch runs.");
217
+ }
218
+
219
+ if multiple && options.output_json.is_some() && options.output_dir.is_none() {
220
+ eprintln!("Note: --output-json applies to a single input. Use --output-dir for batch runs.");
221
+ }
222
+
223
+ if let Some(dir) = &options.output_dir
224
+ && let Err(err) = create_dir_all(dir)
225
+ {
226
+ eprintln!("Failed to create output directory {}: {err}", dir.display());
227
+ }
228
+
229
+ if let Some(dir) = &options.flamegraph_dir
230
+ && let Err(err) = create_dir_all(dir)
231
+ {
232
+ eprintln!("Failed to create flamegraph directory {}: {err}", dir.display());
233
+ }
234
+
235
+ let mut aggregated_results: Vec<ProfileOutput> = Vec::new();
236
+
237
+ for target in targets {
238
+ let flamegraph_path = if let Some(dir) = &options.flamegraph_dir {
239
+ Some(dir.join(format!("{}.svg", sanitize_file_name(&target))))
240
+ } else if !multiple {
241
+ options.flamegraph.clone()
242
+ } else {
243
+ None
244
+ };
245
+
246
+ let output_json_path = if let Some(dir) = &options.output_dir {
247
+ Some(dir.join(format!("{}.json", sanitize_file_name(&target))))
248
+ } else if !multiple {
249
+ options.output_json.clone()
250
+ } else {
251
+ None
252
+ };
253
+
254
+ match run_profile(&target, flamegraph_path.clone()) {
255
+ Ok(profile) => {
256
+ if let Some(json_path) = output_json_path {
257
+ if let Some(parent) = json_path.parent()
258
+ && let Err(err) = create_dir_all(parent)
259
+ {
260
+ eprintln!("Failed to create output directory {}: {err}", parent.display());
261
+ }
262
+
263
+ match File::create(&json_path) {
264
+ Ok(file) => {
265
+ if let Err(err) = serde_json::to_writer_pretty(file, &profile) {
266
+ eprintln!("Failed to write JSON output {}: {err}", json_path.display());
267
+ } else {
268
+ eprintln!("Profile summary written to {}", json_path.display());
269
+ }
270
+ }
271
+ Err(err) => eprintln!("Failed to create JSON output file {}: {err}", json_path.display()),
272
+ }
273
+ } else {
274
+ aggregated_results.push(profile);
275
+ }
276
+ }
277
+ Err(err) => {
278
+ eprintln!("{}: {err}", target.display());
279
+ }
280
+ }
281
+ }
282
+
283
+ if options.output_json.is_none() && options.output_dir.is_none() {
284
+ if aggregated_results.len() == 1 {
285
+ if let Ok(json) = serde_json::to_string_pretty(&aggregated_results[0]) {
286
+ println!("{json}");
287
+ }
288
+ } else if !aggregated_results.is_empty()
289
+ && let Ok(json) = serde_json::to_string_pretty(&aggregated_results)
290
+ {
291
+ println!("{json}");
292
+ }
293
+ }
294
+ }
295
+
296
+ fn run_profile(path: &Path, flamegraph_path: Option<PathBuf>) -> Result<ProfileOutput, String> {
297
+ if !path.exists() {
298
+ return Err("Input file does not exist".to_string());
299
+ }
300
+
301
+ #[cfg(feature = "profiling")]
302
+ let guard = if flamegraph_path.is_some() {
303
+ #[cfg_attr(not(target_os = "macos"), allow(unused_mut))]
304
+ let mut builder = ProfilerGuardBuilder::default().frequency(100);
305
+
306
+ #[cfg(target_os = "macos")]
307
+ {
308
+ builder = builder.blocklist(&[
309
+ "libsystem_kernel.dylib",
310
+ "libsystem_pthread.dylib",
311
+ "libsystem_platform.dylib",
312
+ "libdyld.dylib",
313
+ ]);
314
+ }
315
+
316
+ match builder.build() {
317
+ Ok(guard) => Some(guard),
318
+ Err(err) => {
319
+ eprintln!("Failed to start profiler: {err}");
320
+ None
321
+ }
322
+ }
323
+ } else {
324
+ None
325
+ };
326
+
327
+ #[cfg(not(feature = "profiling"))]
328
+ if flamegraph_path.is_some() {
329
+ eprintln!(
330
+ "--flamegraph requested but build missing 'profiling' feature; recompile with `--features profiling`."
331
+ );
332
+ }
333
+
334
+ let start_rss = max_rss_kb();
335
+ let start = Instant::now();
336
+
337
+ let config = ExtractionConfig::default();
338
+ let result = extract_file_sync(path, None, &config).map_err(|e| format!("Extraction failed: {e:?}"))?;
339
+ let _ = result;
340
+ let duration = start.elapsed();
341
+ let end_rss = max_rss_kb();
342
+
343
+ #[cfg(feature = "profiling")]
344
+ let (flamegraph_path_str, top_functions) = match (flamegraph_path.clone(), guard) {
345
+ (Some(path), Some(guard)) => match guard.report().build() {
346
+ Ok(report) => {
347
+ if let Some(parent) = path.parent()
348
+ && let Err(err) = create_dir_all(parent)
349
+ {
350
+ eprintln!("Failed to create flamegraph directory: {err}");
351
+ }
352
+
353
+ match File::create(&path) {
354
+ Ok(mut file) => {
355
+ if let Err(err) = report.flamegraph(&mut file) {
356
+ eprintln!("Failed to write flamegraph: {err}");
357
+ }
358
+ }
359
+ Err(err) => {
360
+ eprintln!("Failed to create flamegraph file {}: {err}", path.display());
361
+ }
362
+ }
363
+
364
+ let tops = summarize_top_functions(&report, 10);
365
+ let filtered = if tops.is_empty() { None } else { Some(tops) };
366
+ (Some(path.display().to_string()), filtered)
367
+ }
368
+ Err(err) => {
369
+ eprintln!("Failed to build profiling report: {err}");
370
+ (None, None)
371
+ }
372
+ },
373
+ (Some(path), None) => {
374
+ eprintln!("Profiler guard was not initialised; skipping flamegraph generation");
375
+ if let Some(parent) = path.parent() {
376
+ let _ = create_dir_all(parent);
377
+ }
378
+ (None, None)
379
+ }
380
+ _ => (None, None),
381
+ };
382
+
383
+ #[cfg(not(feature = "profiling"))]
384
+ let (flamegraph_path_str, top_functions): (Option<String>, Option<Vec<FunctionSample>>) = (None, None);
385
+
386
+ let peak_kb = end_rss.or(start_rss);
387
+ let delta_kb = match (start_rss, end_rss) {
388
+ (Some(before), Some(after)) => Some(after.saturating_sub(before)),
389
+ _ => None,
390
+ };
391
+
392
+ Ok(ProfileOutput {
393
+ input: path.display().to_string(),
394
+ duration_secs: duration.as_secs_f64(),
395
+ peak_rss_kb: peak_kb,
396
+ delta_rss_kb: delta_kb,
397
+ flamegraph: flamegraph_path_str,
398
+ top_functions,
399
+ })
400
+ }
401
+
402
+ #[cfg(feature = "profiling")]
403
+ fn summarize_top_functions(report: &Report, limit: usize) -> Vec<FunctionSample> {
404
+ let mut totals: HashMap<String, i64> = HashMap::new();
405
+
406
+ for (frames, count) in &report.data {
407
+ let count = *count as i64;
408
+ if count <= 0 {
409
+ continue;
410
+ }
411
+
412
+ for frame_symbols in &frames.frames {
413
+ for symbol in frame_symbols {
414
+ let name = symbol.name();
415
+ *totals.entry(name).or_insert(0) += count;
416
+ }
417
+ }
418
+ }
419
+
420
+ let total_counts: i64 = totals.values().copied().sum();
421
+
422
+ let mut summary: Vec<FunctionSample> = totals
423
+ .into_iter()
424
+ .map(|(function, samples)| {
425
+ let percentage = if total_counts > 0 {
426
+ (samples as f64 / total_counts as f64) * 100.0
427
+ } else {
428
+ 0.0
429
+ };
430
+ FunctionSample {
431
+ function,
432
+ samples,
433
+ percentage,
434
+ }
435
+ })
436
+ .collect();
437
+
438
+ summary.sort_by(|a, b| b.samples.cmp(&a.samples));
439
+
440
+ let filtered: Vec<FunctionSample> = summary
441
+ .iter()
442
+ .filter(|entry| {
443
+ let name = entry.function.as_str();
444
+ !name.starts_with("__") && !name.contains("libsystem") && !name.contains("dyld")
445
+ })
446
+ .take(limit)
447
+ .cloned()
448
+ .collect();
449
+
450
+ if filtered.is_empty() {
451
+ summary.into_iter().take(limit).collect()
452
+ } else {
453
+ filtered
454
+ }
455
+ }
@@ -201,13 +201,6 @@ impl GenericCache {
201
201
  }
202
202
  }
203
203
 
204
- #[cfg_attr(feature = "otel", tracing::instrument(
205
- skip(self),
206
- fields(
207
- cache.hit = tracing::field::Empty,
208
- cache.key = %cache_key,
209
- )
210
- ))]
211
204
  pub fn get(&self, cache_key: &str, source_file: Option<&str>) -> Result<Option<Vec<u8>>> {
212
205
  let cache_path = self.get_cache_path(cache_key);
213
206
 
@@ -217,24 +210,16 @@ impl GenericCache {
217
210
  .lock()
218
211
  .map_err(|e| KreuzbergError::LockPoisoned(format!("Deleting files mutex poisoned: {}", e)))?;
219
212
  if deleting.contains(&cache_path) {
220
- #[cfg(feature = "otel")]
221
- tracing::Span::current().record("cache.hit", false);
222
213
  return Ok(None);
223
214
  }
224
215
  }
225
216
 
226
217
  if !self.is_valid(&cache_path, source_file) {
227
- #[cfg(feature = "otel")]
228
- tracing::Span::current().record("cache.hit", false);
229
218
  return Ok(None);
230
219
  }
231
220
 
232
221
  match fs::read(&cache_path) {
233
- Ok(content) => {
234
- #[cfg(feature = "otel")]
235
- tracing::Span::current().record("cache.hit", true);
236
- Ok(Some(content))
237
- }
222
+ Ok(content) => Ok(Some(content)),
238
223
  Err(_) => {
239
224
  // Best-effort cleanup of corrupted cache files ~keep
240
225
  if let Err(e) = fs::remove_file(&cache_path) {
@@ -243,30 +228,21 @@ impl GenericCache {
243
228
  if let Err(e) = fs::remove_file(self.get_metadata_path(cache_key)) {
244
229
  tracing::debug!("Failed to remove corrupted metadata file: {}", e);
245
230
  }
246
- #[cfg(feature = "otel")]
247
- tracing::Span::current().record("cache.hit", false);
248
231
  Ok(None)
249
232
  }
250
233
  }
251
234
  }
252
235
 
253
- #[cfg_attr(feature = "otel", tracing::instrument(
254
- skip(self, data),
255
- fields(
256
- cache.key = %cache_key,
257
- cache.size_bytes = data.len(),
258
- )
259
- ))]
260
236
  pub fn set(&self, cache_key: &str, data: Vec<u8>, source_file: Option<&str>) -> Result<()> {
261
237
  let cache_path = self.get_cache_path(cache_key);
262
238
 
263
- fs::write(&cache_path, &data)
239
+ fs::write(&cache_path, data)
264
240
  .map_err(|e| KreuzbergError::cache(format!("Failed to write cache file: {}", e)))?;
265
241
 
266
242
  self.save_metadata(cache_key, source_file);
267
243
 
268
244
  let count = self.write_counter.fetch_add(1, Ordering::Relaxed);
269
- if count.is_multiple_of(100)
245
+ if count % 100 == 0
270
246
  && let Some(cache_path_str) = self.cache_dir.to_str()
271
247
  {
272
248
  // Cache cleanup failure - safe to ignore, cache is optional fallback ~keep