Skip to content

Add title bitmap OCR in transcript component - #838

Open
allenporter wants to merge 2 commits into
mainfrom
feat/title-bitmap-ocr
Open

allenporter wants to merge 2 commits into
mainfrom
feat/title-bitmap-ocr

Conversation

@allenporter

Copy link
Copy Markdown
Owner

Implements Step 4 of ADR 0004 for #501.

Summary

  • Persistence & Migration (d0e1f2a3b4c5):
    • Adds NoteTitleTranscriptDO (f_note_title_transcript, composite PK (user_id, file_id, bitmap_md5), text_content, create_time, update_time) in supernote/server/db/models/note_processing.py.
    • Drops unused f_note_title.text_content, removes text_by_md5 carry-over from NoteMetadataModule._sync_titles(), and removes text from NoteTitleVO and types.d.ts NoteTitle.
  • Single-Line Title OCR Prompt:
    • Adds PromptId.TITLE_TRANSCRIPTION, supernote/server/resources/prompts/title/default/prompt.md, and format_title_ocr_prompt() in supernote/server/ai/prompts.py.
  • Title Crop Transcription in OcrModule (supernote/server/components/transcript/processor.py):
    • Transcribes uncached <TITLEBITMAP> crops for the current page using NoteMetadataService.get_title_png_key() and blob_storage.get_bytes(), normalizing output to a single line and upserting safely under concurrent page execution.
    • Supports title-only backfill on already-transcribed pages without re-running full-page OCR or requiring cached page PNGs.
    • Records "" for unrenderable crops so run_if_needed() settles, prunes stale title transcripts when headings change, and implements cleanup_file() scoped by (user_id, file_id).
  • Transcript Read API:
    • Adds TranscriptService.get_title_transcripts() (joined with NoteTitleDO so stale titles are never served, omitting empty strings, and preserving read compatibility with unmigrated legacy DBs).
    • Exposes titles: dict[str, str] (keyed by bitmapMd5) on WebTranscriptResponseVO / POST /api/extended/transcript.

Verification

  • ./script/lint (ruff, ty, tsc, biome, codespell, yamllint) passes.
  • Full pytest suite (uv run --no-sync pytest -q -n 8) passes, including new tests for title crop OCR, title-only backfill with evicted page PNGs, concurrent duplicate bitmap_md5 upserts, unrenderable crops, cleanup_file, format_title_ocr_prompt, and d0e1f2a3b4c5 upgrade/downgrade.

@github-actions github-actions Bot added documentation Improvements or additions to documentation and guides enhancement User-facing feature or API capability web-ui Frontend SPA and Web UI components ai OCR, summarization, embeddings, prompts, vocabulary, and AI backends labels Nov 26, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.89051% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.55%. Comparing base (dc616e3) to head (0bfb69e).

Files with missing lines Patch % Lines
...upernote/server/components/transcript/processor.py 92.50% 6 Missing ⚠️
supernote/server/components/transcript/service.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #838    +/-   ##
========================================
  Coverage   95.54%   95.55%            
========================================
  Files         256      257     +1     
  Lines       27907    28021   +114     
========================================
+ Hits        26665    26776   +111     
- Misses       1242     1245     +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai OCR, summarization, embeddings, prompts, vocabulary, and AI backends documentation Improvements or additions to documentation and guides enhancement User-facing feature or API capability web-ui Frontend SPA and Web UI components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants