Files
fil/docs/snippets/wasm/plugins/plugin_extractor.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

1.3 KiB

Custom Plugin Usage Pattern

Demonstrate the pattern for using registered plugins during document extraction.

import init, { extractBytes, registerPostProcessor } from "kreuzberg-wasm";

await init();

// Register a custom post-processor
const customProcessor = {
  processingStage: () => "post-extraction",
  process: (result) => {
    console.log("Post-processor: enriching extraction result");
    return {
      ...result,
      metadata: {
        ...result.metadata,
        enriched: true,
        processorApplied: "customProcessor",
      },
    };
  },
};

registerPostProcessor(customProcessor);

// Extract document with registered plugin
async function extractWithPlugins(fileBytes, mimeType) {
  const config = {
    ocr: null,
    chunking: null,
    enableQualityProcessing: false,
  };

  // Extraction automatically applies registered post-processors
  const result = await extractBytes(fileBytes, mimeType, config);

  console.log("Extraction complete");
  console.log("Plugins applied:", result.metadata?.enriched);

  return result;
}

// Usage
const pdfBytes = new Uint8Array([
  /* PDF content */
]);
const result = await extractWithPlugins(pdfBytes, "application/pdf");
console.log("Final result:", result);

The extraction pipeline automatically applies all registered plugins in the correct order.