Skip to content

Search inside documents, photos, and audio - #312

Merged
CarlosLugones merged 8 commits into
TheBrainBro:developfrom
jrgf:feature/311-file-content-search
Dec 5, 2026
Merged

CarlosLugones merged 8 commits into
TheBrainBro:developfrom
jrgf:feature/311-file-content-search

Conversation

@jrgf

@jrgf jrgf commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What changes

Search now finds words inside PDFs, plain-text files, photos, and audio recordings. Each result shows the matching passage. Selecting it opens the relevant PDF page, displays the photo, or starts audio playback at the matching timestamp. When a phrase occurs more than once in a recording, each occurrence has its own timestamp.

The self-hosted worker indexes new uploads and processes existing files in the background, including archived items and photos in albums. It uses OCR for scanned text and local Whisper transcription for audio. Indexing covers the first 200 pages of each PDF and the first 60 minutes of each recording.

Ref #311

Verification

The following checks ran before the feature branch picked up the latest develop changes.

  • Relevant automated tests passed across the backend and frontend suites.
  • Lint, type checks, migration checks, and the production frontend build passed.
  • Verified end to end that searching for telescope opened page 2 of Field guide.pdf, found the text in Station sign.png, and started Observatory meeting.mp3 at 3.30 seconds.
  • I have signed the Contributor License Agreement.

Maintainer changes

  • perf(backend): indexing works in 2-minute slices instead of 10 seconds, since it now has its own worker.
  • fix(infra): the two extractor commands are marked as reviewed for Semgrep.

CI passed on the merged state (3ffa43d), including CodeQL and Semgrep. Follow-up: #345.

@CarlosLugones CarlosLugones changed the title feat(backend): search inside documents, photos, and audio (#311) Search inside documents, photos, and audio Nov 24, 2026

@CarlosLugones CarlosLugones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for this PR, @jrgf! Searching inside PDFs, photos and recordings is a big step for BrainBro, and it's clear you put a lot of care into it. The lease and checkpoint logic, how it handles crashed workers and replaced files, and the test coverage for those edge cases are all really solid. It's much appreciated.

Before we merge, a few things I'd like to sort out together:

Where the OCR and transcription tools live

Right now ffmpeg, tesseract, whisper-cli and the model go into the main brainbro image, which api, worker and migrate all share. Everyone who updates would download them, even people who don't want this feature, and api would carry ffmpeg without needing it.

An idea I'd like to discuss with you: follow the same pattern as the embedder, which already runs as its own image (brainbro-embedder, see docker/embedder/) and is published from the same release matrix. A small brainbro-extractor service could take a file and return its passages. That would:

  • keep the main image as it is today,
  • make the feature optional, so search keeps working on titles and notes if the service isn't running,
  • let people cap its CPU in compose, which matters on small hardware like an Umbrel.

I know this is a bigger ask than the rest of the review, so I'm happy to talk it through first. I can also help with the compose and release workflow parts if that's useful.

Worker capacity

The worker runs with --concurrency 2 by default, and beat queues index_upload every 15 seconds. A single unit can take a while: OCR on one page can take up to 45 s, and Whisper works on 60-second chunks, all under a 17-minute limit. SLICE_SECONDS is only checked between units. On a fresh install with a backlog of PDFs and recordings, both slots could stay busy with indexing, and thumbnails, link previews and embeddings would wait behind it. Whether or not the extraction moves to its own service, could indexing run on its own queue, or be limited to one task at a time, so the rest of the worker stays responsive?

Transcription model

With tiny and -l auto, the language is detected separately for each 60-second chunk, and tiny is quite weak in Spanish. For finding keywords it may be enough. I'd just like us to make that trade-off on purpose: did you try base to see how CPU time and quality compare?

Migrations

0024 resets PDFs indexed by "the previous extractor", but that extractor was never merged into develop, so nothing would ever need that reset. Could you fold 0023 and 0024 into one migration and drop the RunPython?

Smaller things

  • _checkpoint calls changed() once per page or audio chunk, so a 200-page PDF sends 200 change events to open clients. One event when the file finishes, or a throttled one, would be gentler.
  • The viewer gets one entry per match, so the same file can show up several times in a row when you page through results with the arrows. This is minor, and fine to leave for a follow-up.

Commits

One small note on conventions: CONTRIBUTING.md asks for small, atomic commits with a scope (backend, frontend, infra, docs) and the issue number, for example:

feat(backend): extract text from PDFs, photos and audio (#311)
feat(backend): search file passages (#311)
feat(infra): add the extractor service (#311)
feat(frontend): show and open content matches in search (#311)
docs: document file content search (#311)

Right now everything is in a single feat: file content search commit of about 1,900 lines, which makes it harder to review and to bisect later. When you rework the branch, splitting it along those lines would help a lot.

Finally, since the checks in the description ran before the branch picked up the latest develop, it would be good to see CI green on the current state.

Thanks again for taking this on. Happy to talk through any of these if you see them differently.

@CarlosLugones CarlosLugones self-assigned this Nov 24, 2026
@jrgf

jrgf commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @CarlosLugones yes I think we can split up and make the extractor an optional feature. Regarding tiny vs base, base can take up to 1.5 gb of ram to run efectivelly but the results are way better for Spanish. Will also address the split in atomic commits and came back to you when everything is done. Thanks for the review

@CarlosLugones

CarlosLugones commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

@jrgf checking in on this. No rush, I know the extractor service is bigger work than the original PR.

If it helps, I'm willing to split it: I can take the brainbro-extractor service (image, compose, release workflow), and you can do the backend changes, and commit split.

About the model: 1.5 GB of RAM is a lot for small hosts like an Umbrel, we need to keep this as lightweight as possible. Let's try with tiny as the default model, and we let users switch to base through an env var or setting.

If you have work in progress locally, feel free to push it as it is, even unfinished, so I can see where we are, and help from there.

@jrgf

jrgf commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @CarlosLugones sorry I didnt have time last week to make the adjustment. Circling back on this, this weekend so we can merge this intent

@jrgf
jrgf force-pushed the feature/311-file-content-search branch from 21fc527 to 0391f35 Compare December 5, 2026 15:31
@jrgf
jrgf requested a review from CarlosLugones December 5, 2026 15:32
@jrgf

jrgf commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @CarlosLugones already made the changes requested. Putted the extractor in an optional feature with his own docker image and adjusted the backend to talk to the new service.

Comment thread docker/extractor/server.py Fixed
@CarlosLugones

Copy link
Copy Markdown
Member

Thanks a lot, @jrgf! This looks great.

I pushed two small commits on top of yours:

  • Index uploads in 2-minute slices. Now that indexing has its own worker, the 10-second slices only added pauses and resent the whole file to the extractor on every resume. Two minutes removes most of that, and a new upload still waits at most about that long behind a long file.
  • Mark the audited extractor commands for Semgrep. Your stdin change already cleared CodeQL. Semgrep still flagged the Popen and ffmpeg calls, so I marked both as reviewed, with the reason.

As a follow-up, I opened #345, so people can turn file content search on or off from the server settings, without the extractor and indexer using RAM while it's off.

Thanks again for all the work on this!

@CarlosLugones
CarlosLugones merged commit 114174c into TheBrainBro:develop Dec 5, 2026
12 checks passed
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.

3 participants