Skip to main content

Class: LoaderRegistry

Defined in: packages/agentos/src/cognition/memory/io/ingestion/LoaderRegistry.ts:104

Central registry mapping file extensions to IDocumentLoader implementations.

Built-in loaders (registered automatically)​

ExtensionsLoader
.txt, .csv, .tsv, .json, .yaml, .ymlTextLoader
.md, .mdxMarkdownLoader
.html, .htmHtmlLoader
.pdfPdfLoader
.docxDocxLoader

Conditional loaders (registered when available)​

ConditionLoader
tesseract.js installedfactory from createOcrPdfLoader (overrides PDF)
python3 -m docling availablefactory from createDoclingLoader (overrides PDF + DOCX)

Registering a custom loader​

const registry = new LoaderRegistry();
registry.register(new PdfLoader());
const doc = await registry.loadFile('/reports/q3.pdf');

Using loadFile​

const registry = new LoaderRegistry();
const doc = await registry.loadFile('/notes/meeting.md');
console.log(doc.metadata.title);

Constructors​

Constructor​

new LoaderRegistry(): LoaderRegistry

Defined in: packages/agentos/src/cognition/memory/io/ingestion/LoaderRegistry.ts:130

Creates a new registry pre-populated with the built-in loaders.

Loader registration order determines conflict resolution: later registrations override earlier ones for the same extension.

Registration order:

  1. TextLoader, MarkdownLoader, HtmlLoader — core text formats.
  2. PdfLoader (with injected OCR + Docling loaders) — PDF extraction.
  3. DocxLoader — DOCX extraction.
  4. Optional: an override from createOcrPdfLoader when tesseract.js is installed.
  5. Optional: an override from createDoclingLoader when Python Docling is available. The Docling-backed loader supports both .pdf and .docx, so it supersedes both PdfLoader and DocxLoader when present.

Returns​

LoaderRegistry

Methods​

getLoader()​

getLoader(extensionOrPath): IDocumentLoader | undefined

Defined in: packages/agentos/src/cognition/memory/io/ingestion/LoaderRegistry.ts:198

Retrieve the loader registered for extensionOrPath.

Both bare extensions (.md, md) and full file paths (/docs/guide.md) are accepted.

Parameters​

extensionOrPath​

string

File extension or full path.

Returns​

IDocumentLoader | undefined

The matching IDocumentLoader, or undefined when no loader is registered for the detected extension.

Example​

const loader = registry.getLoader('.md');
const loader2 = registry.getLoader('README.md');

getSupportedExtensions()​

getSupportedExtensions(): string[]

Defined in: packages/agentos/src/cognition/memory/io/ingestion/LoaderRegistry.ts:215

Return a sorted array of all extensions currently registered.

Each extension is returned with a leading dot in lower-case, e.g. ['.csv', '.htm', '.html', '.json', '.md', …].

Returns​

string[]

Sorted array of registered extension strings.


loadFile()​

loadFile(filePath, options?): Promise<LoadedDocument>

Defined in: packages/agentos/src/cognition/memory/io/ingestion/LoaderRegistry.ts:239

Convenience method: detect format from filePath, find the matching loader, and delegate to its load() method.

Parameters​

filePath​

string

Absolute (or resolvable relative) file path.

options?​

LoadOptions

Optional load hints forwarded to the loader.

Returns​

Promise<LoadedDocument>

A promise resolving to the LoadedDocument.

Throws​

When no loader is registered for the file's extension.

Throws​

When the underlying loader's load() throws.

Example​

const doc = await registry.loadFile('/notes/architecture.md');

register()​

register(loader): void

Defined in: packages/agentos/src/cognition/memory/io/ingestion/LoaderRegistry.ts:172

Register a loader for all extensions it declares.

If a previously registered loader already handles one of the extension, it is replaced. This makes it trivial to swap in a higher-fidelity implementation for any format.

Parameters​

loader​

IDocumentLoader

The loader instance to register.

Returns​

void

Example​

registry.register(new PdfLoader());