kreuzberg 4.0.8 → 4.1.1

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 (312) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +1 -1
  4. data/ext/kreuzberg_rb/native/Cargo.lock +94 -98
  5. data/ext/kreuzberg_rb/native/Cargo.toml +4 -2
  6. data/ext/kreuzberg_rb/native/src/batch.rs +139 -0
  7. data/ext/kreuzberg_rb/native/src/config/mod.rs +10 -0
  8. data/ext/kreuzberg_rb/native/src/config/types.rs +1058 -0
  9. data/ext/kreuzberg_rb/native/src/error_handling.rs +125 -0
  10. data/ext/kreuzberg_rb/native/src/extraction.rs +79 -0
  11. data/ext/kreuzberg_rb/native/src/gc_guarded_value.rs +35 -0
  12. data/ext/kreuzberg_rb/native/src/helpers.rs +176 -0
  13. data/ext/kreuzberg_rb/native/src/lib.rs +342 -3622
  14. data/ext/kreuzberg_rb/native/src/metadata.rs +34 -0
  15. data/ext/kreuzberg_rb/native/src/plugins/mod.rs +92 -0
  16. data/ext/kreuzberg_rb/native/src/plugins/ocr_backend.rs +159 -0
  17. data/ext/kreuzberg_rb/native/src/plugins/post_processor.rs +126 -0
  18. data/ext/kreuzberg_rb/native/src/plugins/validator.rs +99 -0
  19. data/ext/kreuzberg_rb/native/src/result.rs +326 -0
  20. data/ext/kreuzberg_rb/native/src/validation.rs +4 -0
  21. data/lib/kreuzberg/config.rb +99 -2
  22. data/lib/kreuzberg/result.rb +107 -2
  23. data/lib/kreuzberg/types.rb +104 -0
  24. data/lib/kreuzberg/version.rb +1 -1
  25. data/lib/kreuzberg.rb +0 -4
  26. data/sig/kreuzberg.rbs +105 -1
  27. data/spec/fixtures/config.toml +1 -1
  28. data/spec/fixtures/config.yaml +1 -1
  29. data/vendor/Cargo.toml +3 -3
  30. data/vendor/kreuzberg/Cargo.toml +5 -4
  31. data/vendor/kreuzberg/README.md +1 -1
  32. data/vendor/kreuzberg/src/api/config.rs +69 -0
  33. data/vendor/kreuzberg/src/api/handlers.rs +99 -2
  34. data/vendor/kreuzberg/src/api/mod.rs +14 -7
  35. data/vendor/kreuzberg/src/api/router.rs +214 -0
  36. data/vendor/kreuzberg/src/api/startup.rs +243 -0
  37. data/vendor/kreuzberg/src/api/types.rs +78 -0
  38. data/vendor/kreuzberg/src/cache/cleanup.rs +277 -0
  39. data/vendor/kreuzberg/src/cache/core.rs +428 -0
  40. data/vendor/kreuzberg/src/cache/mod.rs +21 -843
  41. data/vendor/kreuzberg/src/cache/utilities.rs +156 -0
  42. data/vendor/kreuzberg/src/chunking/boundaries.rs +301 -0
  43. data/vendor/kreuzberg/src/chunking/builder.rs +294 -0
  44. data/vendor/kreuzberg/src/chunking/config.rs +52 -0
  45. data/vendor/kreuzberg/src/chunking/core.rs +1017 -0
  46. data/vendor/kreuzberg/src/chunking/mod.rs +14 -2211
  47. data/vendor/kreuzberg/src/chunking/processor.rs +10 -0
  48. data/vendor/kreuzberg/src/chunking/validation.rs +686 -0
  49. data/vendor/kreuzberg/src/core/config/extraction/core.rs +169 -0
  50. data/vendor/kreuzberg/src/core/config/extraction/env.rs +179 -0
  51. data/vendor/kreuzberg/src/core/config/extraction/loaders.rs +204 -0
  52. data/vendor/kreuzberg/src/core/config/extraction/mod.rs +42 -0
  53. data/vendor/kreuzberg/src/core/config/extraction/types.rs +93 -0
  54. data/vendor/kreuzberg/src/core/config/formats.rs +135 -0
  55. data/vendor/kreuzberg/src/core/config/mod.rs +20 -0
  56. data/vendor/kreuzberg/src/core/config/ocr.rs +73 -0
  57. data/vendor/kreuzberg/src/core/config/page.rs +57 -0
  58. data/vendor/kreuzberg/src/core/config/pdf.rs +111 -0
  59. data/vendor/kreuzberg/src/core/config/processing.rs +312 -0
  60. data/vendor/kreuzberg/src/core/config_validation/dependencies.rs +187 -0
  61. data/vendor/kreuzberg/src/core/config_validation/mod.rs +386 -0
  62. data/vendor/kreuzberg/src/core/config_validation/sections.rs +401 -0
  63. data/vendor/kreuzberg/src/core/extractor/batch.rs +246 -0
  64. data/vendor/kreuzberg/src/core/extractor/bytes.rs +116 -0
  65. data/vendor/kreuzberg/src/core/extractor/file.rs +240 -0
  66. data/vendor/kreuzberg/src/core/extractor/helpers.rs +71 -0
  67. data/vendor/kreuzberg/src/core/extractor/legacy.rs +62 -0
  68. data/vendor/kreuzberg/src/core/extractor/mod.rs +490 -0
  69. data/vendor/kreuzberg/src/core/extractor/sync.rs +208 -0
  70. data/vendor/kreuzberg/src/core/mime.rs +15 -0
  71. data/vendor/kreuzberg/src/core/mod.rs +4 -1
  72. data/vendor/kreuzberg/src/core/pipeline/cache.rs +60 -0
  73. data/vendor/kreuzberg/src/core/pipeline/execution.rs +89 -0
  74. data/vendor/kreuzberg/src/core/pipeline/features.rs +108 -0
  75. data/vendor/kreuzberg/src/core/pipeline/format.rs +392 -0
  76. data/vendor/kreuzberg/src/core/pipeline/initialization.rs +67 -0
  77. data/vendor/kreuzberg/src/core/pipeline/mod.rs +135 -0
  78. data/vendor/kreuzberg/src/core/pipeline/tests.rs +975 -0
  79. data/vendor/kreuzberg/src/core/server_config/env.rs +90 -0
  80. data/vendor/kreuzberg/src/core/server_config/loader.rs +202 -0
  81. data/vendor/kreuzberg/src/core/server_config/mod.rs +380 -0
  82. data/vendor/kreuzberg/src/core/server_config/tests/basic_tests.rs +124 -0
  83. data/vendor/kreuzberg/src/core/server_config/tests/env_tests.rs +216 -0
  84. data/vendor/kreuzberg/src/core/server_config/tests/file_loading_tests.rs +341 -0
  85. data/vendor/kreuzberg/src/core/server_config/tests/mod.rs +5 -0
  86. data/vendor/kreuzberg/src/core/server_config/validation.rs +17 -0
  87. data/vendor/kreuzberg/src/embeddings.rs +136 -13
  88. data/vendor/kreuzberg/src/extraction/{archive.rs → archive/mod.rs} +45 -239
  89. data/vendor/kreuzberg/src/extraction/archive/sevenz.rs +98 -0
  90. data/vendor/kreuzberg/src/extraction/archive/tar.rs +118 -0
  91. data/vendor/kreuzberg/src/extraction/archive/zip.rs +101 -0
  92. data/vendor/kreuzberg/src/extraction/html/converter.rs +592 -0
  93. data/vendor/kreuzberg/src/extraction/html/image_handling.rs +95 -0
  94. data/vendor/kreuzberg/src/extraction/html/mod.rs +53 -0
  95. data/vendor/kreuzberg/src/extraction/html/processor.rs +659 -0
  96. data/vendor/kreuzberg/src/extraction/html/stack_management.rs +103 -0
  97. data/vendor/kreuzberg/src/extraction/html/types.rs +28 -0
  98. data/vendor/kreuzberg/src/extraction/mod.rs +6 -2
  99. data/vendor/kreuzberg/src/extraction/pptx/container.rs +159 -0
  100. data/vendor/kreuzberg/src/extraction/pptx/content_builder.rs +168 -0
  101. data/vendor/kreuzberg/src/extraction/pptx/elements.rs +132 -0
  102. data/vendor/kreuzberg/src/extraction/pptx/image_handling.rs +57 -0
  103. data/vendor/kreuzberg/src/extraction/pptx/metadata.rs +160 -0
  104. data/vendor/kreuzberg/src/extraction/pptx/mod.rs +558 -0
  105. data/vendor/kreuzberg/src/extraction/pptx/parser.rs +388 -0
  106. data/vendor/kreuzberg/src/extraction/transform/content.rs +205 -0
  107. data/vendor/kreuzberg/src/extraction/transform/elements.rs +211 -0
  108. data/vendor/kreuzberg/src/extraction/transform/mod.rs +480 -0
  109. data/vendor/kreuzberg/src/extraction/transform/types.rs +27 -0
  110. data/vendor/kreuzberg/src/extractors/archive.rs +2 -0
  111. data/vendor/kreuzberg/src/extractors/bibtex.rs +2 -0
  112. data/vendor/kreuzberg/src/extractors/djot_format/attributes.rs +134 -0
  113. data/vendor/kreuzberg/src/extractors/djot_format/conversion.rs +223 -0
  114. data/vendor/kreuzberg/src/extractors/djot_format/extractor.rs +172 -0
  115. data/vendor/kreuzberg/src/extractors/djot_format/mod.rs +24 -0
  116. data/vendor/kreuzberg/src/extractors/djot_format/parsing/block_handlers.rs +271 -0
  117. data/vendor/kreuzberg/src/extractors/djot_format/parsing/content_extraction.rs +257 -0
  118. data/vendor/kreuzberg/src/extractors/djot_format/parsing/event_handlers.rs +101 -0
  119. data/vendor/kreuzberg/src/extractors/djot_format/parsing/inline_handlers.rs +201 -0
  120. data/vendor/kreuzberg/src/extractors/djot_format/parsing/mod.rs +16 -0
  121. data/vendor/kreuzberg/src/extractors/djot_format/parsing/state.rs +78 -0
  122. data/vendor/kreuzberg/src/extractors/djot_format/parsing/table_extraction.rs +68 -0
  123. data/vendor/kreuzberg/src/extractors/djot_format/parsing/text_extraction.rs +61 -0
  124. data/vendor/kreuzberg/src/extractors/djot_format/rendering.rs +452 -0
  125. data/vendor/kreuzberg/src/extractors/docbook.rs +2 -0
  126. data/vendor/kreuzberg/src/extractors/docx.rs +12 -1
  127. data/vendor/kreuzberg/src/extractors/email.rs +2 -0
  128. data/vendor/kreuzberg/src/extractors/epub/content.rs +333 -0
  129. data/vendor/kreuzberg/src/extractors/epub/metadata.rs +137 -0
  130. data/vendor/kreuzberg/src/extractors/epub/mod.rs +186 -0
  131. data/vendor/kreuzberg/src/extractors/epub/parsing.rs +86 -0
  132. data/vendor/kreuzberg/src/extractors/excel.rs +4 -0
  133. data/vendor/kreuzberg/src/extractors/fictionbook.rs +2 -0
  134. data/vendor/kreuzberg/src/extractors/frontmatter_utils.rs +466 -0
  135. data/vendor/kreuzberg/src/extractors/html.rs +80 -8
  136. data/vendor/kreuzberg/src/extractors/image.rs +8 -1
  137. data/vendor/kreuzberg/src/extractors/jats/elements.rs +350 -0
  138. data/vendor/kreuzberg/src/extractors/jats/metadata.rs +21 -0
  139. data/vendor/kreuzberg/src/extractors/{jats.rs → jats/mod.rs} +10 -412
  140. data/vendor/kreuzberg/src/extractors/jats/parser.rs +52 -0
  141. data/vendor/kreuzberg/src/extractors/jupyter.rs +2 -0
  142. data/vendor/kreuzberg/src/extractors/latex/commands.rs +93 -0
  143. data/vendor/kreuzberg/src/extractors/latex/environments.rs +157 -0
  144. data/vendor/kreuzberg/src/extractors/latex/metadata.rs +27 -0
  145. data/vendor/kreuzberg/src/extractors/latex/mod.rs +146 -0
  146. data/vendor/kreuzberg/src/extractors/latex/parser.rs +231 -0
  147. data/vendor/kreuzberg/src/extractors/latex/utilities.rs +126 -0
  148. data/vendor/kreuzberg/src/extractors/markdown.rs +39 -162
  149. data/vendor/kreuzberg/src/extractors/mod.rs +9 -1
  150. data/vendor/kreuzberg/src/extractors/odt.rs +2 -0
  151. data/vendor/kreuzberg/src/extractors/opml/core.rs +165 -0
  152. data/vendor/kreuzberg/src/extractors/opml/mod.rs +31 -0
  153. data/vendor/kreuzberg/src/extractors/opml/parser.rs +479 -0
  154. data/vendor/kreuzberg/src/extractors/orgmode.rs +2 -0
  155. data/vendor/kreuzberg/src/extractors/pdf/extraction.rs +106 -0
  156. data/vendor/kreuzberg/src/extractors/{pdf.rs → pdf/mod.rs} +25 -324
  157. data/vendor/kreuzberg/src/extractors/pdf/ocr.rs +214 -0
  158. data/vendor/kreuzberg/src/extractors/pdf/pages.rs +51 -0
  159. data/vendor/kreuzberg/src/extractors/pptx.rs +9 -2
  160. data/vendor/kreuzberg/src/extractors/rst.rs +2 -0
  161. data/vendor/kreuzberg/src/extractors/rtf/encoding.rs +116 -0
  162. data/vendor/kreuzberg/src/extractors/rtf/formatting.rs +24 -0
  163. data/vendor/kreuzberg/src/extractors/rtf/images.rs +72 -0
  164. data/vendor/kreuzberg/src/extractors/rtf/metadata.rs +216 -0
  165. data/vendor/kreuzberg/src/extractors/rtf/mod.rs +142 -0
  166. data/vendor/kreuzberg/src/extractors/rtf/parser.rs +259 -0
  167. data/vendor/kreuzberg/src/extractors/rtf/tables.rs +83 -0
  168. data/vendor/kreuzberg/src/extractors/structured.rs +2 -0
  169. data/vendor/kreuzberg/src/extractors/text.rs +4 -0
  170. data/vendor/kreuzberg/src/extractors/typst.rs +2 -0
  171. data/vendor/kreuzberg/src/extractors/xml.rs +2 -0
  172. data/vendor/kreuzberg/src/keywords/processor.rs +14 -0
  173. data/vendor/kreuzberg/src/language_detection/processor.rs +10 -0
  174. data/vendor/kreuzberg/src/lib.rs +2 -2
  175. data/vendor/kreuzberg/src/mcp/errors.rs +312 -0
  176. data/vendor/kreuzberg/src/mcp/format.rs +211 -0
  177. data/vendor/kreuzberg/src/mcp/mod.rs +9 -3
  178. data/vendor/kreuzberg/src/mcp/params.rs +196 -0
  179. data/vendor/kreuzberg/src/mcp/server.rs +39 -1438
  180. data/vendor/kreuzberg/src/mcp/tools/cache.rs +179 -0
  181. data/vendor/kreuzberg/src/mcp/tools/extraction.rs +403 -0
  182. data/vendor/kreuzberg/src/mcp/tools/mime.rs +150 -0
  183. data/vendor/kreuzberg/src/mcp/tools/mod.rs +11 -0
  184. data/vendor/kreuzberg/src/ocr/backends/easyocr.rs +96 -0
  185. data/vendor/kreuzberg/src/ocr/backends/mod.rs +7 -0
  186. data/vendor/kreuzberg/src/ocr/backends/paddleocr.rs +27 -0
  187. data/vendor/kreuzberg/src/ocr/backends/tesseract.rs +134 -0
  188. data/vendor/kreuzberg/src/ocr/hocr.rs +60 -16
  189. data/vendor/kreuzberg/src/ocr/language_registry.rs +11 -235
  190. data/vendor/kreuzberg/src/ocr/mod.rs +1 -0
  191. data/vendor/kreuzberg/src/ocr/processor/config.rs +203 -0
  192. data/vendor/kreuzberg/src/ocr/processor/execution.rs +494 -0
  193. data/vendor/kreuzberg/src/ocr/processor/mod.rs +265 -0
  194. data/vendor/kreuzberg/src/ocr/processor/validation.rs +145 -0
  195. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +41 -24
  196. data/vendor/kreuzberg/src/pdf/bindings.rs +21 -8
  197. data/vendor/kreuzberg/src/pdf/hierarchy/bounding_box.rs +289 -0
  198. data/vendor/kreuzberg/src/pdf/hierarchy/clustering.rs +199 -0
  199. data/vendor/kreuzberg/src/pdf/{hierarchy.rs → hierarchy/extraction.rs} +6 -346
  200. data/vendor/kreuzberg/src/pdf/hierarchy/mod.rs +18 -0
  201. data/vendor/kreuzberg/src/plugins/extractor/mod.rs +319 -0
  202. data/vendor/kreuzberg/src/plugins/extractor/registry.rs +434 -0
  203. data/vendor/kreuzberg/src/plugins/extractor/trait.rs +391 -0
  204. data/vendor/kreuzberg/src/plugins/mod.rs +13 -0
  205. data/vendor/kreuzberg/src/plugins/ocr.rs +11 -0
  206. data/vendor/kreuzberg/src/plugins/processor/mod.rs +365 -0
  207. data/vendor/kreuzberg/src/plugins/processor/registry.rs +37 -0
  208. data/vendor/kreuzberg/src/plugins/processor/trait.rs +284 -0
  209. data/vendor/kreuzberg/src/plugins/registry/extractor.rs +416 -0
  210. data/vendor/kreuzberg/src/plugins/registry/mod.rs +116 -0
  211. data/vendor/kreuzberg/src/plugins/registry/ocr.rs +293 -0
  212. data/vendor/kreuzberg/src/plugins/registry/processor.rs +304 -0
  213. data/vendor/kreuzberg/src/plugins/registry/validator.rs +238 -0
  214. data/vendor/kreuzberg/src/plugins/validator/mod.rs +424 -0
  215. data/vendor/kreuzberg/src/plugins/validator/registry.rs +355 -0
  216. data/vendor/kreuzberg/src/plugins/validator/trait.rs +276 -0
  217. data/vendor/kreuzberg/src/stopwords/languages/asian.rs +40 -0
  218. data/vendor/kreuzberg/src/stopwords/languages/germanic.rs +36 -0
  219. data/vendor/kreuzberg/src/stopwords/languages/mod.rs +10 -0
  220. data/vendor/kreuzberg/src/stopwords/languages/other.rs +44 -0
  221. data/vendor/kreuzberg/src/stopwords/languages/romance.rs +36 -0
  222. data/vendor/kreuzberg/src/stopwords/languages/slavic.rs +36 -0
  223. data/vendor/kreuzberg/src/stopwords/mod.rs +7 -33
  224. data/vendor/kreuzberg/src/text/quality.rs +1 -1
  225. data/vendor/kreuzberg/src/text/quality_processor.rs +10 -0
  226. data/vendor/kreuzberg/src/text/token_reduction/core/analysis.rs +238 -0
  227. data/vendor/kreuzberg/src/text/token_reduction/core/mod.rs +8 -0
  228. data/vendor/kreuzberg/src/text/token_reduction/core/punctuation.rs +54 -0
  229. data/vendor/kreuzberg/src/text/token_reduction/core/reducer.rs +384 -0
  230. data/vendor/kreuzberg/src/text/token_reduction/core/sentence_selection.rs +68 -0
  231. data/vendor/kreuzberg/src/text/token_reduction/core/word_filtering.rs +156 -0
  232. data/vendor/kreuzberg/src/text/token_reduction/filters/general.rs +377 -0
  233. data/vendor/kreuzberg/src/text/token_reduction/filters/html.rs +51 -0
  234. data/vendor/kreuzberg/src/text/token_reduction/filters/markdown.rs +285 -0
  235. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +131 -246
  236. data/vendor/kreuzberg/src/types/djot.rs +209 -0
  237. data/vendor/kreuzberg/src/types/extraction.rs +301 -0
  238. data/vendor/kreuzberg/src/types/formats.rs +443 -0
  239. data/vendor/kreuzberg/src/types/metadata.rs +560 -0
  240. data/vendor/kreuzberg/src/types/mod.rs +281 -0
  241. data/vendor/kreuzberg/src/types/page.rs +182 -0
  242. data/vendor/kreuzberg/src/types/serde_helpers.rs +132 -0
  243. data/vendor/kreuzberg/src/types/tables.rs +39 -0
  244. data/vendor/kreuzberg/src/utils/quality/heuristics.rs +58 -0
  245. data/vendor/kreuzberg/src/utils/{quality.rs → quality/mod.rs} +168 -489
  246. data/vendor/kreuzberg/src/utils/quality/patterns.rs +117 -0
  247. data/vendor/kreuzberg/src/utils/quality/scoring.rs +178 -0
  248. data/vendor/kreuzberg/src/utils/string_pool/buffer_pool.rs +325 -0
  249. data/vendor/kreuzberg/src/utils/string_pool/interned.rs +102 -0
  250. data/vendor/kreuzberg/src/utils/string_pool/language_pool.rs +119 -0
  251. data/vendor/kreuzberg/src/utils/string_pool/mime_pool.rs +235 -0
  252. data/vendor/kreuzberg/src/utils/string_pool/mod.rs +41 -0
  253. data/vendor/kreuzberg/tests/api_chunk.rs +313 -0
  254. data/vendor/kreuzberg/tests/api_embed.rs +6 -9
  255. data/vendor/kreuzberg/tests/batch_orchestration.rs +1 -0
  256. data/vendor/kreuzberg/tests/concurrency_stress.rs +7 -0
  257. data/vendor/kreuzberg/tests/core_integration.rs +1 -0
  258. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +130 -0
  259. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +5 -14
  260. data/vendor/kreuzberg/tests/format_integration.rs +2 -0
  261. data/vendor/kreuzberg/tests/helpers/mod.rs +1 -0
  262. data/vendor/kreuzberg/tests/html_table_test.rs +11 -11
  263. data/vendor/kreuzberg/tests/ocr_configuration.rs +16 -0
  264. data/vendor/kreuzberg/tests/ocr_errors.rs +18 -0
  265. data/vendor/kreuzberg/tests/ocr_quality.rs +9 -0
  266. data/vendor/kreuzberg/tests/ocr_stress.rs +1 -0
  267. data/vendor/kreuzberg/tests/pipeline_integration.rs +50 -0
  268. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +13 -0
  269. data/vendor/kreuzberg/tests/plugin_system.rs +12 -0
  270. data/vendor/kreuzberg/tests/pptx_regression_tests.rs +504 -0
  271. data/vendor/kreuzberg/tests/registry_integration_tests.rs +2 -0
  272. data/vendor/kreuzberg-ffi/Cargo.toml +2 -1
  273. data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +2 -0
  274. data/vendor/kreuzberg-ffi/kreuzberg.h +347 -178
  275. data/vendor/kreuzberg-ffi/src/config/html.rs +318 -0
  276. data/vendor/kreuzberg-ffi/src/config/loader.rs +154 -0
  277. data/vendor/kreuzberg-ffi/src/config/merge.rs +104 -0
  278. data/vendor/kreuzberg-ffi/src/config/mod.rs +385 -0
  279. data/vendor/kreuzberg-ffi/src/config/parse.rs +91 -0
  280. data/vendor/kreuzberg-ffi/src/config/serialize.rs +118 -0
  281. data/vendor/kreuzberg-ffi/src/config_builder.rs +598 -0
  282. data/vendor/kreuzberg-ffi/src/error.rs +46 -14
  283. data/vendor/kreuzberg-ffi/src/helpers.rs +10 -0
  284. data/vendor/kreuzberg-ffi/src/html_options.rs +421 -0
  285. data/vendor/kreuzberg-ffi/src/lib.rs +16 -0
  286. data/vendor/kreuzberg-ffi/src/panic_shield.rs +11 -0
  287. data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +2 -0
  288. data/vendor/kreuzberg-ffi/src/result.rs +148 -122
  289. data/vendor/kreuzberg-ffi/src/result_view.rs +4 -0
  290. data/vendor/kreuzberg-tesseract/Cargo.toml +2 -2
  291. metadata +201 -28
  292. data/vendor/kreuzberg/src/api/server.rs +0 -518
  293. data/vendor/kreuzberg/src/core/config.rs +0 -1914
  294. data/vendor/kreuzberg/src/core/config_validation.rs +0 -949
  295. data/vendor/kreuzberg/src/core/extractor.rs +0 -1200
  296. data/vendor/kreuzberg/src/core/pipeline.rs +0 -1223
  297. data/vendor/kreuzberg/src/core/server_config.rs +0 -1220
  298. data/vendor/kreuzberg/src/extraction/html.rs +0 -1830
  299. data/vendor/kreuzberg/src/extraction/pptx.rs +0 -3102
  300. data/vendor/kreuzberg/src/extractors/epub.rs +0 -696
  301. data/vendor/kreuzberg/src/extractors/latex.rs +0 -653
  302. data/vendor/kreuzberg/src/extractors/opml.rs +0 -635
  303. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -809
  304. data/vendor/kreuzberg/src/ocr/processor.rs +0 -858
  305. data/vendor/kreuzberg/src/plugins/extractor.rs +0 -1042
  306. data/vendor/kreuzberg/src/plugins/processor.rs +0 -650
  307. data/vendor/kreuzberg/src/plugins/registry.rs +0 -1339
  308. data/vendor/kreuzberg/src/plugins/validator.rs +0 -967
  309. data/vendor/kreuzberg/src/text/token_reduction/core.rs +0 -832
  310. data/vendor/kreuzberg/src/types.rs +0 -1713
  311. data/vendor/kreuzberg/src/utils/string_pool.rs +0 -762
  312. data/vendor/kreuzberg-ffi/src/config.rs +0 -1341
