Class: DocxLoader
Defined in: packages/agentos/src/cognition/memory/io/ingestion/DocxLoader.ts:298
Document loader for Microsoft Word (.docx) files.
Uses mammoth.extractRawText() to strip all styling and return plain
prose text, which is then stored as the content field. The metadata
block includes an approximate wordCount.
Before mammoth reads a file, the loader inflates every entry of its ZIP archive under DocxLoaderOptions.maxInflatedBytes (128 MiB unless given), one entry's output at a time, and refuses the file with DocumentTooLargeError once the entries pass the bound together.
Implements
Examples
const loader = new DocxLoader();
const doc = await loader.load('/docs/spec.docx');
console.log(doc.metadata.wordCount); // e.g. 1842
const loader = new DocxLoader({ maxInflatedBytes: 64 * 1024 * 1024 });
try {
const doc = await loader.load(uploadedBuffer);
} catch (error) {
if (error instanceof DocumentTooLargeError) {
console.log(`inflates past ${error.limit} bytes`); // mammoth never ran
}
}
Implements
Constructors
Constructor
new DocxLoader(
options?):DocxLoader
Defined in: packages/agentos/src/cognition/memory/io/ingestion/DocxLoader.ts:309
Parameters
options?
DocxLoaderOptions = {}
The loader's options; with none, the bound is 128 MiB.
Returns
DocxLoader
Throws
When maxInflatedBytes is not a positive, finite number.
Properties
supportedExtensions
readonlysupportedExtensions:string[]
Defined in: packages/agentos/src/cognition/memory/io/ingestion/DocxLoader.ts:300
File extensions this loader handles, each with a leading dot.
Used by LoaderRegistry to route file paths to the correct loader.
Example
['.md', '.mdx']
Implementation of
IDocumentLoader.supportedExtensions
Methods
canLoad()
canLoad(
source):boolean
Defined in: packages/agentos/src/cognition/memory/io/ingestion/DocxLoader.ts:324
Returns true when this loader is capable of handling source.
For string sources the check is purely extension-based. For Buffer
sources the loader may inspect magic bytes when relevant.
Parameters
source
Absolute file path or raw bytes.
string | Buffer
Returns
boolean
Implementation of
load()
load(
source,_options?):Promise<LoadedDocument>
Defined in: packages/agentos/src/cognition/memory/io/ingestion/DocxLoader.ts:344
Parses source and returns a normalised LoadedDocument.
When source is a string the loader treats it as an absolute (or
resolvable) file path and reads the file from disk. When source is a
Buffer the loader parses the bytes directly and derives as much
metadata as possible from the buffer content alone.