Repository navigation
Search PDF passages locally with optional embedding models - #115
FlavioRenzi wants to merge 1 commit into
Conversation
Add shared extraction, exact/semantic/hybrid retrieval, verified optional model downloads and independent indexes in a lazy Electron utility process. Provide reader sidebar controls, model settings, indexing and passage navigation. Include retrieval tests, stable smoke setup, benchmark tooling, architecture and usage documentation, packaging and third-party notices. Keep local launcher changes outside this commit.
Codex Review Summary: 🔄 RunningThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f57327a12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| function pageText(items) { | ||
| // Keep item boundaries and line breaks: never merge register names in adjacent cells. | ||
| return items.filter(item => typeof item.str === 'string').map(item => item.str + (item.hasEOL ? '\n' : ' ')).join('').trim(); |
There was a problem hiding this comment.
Preserve words split across PDF text items
When pdf.js splits a word or identifier across text items, such as a font change between I2C_ and CR2, the unconditional separator rewrites it as I2C_ CR2. Indexing that text makes an Exact search for I2C_CR2 return no matches, although basic find still finds it. The existing renderer helper in src/lib/search/snippet.ts preserves this continuity. Preserve contiguous text runs and insert separators only for actual whitespace, geometric gaps, or line breaks.
Useful? React with 👍 / 👎.
| debounce.current = window.setTimeout(() => void search(), 350); | ||
| return () => window.clearTimeout(debounce.current); | ||
| // Search captures the current query/options; status polling must not repeat inference. | ||
| }, [query, mode, model, limit, phrase, canSearch]); |
There was a problem hiding this comment.
Refresh active results when indexing completes
If a query is entered while a long document is being indexed, the first available page or embedding makes canSearch true and runs the query against partial coverage. Subsequent changes to status.pages, status.embedded, and status.state leave these dependencies unchanged, so completion never refreshes the results. A query matching only a later page can therefore keep showing no matches after the incomplete-index warning disappears. Re-run the active query on indexing completion or an index revision change without repeating inference on unchanged status polls.
Useful? React with 👍 / 👎.
| invalidate(); | ||
| setOptionsOpen(false); | ||
| setQuery(queryRequest.text); |
There was a problem hiding this comment.
Preserve or rerun unchanged selection queries
With the sidebar already open, selecting PDF text identical to the current query and invoking the semantic-search shortcut again creates a new queryRequest. This effect clears the results through invalidate(), but setQuery() leaves the query unchanged, so none of the automatic-search dependencies change and the result list stays blank until the user edits or manually submits the query. Preserve the existing results for an unchanged query or explicitly retrigger search for each new selection request.
Useful? React with 👍 / 👎.
Problem
Finding relevant passages in a long PDF needs more than literal text matching. Readers should be able to search locally while ordinary reading, annotations and find remain usable without downloading a model or starting inference.
Change
Add shared PDF extraction and FTS5 indexing, optional independent vector indexes per model, and exact/semantic/hybrid passage retrieval in a lazy Electron utility process. Model installation is explicit, pinned and checksum-verified; indexing supports checkpoints, pause, cancellation and restart.
Add a search sidebar with a fixed query field, selected-text shortcuts, model settings, indexing controls and passage navigation. Preserve the existing PDF.js basic find path. Include retrieval tests, stable smoke setup, native dependency packaging, license notices, documentation and synthetic benchmark tooling.
Search covers the open document and its PDF text layer. Password-protected documents are excluded. Retrieved passages are not sent to Ask AI by this change.
Issue or approval
Related to #101 and the maintainer's approval. The approved scope also includes sending excerpts to Ask AI and linking generated answers to their sources. This PR provides local passage search and does not close the issue. The dedicated search UI needs scope confirmation; SP2502 has already confirmed taking on #101. This PR is available for scope coordination with that contributor and the maintainer.
How I checked it
On Linux, with Node 24.20.0 and Electron 45.2.3, the complete search stack passed:
npx tsc --noEmitandnpm run build.npm test: 259 tests.npm run test:retrieval: 14 tests.npm run smoke, including OCR, printing and retrieval.The combined commit has exactly the same tree as the tested search stack after excluding the separate launcher files. Squashing did not change application sources, tests or dependencies; the complete smoke was not rerun after this metadata-only change.
An additional isolated backend run passed clean dependency installation, TypeScript, build, unit/retrieval tests, reader security, other CI regressions and an offline Electron IPC probe. Its general smoke stopped on an OCR screenshot timeout; that run tested the earlier backend-only split, not this combined feature.
npm audit --audit-level=highpassed there with six moderate vulnerabilities reported.Windows/macOS execution, packaged installers and a fresh real-model inference run were not checked during this preparation. The synthetic benchmark measurements in the documentation are earlier local results, not a real-manual relevance guarantee.
Before/after screenshots were captured in hidden Linux runs using the same sample PDF and query and are attached below:
upstream main, floating basic find.
basic find sidebar, same PDF and query.
local Exact passage results, no model download.
optional model settings.
Screenshots are excluded from the Git history as required by the repository.
AI used