Skip to content

Search PDF passages locally with optional embedding models - #115

Open
FlavioRenzi wants to merge 1 commit into
Forward-Future:mainfrom
FlavioRenzi:feature/local-search
Open

FlavioRenzi wants to merge 1 commit into
Forward-Future:mainfrom
FlavioRenzi:feature/local-search

Conversation

@FlavioRenzi

@FlavioRenzi FlavioRenzi commented Nov 28, 2026 •

Copy link
Copy Markdown

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 --noEmit and npm run build.
  • npm test: 259 tests.
  • npm run test:retrieval: 14 tests.
  • The full hidden 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=high passed 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:

  • before-find

upstream main, floating basic find.

  • after-find

basic find sidebar, same PDF and query.

  • after-local-passage-search

local Exact passage results, no model download.

  • after-model-settings

optional model settings.

Screenshots are excluded from the Git history as required by the repository.

AI used

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.
@FlavioRenzi
FlavioRenzi marked this pull request as ready for review November 28, 2026 23:00
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: 🔄 Running

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-11-28T23:00:11.793862Z 3f57327 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread src/AdvancedSearch.tsx
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]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread src/AdvancedSearch.tsx
Comment on lines +70 to +72
invalidate();
setOptionsOpen(false);
setQuery(queryRequest.text);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant