Nomad changes
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s

This commit is contained in:
Henrik Jess Nielsen
2026-06-01 23:40:55 +02:00
parent 72b1a0a6ed
commit b4c07d3693
5723 changed files with 1130655 additions and 0 deletions

30
docs/snippets/wasm/cache/ocr-cache.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
import { extractBytes, initWasm, TesseractWasmBackend } from "@kreuzberg/wasm";
async function demonstrateOcrCaching() {
await initWasm();
const backend = new TesseractWasmBackend();
await backend.initialize();
console.log("Tesseract WASM backend loaded - models cached");
const imageBytes = new Uint8Array(await fetch("page1.png").then((r) => r.arrayBuffer()));
console.time("First OCR (with model load)");
const _result1 = await extractBytes(imageBytes, "image/png", {
ocr: { backend: "tesseract-wasm", language: "eng" },
});
console.timeEnd("First OCR (with model load)");
console.log("Model cached in memory");
const imageBytes2 = new Uint8Array(await fetch("page2.png").then((r) => r.arrayBuffer()));
console.time("Second OCR (model cached)");
const _result2 = await extractBytes(imageBytes2, "image/png", {
ocr: { backend: "tesseract-wasm", language: "eng" },
});
console.timeEnd("Second OCR (model cached)");
}
demonstrateOcrCaching().catch(console.error);