feat(ingestion): take the record from the metadata of the file #86

Merged
crapougnax merged 3 commits from feat/78-file-metadata into develop 2026-11-30 08:55:39 +00:00
Owner

Closes #78

Was based on #85 (merged): now targets develop.

Change

  • src/instance/file-metadata.ts — readFileMetadata(content, contentType):
    • Markdown: frontmatter (title, description/summary, author(s)/creator(s), publisher, date/year, lang/language, isbn, doi), else the first # heading;
    • HTML: <title>, citation_* and description/author/og:* meta tags, <html lang>;
    • PDF: document information (Title, Author split on ;, Subject, CreationDate), placeholder titles left out ("Microsoft Word - …", "untitled");
    • DOCX docProps/core.xml, ODT meta.xml, EPUB OPF (through META-INF/container.xml, ISBN/DOI from dc:identifier), read with fflate (already a dependency), packages above 50 MB skipped;
    • any failure → no metadata.
  • Ingestion: record = metadata of the file, overridden by what the model tells; title falls back on the file name last. With a model, the metadata are given in the prompt as hints "to check against the document".
  • Docs (EN, FR), section 10.

Bug fixed on the way: small PDFs read as another file

pdf.js (inside pdf-parse) copies its input with new value.constructor(value). For a Buffer, that copy lands in Node's shared pool of small buffers, at an offset pdf.js ignores: it then parses whatever else is in the pool ("bad XRef entry", "Command token too long"). Small originals (under 4 KB) could fail to extract depending on what was allocated before. pdfBytes() hands it a plain Uint8Array; used for text extraction and metadata. Regression test with a PDF at a non-zero pool offset (fails without the fix).

Checks

yarn test 272/272: one test per format, fallbacks, the pooled PDF, hints in the prompt, ingestion without a model (frontmatter → title, description, language, creators, publisher, year) and with a failing model (first heading).

🤖 Generated with Claude Code

Closes #78 Was based on #85 (merged): now targets `develop`. ## Change - `src/instance/file-metadata.ts` — `readFileMetadata(content, contentType)`: - Markdown: frontmatter (`title`, `description`/`summary`, `author(s)`/`creator(s)`, `publisher`, `date`/`year`, `lang`/`language`, `isbn`, `doi`), else the first `#` heading; - HTML: `<title>`, `citation_*` and `description`/`author`/`og:*` meta tags, `<html lang>`; - PDF: document information (Title, Author split on `;`, Subject, CreationDate), placeholder titles left out ("Microsoft Word - …", "untitled"); - DOCX `docProps/core.xml`, ODT `meta.xml`, EPUB OPF (through `META-INF/container.xml`, ISBN/DOI from `dc:identifier`), read with `fflate` (already a dependency), packages above 50 MB skipped; - any failure → no metadata. - Ingestion: record = metadata of the file, overridden by what the model tells; title falls back on the file name last. With a model, the metadata are given in the prompt as hints "to check against the document". - Docs (EN, FR), section 10. ## Bug fixed on the way: small PDFs read as another file pdf.js (inside `pdf-parse`) copies its input with `new value.constructor(value)`. For a `Buffer`, that copy lands in Node's shared pool of small buffers, at an offset pdf.js ignores: it then parses whatever else is in the pool ("bad XRef entry", "Command token too long"). Small originals (under 4 KB) could fail to extract depending on what was allocated before. `pdfBytes()` hands it a plain `Uint8Array`; used for text extraction and metadata. Regression test with a PDF at a non-zero pool offset (fails without the fix). ## Checks `yarn test` 272/272: one test per format, fallbacks, the pooled PDF, hints in the prompt, ingestion without a model (frontmatter → title, description, language, creators, publisher, year) and with a failing model (first heading). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Ingestion reads what a file states about itself: the frontmatter or first
heading of Markdown, the head of HTML, the properties of a PDF, the metadata
of DOCX, ODT and EPUB packages. Without a model, or when it fails, the
record takes them, the file name being the last resort for the title; with a
model, they are given to it as hints to check, and what it tells wins.

Also fixes the reading of small PDFs: the parser copies its input with the
constructor of the input, so a Buffer copy landed in the shared pool of small
buffers at an offset it ignores, and it read another file. It now receives a
plain Uint8Array (text extraction and metadata).

Closes #78

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ingestion now reads the properties of a PDF: the fixtures that were only a
PDF signature made pdf.js warn (Indexing all PDF objects). One shared
fixture, a one-page PDF with an exact cross-reference table.

Refs #78

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
crapougnax changed target branch from fix/79-summary-bound to develop 2026-11-30 08:53:09 +00:00
Merge branch 'develop' into feat/78-file-metadata
All checks were successful
Build and Publish OCI Image / Build & Push ARM64 OCI Image (pull_request) Successful in 1m5s
dda3376208
crapougnax merged commit 7d261d6790 into develop 2026-11-30 08:55:39 +00:00
crapougnax deleted branch feat/78-file-metadata 2026-11-30 08:55:39 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
modaka/studio!86
No description provided.