Skip to content

feat(search): optional semantic embeddings with hybrid ranking (pgvector) - #295

Draft
salmonumbrella wants to merge 2 commits into
maathimself:mainfrom
salmonumbrella:search/split-2-semantic-rebased
Draft

feat(search): optional semantic embeddings with hybrid ranking (pgvector)#295
salmonumbrella wants to merge 2 commits into
maathimself:mainfrom
salmonumbrella:search/split-2-semantic-rebased

Conversation

@salmonumbrella

Copy link
Copy Markdown
Contributor

Split 2/3 of #283, stacked on #294 — the diff shows #294's commit until it merges; review the last commit only (feat(search): optional semantic embeddings with hybrid ranking (pgvector)). I'll rebase this onto main as soon as #294 lands. Everything costly or privacy-sensitive is off by default; stock Postgres still boots clean with semantic disabled.

Summary

  • Opt-in embeddings pipeline against any OpenAI-compatible /v1/embeddings endpoint (key encrypted at rest, host-validated, masked on read). Fingerprinted generations (config change ⇒ clean rebuild), a crash-safe fill worker, per-dimension HNSW partial indexes, re-embedding of late-arriving bodies. Migrations 0038–0039 (fast-DDL).
  • Hybrid query mode — BM25∪ANN reciprocal-rank fusion behind an in-input Semantic toggle; lexical stays the default, with silent fallback while the index builds.
  • Settings UI with explicit privacy copy and live Test/Build progress, in all 7 locales.
  • Eval harness (backend/scripts/search-eval.mjs) that produced the quality numbers: on a real 18k-message mailbox, paraphrase Recall@20 goes 0% (current search) → 76% (hybrid); keyword MRR 0.43, best of all modes tested.

Deployment notes

  • compose moves postgres:16-alpinepgvector/pgvector:pg16 (same PG16 major; the data dir mounts as-is). Run REINDEX DATABASE once after the first boot: the musl → glibc collation change can misorder existing text btree indexes (the app logs a loud warning when it detects this).
  • External email-text egress happens ONLY when an admin explicitly configures an embeddings endpoint; the UI copy spells this out.

Testing

  • Backend: 954 passed / 43 skipped (pgvector integration suites, gated on a live DB), lint clean
  • Frontend: 1,438 passed / 0 failed, lint clean, production build clean

Contributor License Agreement

By submitting this pull request I confirm that:

  • I have read and agree to the Contributor License Agreement.
  • My contribution is my own original work (or I have identified any third-party material and confirmed it is compatible with the CLA).
  • I have the right to submit this contribution under the terms of the CLA.

🤖 Generated with Claude Code

salmonumbrella and others added 2 commits July 18, 2026 21:42
Results ranked by relevance instead of date-only: subject > sender > body
(setweight A-D + ts_rank_cd), prefix matching as you type, quoted phrases,
served by a GIN index over a trigger-maintained search_fts column. Backfill
runs as a resumable background drainer (fast-DDL migrations 0035-0037, no
boot-blocking rewrite); not-yet-backfilled rows fall back to the previous
query path. Body text is materialized by a provider-gated background IMAP
drainer with circuit breakers, poison-message forward progress, and
progress reporting. Filter-only queries stay date-ordered.

No infrastructure changes - runs on stock postgres:16-alpine.

Split 1/3 of maathimself#283.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tor)

Explicit opt-in embeddings pipeline against any OpenAI-compatible
/v1/embeddings endpoint (key encrypted at rest, host-validated, masked on
read). Fingerprinted generations (config change => clean rebuild), a
crash-safe fill worker, per-dimension HNSW partial indexes, re-embedding of
late-arriving bodies. Query side adds hybrid BM25+ANN reciprocal-rank
fusion behind an in-input Semantic toggle; lexical stays the default, with
silent fallback while the index builds. Settings UI with explicit privacy
copy and live Test/Build progress, in all 7 locales. Migrations 0038-0039.
Includes the search-eval harness that produced the published quality
numbers, and its explain/total diagnostics seams.

Infra: compose moves postgres:16-alpine -> pgvector/pgvector:pg16 (same
PG16 major). Run REINDEX DATABASE once after the first boot: the
musl -> glibc collation change can misorder existing text btree indexes;
the app logs a loud warning when it detects this.

Split 2/3 of maathimself#283, stacked on the weighted-FTS PR.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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