feat: PDF ingestion via unpdf with page chunking
Summary
Adds an memorix_ingest_pdf MCP tool that extracts text from PDF files using unpdf and stores each page (or chunk) as a memorix observation.
What's included
src/multimodal/pdf-loader.ts— PDF text extractor with:- Page-level chunking (one observation per page by default)
- Configurable max pages
- Graceful handling of empty/corrupted PDFs
- Optional
unpdfdependency (clear error if not installed)
src/server.ts— MCP tool registration (memorix_ingest_pdf)tests/multimodal/pdf-loader.test.ts— 4 tests covering:- Multi-page extraction and observation storage
- Empty PDF handling
- Page limit configuration
- Missing file error handling
Design decisions
unpdfis an optional peer dependency — tool returns clear error if not installed (npm install unpdf).- Each page becomes a separate observation for granular search/retrieval.
- Stores as
how-it-worksobservation type with PDF metadata (page number, total pages, filename) in facts. - No heavy native dependencies —
unpdfis pure JS/WASM.
Tests
4 pass, 0 fail
Thanks for working on PDF ingestion — page-level storage is a good direction, but this branch still has a few hard blockers.
- The test file is using
bun:test, while the repo runsvitestin CI. src/multimodal/pdf-loader.tscurrently fails typecheck becauseunpdfis dynamically imported but not represented in a way TypeScript can resolve in this repo's current dependency/type setup.- In
src/server.ts, the object flowing intostoreObservationis inferred astype: stringrather than a properObservationType.
So at the moment this is not just a dependency-install issue — it needs one more pass to make the optional dependency story and the repo's type/test expectations line up.
All three are valid — I'll fix them:
- bun:test → vitest: Will switch the test file to vitest imports.
- unpdf typecheck: Will declare
unpdfas an optional peer dependency inpackage.jsonand add a@types/unpdfshim or inline type declaration so the dynamic import resolves under TypeScript without requiring the package at build time. - ObservationType: Will add an explicit type assertion on the object passed to
storeObservationso it satisfiesObservationTyperather than widening tostring.
The optional dependency story for global installs is the part that needs the most care — I'll make sure the error path when unpdf is absent gives users a clear install instruction rather than an opaque import failure.
Addressed review feedback:
- Fixed TypeScript type issue: replaced bare
import('unpdf')cast with properUnpdfModuleinterface shim viatryLoadUnpdf()helper - Fixed
storeFnparameter: changedtype: stringtotype: ObservationTypewith proper import - Fixed test imports: migrated from
bun:testtovitest - All 4 tests pass,
tsc --noEmitclean
Leaving this open as a future ingestion candidate, but it still should not merge as-is.
The remaining blockers are still real: the optional unpdf dependency contract does not work cleanly for the documented global-install flow, maxPages needs strict positive-integer validation, and after 1.0.8 any new native Memorix capability needs CLI + MCP + docs parity rather than landing as an MCP-only surface.
A good next revision would define the dependency/install story first, add validation, and expose the PDF ingest path through the CLI as well.