AI Search Phase 2 DOCX Extraction
Use this prompt to implement deterministic DOCX text extraction for AI indexing only.
Scope
- Work in
src/lib/search/ai/extraction; do not usesrc/lib/content-extraction.ts. - Preserve existing text-like and PDF extraction behavior.
- Support
.docxandapplication/vnd.openxmlformats-officedocument.wordprocessingml.document, including parameterized MIME values. - Keep legacy
.doc, ODT, RTF, Google-native formats, PPTX, XLSX, OCR, and embedded image extraction out of this phase. - Use
mammoth.extractRawTextfor plain text and paragraph breaks where Mammoth provides them. - Skip images, charts, SmartArt, diagrams, tracked-change/comment metadata, and complex formatting preservation.
Implementation Notes
- Add
mammothif it is not already present. Mammoth 1.12 shipslib/index.d.ts;@types/mammothis not published. - Add a dedicated DOCX parser module with a typed parser error carrying sanitized messages,
cause, and parser context. - Route DOCX inputs through the DOCX extractor before generic UTF decoding.
- Keep unsupported document policies for legacy
.doc, ODT, RTF, and Google-native formats. - Use existing normalization and byte-limit enforcement.
- Route BackendIndexingRunner telemetry with
extractionMethod: "docx". - Use sanitized taxonomy messages for corrupt and encrypted DOCX failures.
Required Tests
- Valid DOCX with text.
- Empty DOCX returns empty extractor output.
- Corrupt DOCX fails with the DOCX parse taxonomy.
- Password-protected/encrypted DOCX fails or skips with the DOCX encrypted taxonomy.