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,490 @@
1
+ //! Main extraction entry points.
2
+ //!
3
+ //! This module provides the primary API for extracting content from files and byte arrays.
4
+ //! It orchestrates the entire extraction pipeline: cache checking, MIME detection,
5
+ //! extractor selection, extraction, post-processing, and cache storage.
6
+ //!
7
+ //! # Functions
8
+ //!
9
+ //! - [`extract_file`] - Extract content from a file path
10
+ //! - [`extract_bytes`] - Extract content from a byte array
11
+ //! - [`batch_extract_file`] - Extract content from multiple files concurrently
12
+ //! - [`batch_extract_bytes`] - Extract content from multiple byte arrays concurrently
13
+
14
+ mod bytes;
15
+ mod file;
16
+ mod helpers;
17
+ mod legacy;
18
+ mod sync;
19
+
20
+ #[cfg(feature = "tokio-runtime")]
21
+ mod batch;
22
+
23
+ // Re-export public API
24
+ pub use bytes::extract_bytes;
25
+ pub use file::extract_file;
26
+ pub use helpers::get_pool_sizing_hint;
27
+ pub use sync::{batch_extract_bytes_sync, extract_bytes_sync};
28
+
29
+ #[cfg(feature = "tokio-runtime")]
30
+ pub use sync::extract_file_sync;
31
+
32
+ #[cfg(feature = "tokio-runtime")]
33
+ pub use batch::{batch_extract_bytes, batch_extract_file};
34
+ #[cfg(feature = "tokio-runtime")]
35
+ pub use sync::batch_extract_file_sync;
36
+
37
+ #[cfg(test)]
38
+ mod tests {
39
+ use super::*;
40
+ use crate::core::config::ExtractionConfig;
41
+ use serial_test::serial;
42
+ use std::fs::File;
43
+ use std::io::Write;
44
+ use std::sync::Arc;
45
+ use tempfile::tempdir;
46
+
47
+ fn assert_text_content(actual: &str, expected: &str) {
48
+ assert_eq!(actual.trim_end_matches('\n'), expected);
49
+ }
50
+
51
+ #[tokio::test]
52
+ async fn test_extract_file_basic() {
53
+ let dir = tempdir().unwrap();
54
+ let file_path = dir.path().join("test.txt");
55
+ let mut file = File::create(&file_path).unwrap();
56
+ file.write_all(b"Hello, world!").unwrap();
57
+
58
+ let config = ExtractionConfig::default();
59
+ let result = extract_file(&file_path, None, &config).await;
60
+
61
+ assert!(result.is_ok());
62
+ let result = result.unwrap();
63
+ assert_text_content(&result.content, "Hello, world!");
64
+ assert_eq!(result.mime_type, "text/plain");
65
+ }
66
+
67
+ #[tokio::test]
68
+ async fn test_extract_file_with_mime_override() {
69
+ let dir = tempdir().unwrap();
70
+ let file_path = dir.path().join("test.dat");
71
+ let mut file = File::create(&file_path).unwrap();
72
+ file.write_all(b"test content").unwrap();
73
+
74
+ let config = ExtractionConfig::default();
75
+ let result = extract_file(&file_path, Some("text/plain"), &config).await;
76
+
77
+ assert!(result.is_ok());
78
+ let result = result.unwrap();
79
+ assert_eq!(result.mime_type, "text/plain");
80
+ }
81
+
82
+ #[tokio::test]
83
+ async fn test_extract_file_nonexistent() {
84
+ let config = ExtractionConfig::default();
85
+ let result = extract_file("/nonexistent/file.txt", None, &config).await;
86
+ assert!(result.is_err());
87
+ }
88
+
89
+ #[tokio::test]
90
+ async fn test_extract_bytes_basic() {
91
+ let config = ExtractionConfig::default();
92
+ let result = extract_bytes(b"test content", "text/plain", &config).await;
93
+
94
+ assert!(result.is_ok());
95
+ let result = result.unwrap();
96
+ assert_text_content(&result.content, "test content");
97
+ assert_eq!(result.mime_type, "text/plain");
98
+ }
99
+
100
+ #[tokio::test]
101
+ async fn test_extract_bytes_invalid_mime() {
102
+ let config = ExtractionConfig::default();
103
+ let result = extract_bytes(b"test", "invalid/mime", &config).await;
104
+ assert!(result.is_err());
105
+ }
106
+
107
+ #[tokio::test]
108
+ async fn test_batch_extract_file() {
109
+ let dir = tempdir().unwrap();
110
+
111
+ let file1 = dir.path().join("test1.txt");
112
+ let file2 = dir.path().join("test2.txt");
113
+
114
+ File::create(&file1).unwrap().write_all(b"content 1").unwrap();
115
+ File::create(&file2).unwrap().write_all(b"content 2").unwrap();
116
+
117
+ let config = ExtractionConfig::default();
118
+ let paths = vec![file1, file2];
119
+ let results = batch_extract_file(paths, &config).await;
120
+
121
+ assert!(results.is_ok());
122
+ let results = results.unwrap();
123
+ assert_eq!(results.len(), 2);
124
+ assert_text_content(&results[0].content, "content 1");
125
+ assert_text_content(&results[1].content, "content 2");
126
+ }
127
+
128
+ #[tokio::test]
129
+ async fn test_batch_extract_file_empty() {
130
+ let config = ExtractionConfig::default();
131
+ let paths: Vec<std::path::PathBuf> = vec![];
132
+ let results = batch_extract_file(paths, &config).await;
133
+
134
+ assert!(results.is_ok());
135
+ assert_eq!(results.unwrap().len(), 0);
136
+ }
137
+
138
+ #[tokio::test]
139
+ async fn test_batch_extract_bytes() {
140
+ let config = ExtractionConfig::default();
141
+ let contents = vec![
142
+ (b"content 1".as_slice(), "text/plain"),
143
+ (b"content 2".as_slice(), "text/plain"),
144
+ ];
145
+ let owned_contents: Vec<(Vec<u8>, String)> = contents
146
+ .into_iter()
147
+ .map(|(bytes, mime)| (bytes.to_vec(), mime.to_string()))
148
+ .collect();
149
+ let results = batch_extract_bytes(owned_contents, &config).await;
150
+
151
+ assert!(results.is_ok());
152
+ let results = results.unwrap();
153
+ assert_eq!(results.len(), 2);
154
+ assert_text_content(&results[0].content, "content 1");
155
+ assert_text_content(&results[1].content, "content 2");
156
+ }
157
+
158
+ #[test]
159
+ fn test_sync_wrappers() {
160
+ let dir = tempdir().unwrap();
161
+ let file_path = dir.path().join("test.txt");
162
+ File::create(&file_path).unwrap().write_all(b"sync test").unwrap();
163
+
164
+ let config = ExtractionConfig::default();
165
+
166
+ let result = extract_file_sync(&file_path, None, &config);
167
+ assert!(result.is_ok());
168
+ let result = result.unwrap();
169
+ assert_text_content(&result.content, "sync test");
170
+
171
+ let result = extract_bytes_sync(b"test", "text/plain", &config);
172
+ assert!(result.is_ok());
173
+ }
174
+
175
+ #[tokio::test]
176
+ async fn test_extractor_cache() {
177
+ let config = ExtractionConfig::default();
178
+
179
+ let result1 = extract_bytes(b"test 1", "text/plain", &config).await;
180
+ assert!(result1.is_ok());
181
+ let result1 = result1.unwrap();
182
+
183
+ let result2 = extract_bytes(b"test 2", "text/plain", &config).await;
184
+ assert!(result2.is_ok());
185
+ let result2 = result2.unwrap();
186
+
187
+ assert_text_content(&result1.content, "test 1");
188
+ assert_text_content(&result2.content, "test 2");
189
+
190
+ let result3 = extract_bytes(b"# test 3", "text/markdown", &config).await;
191
+ assert!(result3.is_ok());
192
+ }
193
+
194
+ #[tokio::test]
195
+ async fn test_extract_file_empty() {
196
+ let dir = tempdir().unwrap();
197
+ let file_path = dir.path().join("empty.txt");
198
+ File::create(&file_path).unwrap();
199
+
200
+ let config = ExtractionConfig::default();
201
+ let result = extract_file(&file_path, None, &config).await;
202
+
203
+ assert!(result.is_ok());
204
+ let result = result.unwrap();
205
+ assert_eq!(result.content, "");
206
+ }
207
+
208
+ #[tokio::test]
209
+ async fn test_extract_bytes_empty() {
210
+ let config = ExtractionConfig::default();
211
+ let result = extract_bytes(b"", "text/plain", &config).await;
212
+
213
+ assert!(result.is_ok());
214
+ let result = result.unwrap();
215
+ assert_eq!(result.content, "");
216
+ }
217
+
218
+ #[tokio::test]
219
+ async fn test_extract_file_whitespace_only() {
220
+ let dir = tempdir().unwrap();
221
+ let file_path = dir.path().join("whitespace.txt");
222
+ File::create(&file_path).unwrap().write_all(b" \n\t \n ").unwrap();
223
+
224
+ let config = ExtractionConfig::default();
225
+ let result = extract_file(&file_path, None, &config).await;
226
+
227
+ assert!(result.is_ok());
228
+ }
229
+
230
+ #[tokio::test]
231
+ async fn test_extract_file_very_long_path() {
232
+ let dir = tempdir().unwrap();
233
+ let long_name = "a".repeat(200);
234
+ let file_path = dir.path().join(format!("{}.txt", long_name));
235
+
236
+ if let Ok(mut f) = File::create(&file_path) {
237
+ f.write_all(b"content").unwrap();
238
+ let config = ExtractionConfig::default();
239
+ let result = extract_file(&file_path, None, &config).await;
240
+ assert!(result.is_ok() || result.is_err());
241
+ }
242
+ }
243
+
244
+ #[tokio::test]
245
+ async fn test_extract_file_special_characters_in_path() {
246
+ let dir = tempdir().unwrap();
247
+ let file_path = dir.path().join("test with spaces & symbols!.txt");
248
+ File::create(&file_path).unwrap().write_all(b"content").unwrap();
249
+
250
+ let config = ExtractionConfig::default();
251
+ let result = extract_file(&file_path, None, &config).await;
252
+
253
+ assert!(result.is_ok());
254
+ let result = result.unwrap();
255
+ assert_text_content(&result.content, "content");
256
+ }
257
+
258
+ #[tokio::test]
259
+ async fn test_extract_file_unicode_filename() {
260
+ let dir = tempdir().unwrap();
261
+ let file_path = dir.path().join("测试文件名.txt");
262
+ File::create(&file_path).unwrap().write_all(b"content").unwrap();
263
+
264
+ let config = ExtractionConfig::default();
265
+ let result = extract_file(&file_path, None, &config).await;
266
+
267
+ assert!(result.is_ok());
268
+ }
269
+
270
+ #[tokio::test]
271
+ async fn test_extract_bytes_unsupported_mime() {
272
+ let config = ExtractionConfig::default();
273
+ let result = extract_bytes(b"test", "application/x-unknown-format", &config).await;
274
+
275
+ assert!(result.is_err());
276
+ use crate::KreuzbergError;
277
+ assert!(matches!(result.unwrap_err(), KreuzbergError::UnsupportedFormat(_)));
278
+ }
279
+
280
+ #[tokio::test]
281
+ async fn test_batch_extract_file_with_errors() {
282
+ let dir = tempdir().unwrap();
283
+
284
+ let valid_file = dir.path().join("valid.txt");
285
+ File::create(&valid_file).unwrap().write_all(b"valid content").unwrap();
286
+
287
+ let invalid_file = dir.path().join("nonexistent.txt");
288
+
289
+ let config = ExtractionConfig::default();
290
+ let paths = vec![valid_file, invalid_file];
291
+ let results = batch_extract_file(paths, &config).await;
292
+
293
+ assert!(results.is_ok());
294
+ let results = results.unwrap();
295
+ assert_eq!(results.len(), 2);
296
+ assert_text_content(&results[0].content, "valid content");
297
+ assert!(results[1].metadata.error.is_some());
298
+ }
299
+
300
+ #[tokio::test]
301
+ async fn test_batch_extract_bytes_mixed_valid_invalid() {
302
+ let config = ExtractionConfig::default();
303
+ let contents = vec![
304
+ (b"valid 1".as_slice(), "text/plain"),
305
+ (b"invalid".as_slice(), "invalid/mime"),
306
+ (b"valid 2".as_slice(), "text/plain"),
307
+ ];
308
+ let owned_contents: Vec<(Vec<u8>, String)> = contents
309
+ .into_iter()
310
+ .map(|(bytes, mime)| (bytes.to_vec(), mime.to_string()))
311
+ .collect();
312
+ let results = batch_extract_bytes(owned_contents, &config).await;
313
+
314
+ assert!(results.is_ok());
315
+ let results = results.unwrap();
316
+ assert_eq!(results.len(), 3);
317
+ assert_text_content(&results[0].content, "valid 1");
318
+ assert!(results[1].metadata.error.is_some());
319
+ assert_text_content(&results[2].content, "valid 2");
320
+ }
321
+
322
+ #[tokio::test]
323
+ async fn test_batch_extract_bytes_all_invalid() {
324
+ let config = ExtractionConfig::default();
325
+ let contents = vec![
326
+ (b"test 1".as_slice(), "invalid/mime1"),
327
+ (b"test 2".as_slice(), "invalid/mime2"),
328
+ ];
329
+ let owned_contents: Vec<(Vec<u8>, String)> = contents
330
+ .into_iter()
331
+ .map(|(bytes, mime)| (bytes.to_vec(), mime.to_string()))
332
+ .collect();
333
+ let results = batch_extract_bytes(owned_contents, &config).await;
334
+
335
+ assert!(results.is_ok());
336
+ let results = results.unwrap();
337
+ assert_eq!(results.len(), 2);
338
+ assert!(results[0].metadata.error.is_some());
339
+ assert!(results[1].metadata.error.is_some());
340
+ }
341
+
342
+ #[tokio::test]
343
+ async fn test_extract_bytes_very_large() {
344
+ let large_content = vec![b'a'; 10_000_000];
345
+ let config = ExtractionConfig::default();
346
+ let result = extract_bytes(&large_content, "text/plain", &config).await;
347
+
348
+ assert!(result.is_ok());
349
+ let result = result.unwrap();
350
+ let trimmed_len = result.content.trim_end_matches('\n').len();
351
+ assert_eq!(trimmed_len, 10_000_000);
352
+ }
353
+
354
+ #[tokio::test]
355
+ async fn test_batch_extract_large_count() {
356
+ let dir = tempdir().unwrap();
357
+ let mut paths = Vec::new();
358
+
359
+ for i in 0..100 {
360
+ let file_path = dir.path().join(format!("file{}.txt", i));
361
+ File::create(&file_path)
362
+ .unwrap()
363
+ .write_all(format!("content {}", i).as_bytes())
364
+ .unwrap();
365
+ paths.push(file_path);
366
+ }
367
+
368
+ let config = ExtractionConfig::default();
369
+ let results = batch_extract_file(paths, &config).await;
370
+
371
+ assert!(results.is_ok());
372
+ let results = results.unwrap();
373
+ assert_eq!(results.len(), 100);
374
+
375
+ for (i, result) in results.iter().enumerate() {
376
+ assert_text_content(&result.content, &format!("content {}", i));
377
+ }
378
+ }
379
+
380
+ #[tokio::test]
381
+ async fn test_extract_file_mime_detection_fallback() {
382
+ let dir = tempdir().unwrap();
383
+ let file_path = dir.path().join("testfile");
384
+ File::create(&file_path)
385
+ .unwrap()
386
+ .write_all(b"plain text content")
387
+ .unwrap();
388
+
389
+ let config = ExtractionConfig::default();
390
+ let result = extract_file(&file_path, None, &config).await;
391
+
392
+ assert!(result.is_ok() || result.is_err());
393
+ }
394
+
395
+ #[tokio::test]
396
+ async fn test_extract_file_wrong_mime_override() {
397
+ let dir = tempdir().unwrap();
398
+ let file_path = dir.path().join("test.txt");
399
+ File::create(&file_path).unwrap().write_all(b"plain text").unwrap();
400
+
401
+ let config = ExtractionConfig::default();
402
+ let result = extract_file(&file_path, Some("application/pdf"), &config).await;
403
+
404
+ assert!(result.is_err() || result.is_ok());
405
+ }
406
+
407
+ #[test]
408
+ fn test_sync_wrapper_nonexistent_file() {
409
+ let config = ExtractionConfig::default();
410
+ let result = extract_file_sync("/nonexistent/path.txt", None, &config);
411
+
412
+ assert!(result.is_err());
413
+ use crate::KreuzbergError;
414
+ assert!(matches!(result.unwrap_err(), KreuzbergError::Validation { .. }));
415
+ }
416
+
417
+ #[test]
418
+ fn test_sync_wrapper_batch_empty() {
419
+ let config = ExtractionConfig::default();
420
+ let paths: Vec<std::path::PathBuf> = vec![];
421
+ let results = batch_extract_file_sync(paths, &config);
422
+
423
+ assert!(results.is_ok());
424
+ assert_eq!(results.unwrap().len(), 0);
425
+ }
426
+
427
+ #[test]
428
+ fn test_sync_wrapper_batch_bytes_empty() {
429
+ let config = ExtractionConfig::default();
430
+ let contents: Vec<(Vec<u8>, String)> = vec![];
431
+ let results = batch_extract_bytes_sync(contents, &config);
432
+
433
+ assert!(results.is_ok());
434
+ assert_eq!(results.unwrap().len(), 0);
435
+ }
436
+
437
+ #[tokio::test]
438
+ async fn test_concurrent_extractions_same_mime() {
439
+ use tokio::task::JoinSet;
440
+
441
+ let config = Arc::new(ExtractionConfig::default());
442
+ let mut tasks = JoinSet::new();
443
+
444
+ for i in 0..50 {
445
+ let config_clone = Arc::clone(&config);
446
+ tasks.spawn(async move {
447
+ let content = format!("test content {}", i);
448
+ extract_bytes(content.as_bytes(), "text/plain", &config_clone).await
449
+ });
450
+ }
451
+
452
+ let mut success_count = 0;
453
+ while let Some(task_result) = tasks.join_next().await {
454
+ if let Ok(Ok(_)) = task_result {
455
+ success_count += 1;
456
+ }
457
+ }
458
+
459
+ assert_eq!(success_count, 50);
460
+ }
461
+
462
+ #[serial]
463
+ #[tokio::test]
464
+ async fn test_concurrent_extractions_different_mimes() {
465
+ use tokio::task::JoinSet;
466
+
467
+ let config = Arc::new(ExtractionConfig::default());
468
+ let mut tasks = JoinSet::new();
469
+
470
+ let mime_types = ["text/plain", "text/markdown"];
471
+
472
+ for i in 0..30 {
473
+ let config_clone = Arc::clone(&config);
474
+ let mime = mime_types[i % mime_types.len()];
475
+ tasks.spawn(async move {
476
+ let content = format!("test {}", i);
477
+ extract_bytes(content.as_bytes(), mime, &config_clone).await
478
+ });
479
+ }
480
+
481
+ let mut success_count = 0;
482
+ while let Some(task_result) = tasks.join_next().await {
483
+ if let Ok(Ok(_)) = task_result {
484
+ success_count += 1;
485
+ }
486
+ }
487
+
488
+ assert_eq!(success_count, 30);
489
+ }
490
+ }
@@ -0,0 +1,208 @@
1
+ //! Synchronous wrappers for extraction operations.
2
+ //!
3
+ //! This module provides blocking synchronous wrappers around async extraction functions
4
+ //! for use in non-async contexts. Uses a global Tokio runtime for optimal performance.
5
+
6
+ use crate::Result;
7
+ use crate::core::config::ExtractionConfig;
8
+ use crate::types::ExtractionResult;
9
+
10
+ #[cfg(feature = "tokio-runtime")]
11
+ use std::path::Path;
12
+
13
+ #[cfg(feature = "tokio-runtime")]
14
+ use once_cell::sync::Lazy;
15
+
16
+ #[cfg(feature = "tokio-runtime")]
17
+ use super::batch::{batch_extract_bytes, batch_extract_file};
18
+ #[cfg(feature = "tokio-runtime")]
19
+ use super::bytes::extract_bytes;
20
+ #[cfg(feature = "tokio-runtime")]
21
+ use super::file::extract_file;
22
+
23
+ /// Global Tokio runtime for synchronous operations.
24
+ ///
25
+ /// This runtime is lazily initialized on first use and shared across all sync wrappers.
26
+ /// Using a global runtime instead of creating one per call provides 100x+ performance improvement.
27
+ ///
28
+ /// # Safety
29
+ ///
30
+ /// The `.expect()` here is justified because:
31
+ /// 1. Runtime creation can only fail due to system resource exhaustion (OOM, thread limit)
32
+ /// 2. If runtime creation fails, the process is already in a critical state
33
+ /// 3. This is a one-time initialization - if it fails, nothing will work
34
+ /// 4. Better to fail fast than return errors from every sync operation
35
+ ///
36
+ /// # Availability
37
+ ///
38
+ /// This static is only available when the `tokio-runtime` feature is enabled.
39
+ /// For WASM targets, use the truly synchronous extraction functions instead.
40
+ #[cfg(feature = "tokio-runtime")]
41
+ static GLOBAL_RUNTIME: Lazy<tokio::runtime::Runtime> = Lazy::new(|| {
42
+ tokio::runtime::Builder::new_multi_thread()
43
+ .enable_all()
44
+ .build()
45
+ .expect("Failed to create global Tokio runtime - system may be out of resources")
46
+ });
47
+
48
+ /// Synchronous wrapper for `extract_file`.
49
+ ///
50
+ /// This is a convenience function that blocks the current thread until extraction completes.
51
+ /// For async code, use `extract_file` directly.
52
+ ///
53
+ /// Uses the global Tokio runtime for 100x+ performance improvement over creating
54
+ /// a new runtime per call. Always uses the global runtime to avoid nested runtime issues.
55
+ ///
56
+ /// This function is only available with the `tokio-runtime` feature. For WASM targets,
57
+ /// use a truly synchronous extraction approach instead.
58
+ ///
59
+ /// # Example
60
+ ///
61
+ /// ```rust,no_run
62
+ /// use kreuzberg::core::extractor::extract_file_sync;
63
+ /// use kreuzberg::core::config::ExtractionConfig;
64
+ ///
65
+ /// let config = ExtractionConfig::default();
66
+ /// let result = extract_file_sync("document.pdf", None, &config)?;
67
+ /// println!("Content: {}", result.content);
68
+ /// # Ok::<(), kreuzberg::KreuzbergError>(())
69
+ /// ```
70
+ #[cfg(feature = "tokio-runtime")]
71
+ pub fn extract_file_sync(
72
+ path: impl AsRef<Path>,
73
+ mime_type: Option<&str>,
74
+ config: &ExtractionConfig,
75
+ ) -> Result<ExtractionResult> {
76
+ GLOBAL_RUNTIME.block_on(extract_file(path, mime_type, config))
77
+ }
78
+
79
+ /// Synchronous wrapper for `extract_bytes`.
80
+ ///
81
+ /// Uses the global Tokio runtime for 100x+ performance improvement over creating
82
+ /// a new runtime per call.
83
+ ///
84
+ /// With the `tokio-runtime` feature, this blocks the current thread using the global
85
+ /// Tokio runtime. Without it (WASM), this calls a truly synchronous implementation.
86
+ ///
87
+ /// # Example
88
+ ///
89
+ /// ```rust,no_run
90
+ /// use kreuzberg::core::extractor::extract_bytes_sync;
91
+ /// use kreuzberg::core::config::ExtractionConfig;
92
+ ///
93
+ /// let config = ExtractionConfig::default();
94
+ /// let bytes = b"Hello, world!";
95
+ /// let result = extract_bytes_sync(bytes, "text/plain", &config)?;
96
+ /// println!("Content: {}", result.content);
97
+ /// # Ok::<(), kreuzberg::KreuzbergError>(())
98
+ /// ```
99
+ #[cfg(feature = "tokio-runtime")]
100
+ pub fn extract_bytes_sync(content: &[u8], mime_type: &str, config: &ExtractionConfig) -> Result<ExtractionResult> {
101
+ GLOBAL_RUNTIME.block_on(extract_bytes(content, mime_type, config))
102
+ }
103
+
104
+ /// Synchronous wrapper for `extract_bytes` (WASM-compatible version).
105
+ ///
106
+ /// This is a truly synchronous implementation without tokio runtime dependency.
107
+ /// It calls `extract_bytes_sync_impl()` to perform the extraction.
108
+ #[cfg(not(feature = "tokio-runtime"))]
109
+ pub fn extract_bytes_sync(content: &[u8], mime_type: &str, config: &ExtractionConfig) -> Result<ExtractionResult> {
110
+ super::legacy::extract_bytes_sync_impl(content.to_vec(), Some(mime_type.to_string()), Some(config.clone()))
111
+ }
112
+
113
+ /// Synchronous wrapper for `batch_extract_file`.
114
+ ///
115
+ /// Uses the global Tokio runtime for 100x+ performance improvement over creating
116
+ /// a new runtime per call.
117
+ ///
118
+ /// This function is only available with the `tokio-runtime` feature. For WASM targets,
119
+ /// use a truly synchronous extraction approach instead.
120
+ ///
121
+ /// # Example
122
+ ///
123
+ /// ```rust,no_run
124
+ /// use kreuzberg::core::extractor::batch_extract_file_sync;
125
+ /// use kreuzberg::core::config::ExtractionConfig;
126
+ ///
127
+ /// let config = ExtractionConfig::default();
128
+ /// let paths = vec!["doc1.pdf", "doc2.pdf"];
129
+ /// let results = batch_extract_file_sync(paths, &config)?;
130
+ /// println!("Processed {} files", results.len());
131
+ /// # Ok::<(), kreuzberg::KreuzbergError>(())
132
+ /// ```
133
+ #[cfg(feature = "tokio-runtime")]
134
+ pub fn batch_extract_file_sync(
135
+ paths: Vec<impl AsRef<Path>>,
136
+ config: &ExtractionConfig,
137
+ ) -> Result<Vec<ExtractionResult>> {
138
+ GLOBAL_RUNTIME.block_on(batch_extract_file(paths, config))
139
+ }
140
+
141
+ /// Synchronous wrapper for `batch_extract_bytes`.
142
+ ///
143
+ /// Uses the global Tokio runtime for 100x+ performance improvement over creating
144
+ /// a new runtime per call.
145
+ ///
146
+ /// With the `tokio-runtime` feature, this blocks the current thread using the global
147
+ /// Tokio runtime. Without it (WASM), this calls a truly synchronous implementation
148
+ /// that iterates through items and calls `extract_bytes_sync()`.
149
+ ///
150
+ /// # Example
151
+ ///
152
+ /// ```rust,no_run
153
+ /// use kreuzberg::core::extractor::batch_extract_bytes_sync;
154
+ /// use kreuzberg::core::config::ExtractionConfig;
155
+ ///
156
+ /// let config = ExtractionConfig::default();
157
+ /// let contents = vec![
158
+ /// (b"content 1".to_vec(), "text/plain".to_string()),
159
+ /// (b"content 2".to_vec(), "text/plain".to_string()),
160
+ /// ];
161
+ /// let results = batch_extract_bytes_sync(contents, &config)?;
162
+ /// println!("Processed {} items", results.len());
163
+ /// # Ok::<(), kreuzberg::KreuzbergError>(())
164
+ /// ```
165
+ #[cfg(feature = "tokio-runtime")]
166
+ pub fn batch_extract_bytes_sync(
167
+ contents: Vec<(Vec<u8>, String)>,
168
+ config: &ExtractionConfig,
169
+ ) -> Result<Vec<ExtractionResult>> {
170
+ GLOBAL_RUNTIME.block_on(batch_extract_bytes(contents, config))
171
+ }
172
+
173
+ /// Synchronous wrapper for `batch_extract_bytes` (WASM-compatible version).
174
+ ///
175
+ /// This is a truly synchronous implementation that iterates through items
176
+ /// and calls `extract_bytes_sync()` for each.
177
+ #[cfg(not(feature = "tokio-runtime"))]
178
+ pub fn batch_extract_bytes_sync(
179
+ contents: Vec<(Vec<u8>, String)>,
180
+ config: &ExtractionConfig,
181
+ ) -> Result<Vec<ExtractionResult>> {
182
+ use crate::types::{ErrorMetadata, Metadata};
183
+ use crate::utils::intern_mime_type;
184
+
185
+ let mut results = Vec::with_capacity(contents.len());
186
+ for (content, mime_type) in contents {
187
+ let result = extract_bytes_sync(&content, &mime_type, config);
188
+ results.push(result.unwrap_or_else(|e| ExtractionResult {
189
+ content: format!("Error: {}", e),
190
+ mime_type: intern_mime_type("text/plain").to_string(),
191
+ metadata: Metadata {
192
+ error: Some(ErrorMetadata {
193
+ error_type: format!("{:?}", e),
194
+ message: e.to_string(),
195
+ }),
196
+ ..Default::default()
197
+ },
198
+ tables: vec![],
199
+ detected_languages: None,
200
+ chunks: None,
201
+ images: None,
202
+ djot_content: None,
203
+ pages: None,
204
+ elements: None,
205
+ }));
206
+ }
207
+ Ok(results)
208
+ }