Repository navigation
Search inside documents, photos, and audio - #312
Conversation
CarlosLugones
left a comment
There was a problem hiding this comment.
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
_checkpointcallschanged()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.
|
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 |
|
@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 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 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. |
|
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 |
21fc527 to
0391f35
Compare
|
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. |
|
Thanks a lot, @jrgf! This looks great. I pushed two small commits on top of yours:
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! |
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
developchanges.telescopeopened page 2 ofField guide.pdf, found the text inStation sign.png, and startedObservatory meeting.mp3at 3.30 seconds.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.