@@ -0,0 +1,392 @@
1
+ //! Output format conversion for extraction results.
2
+ //!
3
+ //! This module handles conversion of extraction results to various output formats
4
+ //! (Plain, Djot, Markdown, HTML) with proper error handling and metadata recording.
5
+
6
+ use crate::core::config::OutputFormat;
7
+ use crate::types::ExtractionResult;
8
+
9
+ /// Apply output format conversion to the extraction result.
10
+ ///
11
+ /// This function converts the result's content field based on the configured output format:
12
+ /// - `Plain`: No conversion (default)
13
+ /// - `Djot`: Use djot_content if available, otherwise keep plain text
14
+ /// - `Markdown`: Convert to Markdown format (uses djot as it's similar)
15
+ /// - `Html`: Convert to HTML format
16
+ ///
17
+ /// Skips conversion if content was already formatted during extraction (e.g., HTML extractor
18
+ /// already produced djot or markdown output).
19
+ ///
20
+ /// # Arguments
21
+ ///
22
+ /// * `result` - The extraction result to modify
23
+ /// * `output_format` - The desired output format
24
+ pub fn apply_output_format(result: &mut ExtractionResult, output_format: OutputFormat) {
25
+ // Check if content was already formatted during extraction
26
+ let already_formatted = match result.mime_type.as_str() {
27
+ "text/markdown" if output_format == OutputFormat::Markdown => true,
28
+ "text/djot" if output_format == OutputFormat::Djot => true,
29
+ _ => false,
30
+ };
31
+
32
+ if already_formatted {
33
+ return; // Skip re-conversion
34
+ }
35
+
36
+ match output_format {
37
+ OutputFormat::Plain => {
38
+ // Default - no conversion needed
39
+ }
40
+ OutputFormat::Djot => {
41
+ // Convert the extraction result to djot markup
42
+ match crate::extractors::djot_format::extraction_result_to_djot(result) {
43
+ Ok(djot_markup) => {
44
+ result.content = djot_markup;
45
+ }
46
+ Err(e) => {
47
+ // Keep original content on error, record error in metadata
48
+ result.metadata.additional.insert(
49
+ "output_format_error".to_string(),
50
+ serde_json::Value::String(format!("Failed to convert to djot: {}", e)),
51
+ );
52
+ }
53
+ }
54
+ }
55
+ OutputFormat::Markdown => {
56
+ // Djot is syntactically similar to Markdown, so we use djot output as a
57
+ // reasonable approximation. Full Markdown conversion would require a
58
+ // dedicated converter that handles the syntactic differences (e.g.,
59
+ // emphasis markers are swapped: djot uses _ for emphasis and * for strong,
60
+ // while CommonMark uses * for emphasis and ** for strong).
61
+ if result.djot_content.is_some() {
62
+ match crate::extractors::djot_format::extraction_result_to_djot(result) {
63
+ Ok(djot_markup) => {
64
+ result.content = djot_markup;
65
+ }
66
+ Err(e) => {
67
+ // Keep original content on error, record error in metadata
68
+ result.metadata.additional.insert(
69
+ "output_format_error".to_string(),
70
+ serde_json::Value::String(format!("Failed to convert to markdown: {}", e)),
71
+ );
72
+ }
73
+ }
74
+ }
75
+ // For non-djot documents, content remains as-is
76
+ }
77
+ OutputFormat::Html => {
78
+ // Convert to HTML format
79
+ if result.djot_content.is_some() {
80
+ // First generate djot markup, then convert to HTML
81
+ match crate::extractors::djot_format::extraction_result_to_djot(result) {
82
+ Ok(djot_markup) => {
83
+ match crate::extractors::djot_format::djot_to_html(&djot_markup) {
84
+ Ok(html) => {
85
+ result.content = html;
86
+ }
87
+ Err(e) => {
88
+ // Keep original content on error, record error in metadata
89
+ result.metadata.additional.insert(
90
+ "output_format_error".to_string(),
91
+ serde_json::Value::String(format!("Failed to convert djot to HTML: {}", e)),
92
+ );
93
+ }
94
+ }
95
+ }
96
+ Err(e) => {
97
+ // Keep original content on error, record error in metadata
98
+ result.metadata.additional.insert(
99
+ "output_format_error".to_string(),
100
+ serde_json::Value::String(format!("Failed to generate djot for HTML conversion: {}", e)),
101
+ );
102
+ }
103
+ }
104
+ } else {
105
+ // For non-djot documents, wrap plain text in basic HTML
106
+ let escaped_content = html_escape(&result.content);
107
+ result.content = format!("<pre>{}</pre>", escaped_content);
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ /// Escape HTML special characters in a string.
114
+ fn html_escape(s: &str) -> String {
115
+ s.replace('&', "&amp;")
116
+ .replace('<', "&lt;")
117
+ .replace('>', "&gt;")
118
+ .replace('"', "&quot;")
119
+ .replace('\'', "&#39;")
120
+ }
121
+
122
+ #[cfg(test)]
123
+ mod tests {
124
+ use super::*;
125
+ use crate::types::Metadata;
126
+
127
+ #[test]
128
+ fn test_apply_output_format_plain() {
129
+ let mut result = ExtractionResult {
130
+ content: "Hello World".to_string(),
131
+ mime_type: "text/plain".to_string(),
132
+ metadata: Metadata::default(),
133
+ tables: vec![],
134
+ detected_languages: None,
135
+ chunks: None,
136
+ images: None,
137
+ pages: None,
138
+ djot_content: None,
139
+ elements: None,
140
+ };
141
+
142
+ apply_output_format(&mut result, OutputFormat::Plain);
143
+
144
+ // Plain format should not modify content
145
+ assert_eq!(result.content, "Hello World");
146
+ }
147
+
148
+ #[test]
149
+ fn test_apply_output_format_djot_with_djot_content() {
150
+ use crate::types::{BlockType, DjotContent, FormattedBlock, InlineElement, InlineType};
151
+
152
+ let mut result = ExtractionResult {
153
+ content: "Hello World".to_string(),
154
+ mime_type: "text/djot".to_string(),
155
+ metadata: Metadata::default(),
156
+ tables: vec![],
157
+ detected_languages: None,
158
+ chunks: None,
159
+ images: None,
160
+ pages: None,
161
+ elements: None,
162
+ djot_content: Some(DjotContent {
163
+ plain_text: "Hello World".to_string(),
164
+ blocks: vec![FormattedBlock {
165
+ block_type: BlockType::Heading,
166
+ level: Some(1),
167
+ inline_content: vec![InlineElement {
168
+ element_type: InlineType::Text,
169
+ content: "Hello World".to_string(),
170
+ attributes: None,
171
+ metadata: None,
172
+ }],
173
+ attributes: None,
174
+ language: None,
175
+ code: None,
176
+ children: vec![],
177
+ }],
178
+ metadata: Metadata::default(),
179
+ tables: vec![],
180
+ images: vec![],
181
+ links: vec![],
182
+ footnotes: vec![],
183
+ attributes: std::collections::HashMap::new(),
184
+ }),
185
+ };
186
+
187
+ apply_output_format(&mut result, OutputFormat::Djot);
188
+
189
+ // The content should still be present (the function preserves content)
190
+ assert!(!result.content.is_empty());
191
+ }
192
+
193
+ #[test]
194
+ fn test_apply_output_format_djot_without_djot_content() {
195
+ let mut result = ExtractionResult {
196
+ content: "Hello World".to_string(),
197
+ mime_type: "text/plain".to_string(),
198
+ metadata: Metadata::default(),
199
+ tables: vec![],
200
+ detected_languages: None,
201
+ chunks: None,
202
+ images: None,
203
+ pages: None,
204
+ djot_content: None,
205
+ elements: None,
206
+ };
207
+
208
+ apply_output_format(&mut result, OutputFormat::Djot);
209
+
210
+ // Without djot_content, content is converted to djot paragraphs
211
+ // extraction_result_to_djot creates paragraphs from plain text
212
+ assert!(result.content.contains("Hello World"));
213
+ }
214
+
215
+ #[test]
216
+ fn test_apply_output_format_html() {
217
+ let mut result = ExtractionResult {
218
+ content: "Hello World".to_string(),
219
+ mime_type: "text/plain".to_string(),
220
+ metadata: Metadata::default(),
221
+ tables: vec![],
222
+ detected_languages: None,
223
+ chunks: None,
224
+ images: None,
225
+ pages: None,
226
+ djot_content: None,
227
+ elements: None,
228
+ };
229
+
230
+ apply_output_format(&mut result, OutputFormat::Html);
231
+
232
+ // For non-djot documents, HTML wraps content in <pre> tags
233
+ assert!(result.content.contains("<pre>"));
234
+ assert!(result.content.contains("Hello World"));
235
+ assert!(result.content.contains("</pre>"));
236
+ }
237
+
238
+ #[test]
239
+ fn test_apply_output_format_html_escapes_special_chars() {
240
+ let mut result = ExtractionResult {
241
+ content: "<script>alert('XSS')</script>".to_string(),
242
+ mime_type: "text/plain".to_string(),
243
+ metadata: Metadata::default(),
244
+ tables: vec![],
245
+ detected_languages: None,
246
+ chunks: None,
247
+ images: None,
248
+ pages: None,
249
+ djot_content: None,
250
+ elements: None,
251
+ };
252
+
253
+ apply_output_format(&mut result, OutputFormat::Html);
254
+
255
+ // HTML special characters should be escaped
256
+ assert!(result.content.contains("&lt;"));
257
+ assert!(result.content.contains("&gt;"));
258
+ assert!(!result.content.contains("<script>"));
259
+ }
260
+
261
+ #[test]
262
+ fn test_apply_output_format_markdown() {
263
+ let mut result = ExtractionResult {
264
+ content: "Hello World".to_string(),
265
+ mime_type: "text/plain".to_string(),
266
+ metadata: Metadata::default(),
267
+ tables: vec![],
268
+ detected_languages: None,
269
+ chunks: None,
270
+ images: None,
271
+ pages: None,
272
+ djot_content: None,
273
+ elements: None,
274
+ };
275
+
276
+ apply_output_format(&mut result, OutputFormat::Markdown);
277
+
278
+ // For non-djot documents without djot_content, markdown keeps content as-is
279
+ assert_eq!(result.content, "Hello World");
280
+ }
281
+
282
+ #[test]
283
+ fn test_apply_output_format_preserves_metadata() {
284
+ let mut additional = std::collections::HashMap::new();
285
+ additional.insert("custom_key".to_string(), serde_json::json!("custom_value"));
286
+ let metadata = Metadata {
287
+ title: Some("Test Title".to_string()),
288
+ additional,
289
+ ..Default::default()
290
+ };
291
+
292
+ let mut result = ExtractionResult {
293
+ content: "Hello World".to_string(),
294
+ mime_type: "text/plain".to_string(),
295
+ metadata,
296
+ tables: vec![],
297
+ detected_languages: None,
298
+ chunks: None,
299
+ images: None,
300
+ pages: None,
301
+ djot_content: None,
302
+ elements: None,
303
+ };
304
+
305
+ apply_output_format(&mut result, OutputFormat::Djot);
306
+
307
+ // Metadata should be preserved
308
+ assert_eq!(result.metadata.title, Some("Test Title".to_string()));
309
+ assert_eq!(
310
+ result.metadata.additional.get("custom_key"),
311
+ Some(&serde_json::json!("custom_value"))
312
+ );
313
+ }
314
+
315
+ #[test]
316
+ fn test_apply_output_format_preserves_tables() {
317
+ use crate::types::Table;
318
+
319
+ let table = Table {
320
+ cells: vec![vec!["A".to_string(), "B".to_string()]],
321
+ markdown: "| A | B |".to_string(),
322
+ page_number: 1,
323
+ };
324
+
325
+ let mut result = ExtractionResult {
326
+ content: "Hello World".to_string(),
327
+ mime_type: "text/plain".to_string(),
328
+ metadata: Metadata::default(),
329
+ tables: vec![table],
330
+ detected_languages: None,
331
+ chunks: None,
332
+ images: None,
333
+ pages: None,
334
+ djot_content: None,
335
+ elements: None,
336
+ };
337
+
338
+ apply_output_format(&mut result, OutputFormat::Html);
339
+
340
+ // Tables should be preserved
341
+ assert_eq!(result.tables.len(), 1);
342
+ assert_eq!(result.tables[0].cells[0][0], "A");
343
+ }
344
+
345
+ #[test]
346
+ fn test_apply_output_format_preserves_djot_content() {
347
+ use crate::types::{BlockType, DjotContent, FormattedBlock, InlineElement, InlineType};
348
+
349
+ let djot_content = DjotContent {
350
+ plain_text: "test".to_string(),
351
+ blocks: vec![FormattedBlock {
352
+ block_type: BlockType::Paragraph,
353
+ level: None,
354
+ inline_content: vec![InlineElement {
355
+ element_type: InlineType::Text,
356
+ content: "test".to_string(),
357
+ attributes: None,
358
+ metadata: None,
359
+ }],
360
+ attributes: None,
361
+ language: None,
362
+ code: None,
363
+ children: vec![],
364
+ }],
365
+ metadata: Metadata::default(),
366
+ tables: vec![],
367
+ images: vec![],
368
+ links: vec![],
369
+ footnotes: vec![],
370
+ attributes: std::collections::HashMap::new(),
371
+ };
372
+
373
+ let mut result = ExtractionResult {
374
+ content: "test".to_string(),
375
+ mime_type: "text/djot".to_string(),
376
+ metadata: Metadata::default(),
377
+ tables: vec![],
378
+ detected_languages: None,
379
+ chunks: None,
380
+ images: None,
381
+ pages: None,
382
+ elements: None,
383
+ djot_content: Some(djot_content),
384
+ };
385
+
386
+ apply_output_format(&mut result, OutputFormat::Djot);
387
+
388
+ // djot_content should still be present after format application
389
+ assert!(result.djot_content.is_some());
390
+ assert_eq!(result.djot_content.as_ref().unwrap().blocks.len(), 1);
391
+ }
392
+ }
@@ -0,0 +1,67 @@
1
+ //! Pipeline initialization and setup logic.
2
+ //!
3
+ //! This module handles the initialization of features and processor cache
4
+ //! required for pipeline execution.
5
+
6
+ use crate::Result;
7
+
8
+ use super::cache::{PROCESSOR_CACHE, ProcessorCache};
9
+
10
+ /// Type alias for processor stages tuple (Early, Middle, Late).
11
+ type ProcessorStages = (
12
+ std::sync::Arc<Vec<std::sync::Arc<dyn crate::plugins::PostProcessor>>>,
13
+ std::sync::Arc<Vec<std::sync::Arc<dyn crate::plugins::PostProcessor>>>,
14
+ std::sync::Arc<Vec<std::sync::Arc<dyn crate::plugins::PostProcessor>>>,
15
+ );
16
+
17
+ /// Initialize feature-specific systems that may be needed during pipeline execution.
18
+ pub(super) fn initialize_features() {
19
+ #[cfg(any(feature = "keywords-yake", feature = "keywords-rake"))]
20
+ {
21
+ let _ = crate::keywords::ensure_initialized();
22
+ }
23
+
24
+ #[cfg(feature = "language-detection")]
25
+ {
26
+ let _ = crate::language_detection::ensure_initialized();
27
+ }
28
+
29
+ #[cfg(feature = "chunking")]
30
+ {
31
+ let _ = crate::chunking::ensure_initialized();
32
+ }
33
+
34
+ #[cfg(feature = "quality")]
35
+ {
36
+ let registry = crate::plugins::registry::get_post_processor_registry();
37
+ if let Ok(mut reg) = registry.write() {
38
+ let _ = reg.register(std::sync::Arc::new(crate::text::QualityProcessor), 30);
39
+ }
40
+ }
41
+ }
42
+
43
+ /// Initialize the processor cache if not already initialized.
44
+ pub(super) fn initialize_processor_cache() -> Result<()> {
45
+ let mut cache_lock = PROCESSOR_CACHE
46
+ .write()
47
+ .map_err(|e| crate::KreuzbergError::Other(format!("Processor cache lock poisoned: {}", e)))?;
48
+ if cache_lock.is_none() {
49
+ *cache_lock = Some(ProcessorCache::new()?);
50
+ }
51
+ Ok(())
52
+ }
53
+
54
+ /// Get processors from the cache, organized by stage.
55
+ pub(super) fn get_processors_from_cache() -> Result<ProcessorStages> {
56
+ let cache_lock = PROCESSOR_CACHE
57
+ .read()
58
+ .map_err(|e| crate::KreuzbergError::Other(format!("Processor cache lock poisoned: {}", e)))?;
59
+ let cache = cache_lock
60
+ .as_ref()
61
+ .ok_or_else(|| crate::KreuzbergError::Other("Processor cache not initialized".to_string()))?;
62
+ Ok((
63
+ std::sync::Arc::clone(&cache.early),
64
+ std::sync::Arc::clone(&cache.middle),
65
+ std::sync::Arc::clone(&cache.late),
66
+ ))
67
+ }
@@ -0,0 +1,135 @@
1
+ //! Post-processing pipeline orchestration.
2
+ //!
3
+ //! This module orchestrates the post-processing pipeline, executing validators,
4
+ //! quality processing, chunking, and custom hooks in the correct order.
5
+
6
+ mod cache;
7
+ mod execution;
8
+ mod features;
9
+ mod format;
10
+ mod initialization;
11
+
12
+ #[cfg(test)]
13
+ mod tests;
14
+
15
+ pub use cache::clear_processor_cache;
16
+ pub use format::apply_output_format;
17
+
18
+ use crate::Result;
19
+ use crate::core::config::ExtractionConfig;
20
+ use crate::types::ExtractionResult;
21
+
22
+ use execution::{execute_processors, execute_validators};
23
+ use features::{execute_chunking, execute_language_detection};
24
+ use initialization::{get_processors_from_cache, initialize_features, initialize_processor_cache};
25
+
26
+ /// Run the post-processing pipeline on an extraction result.
27
+ ///
28
+ /// Executes post-processing in the following order:
29
+ /// 1. Post-Processors - Execute by stage (Early, Middle, Late) to modify/enhance the result
30
+ /// 2. Quality Processing - Text cleaning and quality scoring
31
+ /// 3. Chunking - Text splitting if enabled
32
+ /// 4. Validators - Run validation hooks on the processed result (can fail fast)
33
+ ///
34
+ /// # Arguments
35
+ ///
36
+ /// * `result` - The extraction result to process
37
+ /// * `config` - Extraction configuration
38
+ ///
39
+ /// # Returns
40
+ ///
41
+ /// The processed extraction result.
42
+ ///
43
+ /// # Errors
44
+ ///
45
+ /// - Validator errors bubble up immediately
46
+ /// - Post-processor errors are caught and recorded in metadata
47
+ /// - System errors (IO, RuntimeError equivalents) always bubble up
48
+ #[cfg_attr(feature = "otel", tracing::instrument(
49
+ skip(result, config),
50
+ fields(
51
+ pipeline.stage = "post_processing",
52
+ content.length = result.content.len(),
53
+ )
54
+ ))]
55
+ pub async fn run_pipeline(mut result: ExtractionResult, config: &ExtractionConfig) -> Result<ExtractionResult> {
56
+ let pp_config = config.postprocessor.as_ref();
57
+ let postprocessing_enabled = pp_config.is_none_or(|c| c.enabled);
58
+
59
+ if postprocessing_enabled {
60
+ initialize_features();
61
+ initialize_processor_cache()?;
62
+
63
+ let (early_processors, middle_processors, late_processors) = get_processors_from_cache()?;
64
+
65
+ execute_processors(
66
+ &mut result,
67
+ config,
68
+ &pp_config,
69
+ early_processors,
70
+ middle_processors,
71
+ late_processors,
72
+ )
73
+ .await?;
74
+ }
75
+
76
+ execute_chunking(&mut result, config)?;
77
+ execute_language_detection(&mut result, config)?;
78
+ execute_validators(&result, config).await?;
79
+
80
+ // Transform to element-based output if requested
81
+ if config.result_format == crate::types::OutputFormat::ElementBased {
82
+ result.elements = Some(crate::extraction::transform::transform_extraction_result_to_elements(
83
+ &result,
84
+ ));
85
+ }
86
+
87
+ // Apply output format conversion as the final step
88
+ apply_output_format(&mut result, config.output_format);
89
+
90
+ Ok(result)
91
+ }
92
+
93
+ /// Run the post-processing pipeline synchronously (WASM-compatible version).
94
+ ///
95
+ /// This is a synchronous implementation for WASM and non-async contexts.
96
+ /// It performs a subset of the full async pipeline, excluding async post-processors
97
+ /// and validators.
98
+ ///
99
+ /// # Arguments
100
+ ///
101
+ /// * `result` - The extraction result to process
102
+ /// * `config` - Extraction configuration
103
+ ///
104
+ /// # Returns
105
+ ///
106
+ /// The processed extraction result.
107
+ ///
108
+ /// # Notes
109
+ ///
110
+ /// This function is only available when the `tokio-runtime` feature is disabled.
111
+ /// It handles:
112
+ /// - Quality processing (if enabled)
113
+ /// - Chunking (if enabled)
114
+ /// - Language detection (if enabled)
115
+ ///
116
+ /// It does NOT handle:
117
+ /// - Async post-processors
118
+ /// - Async validators
119
+ #[cfg(not(feature = "tokio-runtime"))]
120
+ pub fn run_pipeline_sync(mut result: ExtractionResult, config: &ExtractionConfig) -> Result<ExtractionResult> {
121
+ execute_chunking(&mut result, config)?;
122
+ execute_language_detection(&mut result, config)?;
123
+
124
+ // Transform to element-based output if requested
125
+ if config.result_format == crate::types::OutputFormat::ElementBased {
126
+ result.elements = Some(crate::extraction::transform::transform_extraction_result_to_elements(
127
+ &result,
128
+ ));
129
+ }
130
+
131
+ // Apply output format conversion as the final step
132
+ apply_output_format(&mut result, config.output_format);
133
+
134
+ Ok(result)
135
+ }