Skip to content

Add explicit title override to document ingest#54

Merged
hallelx2 merged 1 commit into
mainfrom
feat/ingest-title-override
Jul 4, 2026
Merged

Add explicit title override to document ingest#54
hallelx2 merged 1 commit into
mainfrom
feat/ingest-title-override

Conversation

@hallelx2

@hallelx2 hallelx2 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

@

What

Accept an optional title on ingest — a multipart form field or a JSON body field. When present it seeds the document row and is threaded through the ingest Payload so persistTree keeps it: the parsed title never overwrites an explicit one. Empty preserves existing auto-discovery.

Why

Some PDFs have unreliable title text the font-heuristic latches onto:

  • rotated arXiv margin stamps extracted in reverse — 3202 guA (=“Aug 2023”), ]LC.sc[ (=“[cs.CL]”)
  • repeated ORCID iD markers — iD iD iD iD
  • letter-spaced cover pages

The existing isLikelyMojibakeTitle guard only catches doubled-glyph watermarks, so these slip through and become the display title. An explicit override lets callers — and curated corpora like the Playground demo set — show a clean name regardless.

Tests

  • TestPersistTree_TitleOverrideIsSticky: override is never clobbered by the parsed title; a blank override still lets a usable parsed title through.
  • go build ./... + go test ./... green.
    @

Summary by CodeRabbit

  • New Features

    • Document uploads can now include an optional title, entered during form or JSON submission.
    • Supplied titles are preserved through ingest and used when saving the document.
  • Bug Fixes

    • Prevented parser-generated titles from overwriting a user-provided title.
    • Improved title handling for documents with blank or trimmed input.

@
Add explicit title override to document ingest

Accept an optional "title" on ingest (multipart form field or JSON body).
When set it seeds the document row AND is threaded through the ingest
Payload so persistTree keeps it — the parsed title never clobbers it.

Motivation: some PDFs have unreliable title text the parser latches onto
— rotated arXiv margin stamps extracted in reverse ("3202 guA" for
"Aug 2023"), repeated ORCID iD markers ("iD iD iD iD"), letter-spaced
cover pages. The existing mojibake guard only catches doubled-glyph
watermarks. An explicit title lets callers (and curated corpora like the
playground demo set) show a clean display name regardless. Empty = keep
auto-discovery.
@

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @hallelx2, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be2062af-e78a-4a81-ad0e-35bfe2e21a61

📥 Commits

Reviewing files that changed from the base of the PR and between db327d3 and c083031.

📒 Files selected for processing (3)
  • internal/handler/documents.go
  • pkg/ingest/ingest.go
  • pkg/ingest/persist_content_ref_test.go

📝 Walkthrough

Walkthrough

Adds support for an optional, caller-supplied document title override in the ingest handler and pipeline. The handler captures a title from multipart form or JSON payload, propagates it through the ingest Payload, and persistTree now honors this sticky override instead of always writing the parsed title.

Changes

Sticky document title override

Layer / File(s) Summary
Handler title override capture and usage
internal/handler/documents.go
Captures an optional title field from multipart form or JSON payload, trims it into titleOverride, uses it to compute the document title (falling back to filename), and sets the enqueued job payload's Title from it.
Pipeline Payload and persistTree sticky logic
pkg/ingest/ingest.go
Adds Title field to Payload; Run and runMinimal pass it to persistTree, which now accepts a titleOverride parameter and skips overwriting the title when the override is non-empty, otherwise applying the parsed title if it passes mojibake checks.
Sticky title tests
pkg/ingest/persist_content_ref_test.go
Adds TestPersistTree_TitleOverrideIsSticky and updates the existing content-ref test to pass an explicit blank title override argument.

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant HandleIngestDocument
  participant Pipeline
  participant persistTree

  Client->>HandleIngestDocument: submit document with optional title
  HandleIngestDocument->>HandleIngestDocument: trim title into titleOverride
  HandleIngestDocument->>Pipeline: enqueue Payload{Title: titleOverride}
  Pipeline->>persistTree: persistTree(titleOverride)
  alt titleOverride non-empty
    persistTree->>persistTree: skip SetDocumentTitle
  else titleOverride empty
    persistTree->>persistTree: set title if parsed title passes mojibake check
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an explicit title override to document ingest.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ingest-title-override

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hallelx2 hallelx2 merged commit 7fb8432 into main Jul 4, 2026
8 checks passed
@hallelx2 hallelx2 deleted the feat/ingest-title-override branch July 4, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant