Skalierungs-Add-ons: dedizierter Worker + optionaler HNSW-ANN-Index - #17
Merged
Merged
Conversation
Splits pg-boss setup into startClient() (connect + queues + schedules, run everywhere) and registerWorkers() (the job handlers). The web tier registers workers in-process by default; set WORKERS_IN_PROCESS=false to have it only enqueue and run one or more standalone workers instead (src/worker.ts, `npm run worker`) so long extraction/embedding/generation jobs don't compete with request handling. pg-boss distributes jobs across all connected workers. Adds tsx devDependency and a commented worker service in docker-compose. Default behaviour unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191JikNRN8Q2HBtf6fpLXmH
Adds a fast approximate-nearest-neighbour vector index for large corpora, opt-in and off by default (the dimensionless sequential scan stays the default, unchanged). - src/lib/ai/ann.ts: builds a typed shadow column embedding_hnsw vector(N) + HNSW index for the active embedding model, dimension inferred from stored data; rebuild handles model/dimension changes cleanly. State tracked in a new non-secret `ai.ann` setting. - Runs as a background job (reindex-vectors queue) triggered by an admin action (startVectorReindex); admin AI page shows status + a build button (AnnIndexCard), i18n de/en. - hybridSearch uses the ANN column when ready for the active model, else the scan; new material/summary chunks keep the ANN column current via populateAnn. All raw SQL is additive and guarded — failure marks the index failed and search falls back to the scan. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191JikNRN8Q2HBtf6fpLXmH
…e-data-processing-oueat5
This was referenced Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Überblick
Zwei bewusst zurückgestellte Skalierungs-Bausteine aus dem GB-Modul-Vorhaben, jetzt als eigenständige, additive und opt-in Änderungen. Der Default-Pfad bleibt unverändert — ohne neue Env-Variablen/Admin-Aktionen verhält sich die App exakt wie bisher.
Baut auf dem bereits gemergten PR #14 auf (Phasen 0–3-Kern) und ist auf den aktuellen
main-Stand gemerged (enthält #15/#16).Enthaltene Änderungen
A — Dedizierter Worker-Prozess (
feat(jobs))Lange Jobs (Embedding, Zusammenfassung, Generierung) können optional außerhalb des Web-Tiers laufen, damit der Next-Server reaktiv bleibt.
src/lib/jobs/index.ts:start()aufgeteilt instartClient()(immer:boss.start+createQueue+schedule, damitsend()funktioniert) undregisterWorkers(boss)(dieboss.work(...)).WORKERS_IN_PROCESS(Defaulttrue). Beifalseregistriert der Next-Server keine Worker mehr, sondern reiht nur ein.src/worker.ts(Client +registerWorkers+ Alive-Loop + SIGTERM-Handling), npm-Scriptworker.src/instrumentation.tsrespektiert das Flag.docker-compose.yml: dokumentierter optionaler zweiter Service. pg-boss verteilt Jobs automatisch über konkurrierende Worker — kein Doppel-Processing.B — Optionaler pgvector HNSW-ANN-Index (
feat(retrieval))Schnelle Vektorsuche statt sequenziellem Cosine-Scan bei GB-Skala. Benötigt eine fixierte Dimension, deshalb eine typisierte Schattenspalte neben der bewusst dimensionslosen Basisspalte.
src/lib/ai/ann.ts(neu):annDimensionFor,populateAnn,reindexVectors— baut per Admin-Aktion im Hintergrund eineembedding_hnsw vector(N)-Spalte + HNSW-Index (vector_cosine_ops) für das aktive Embedding-Modell, Backfill ausembedding(Source of Truth). Dimension wird aus den Daten abgeleitet, nicht geraten.src/lib/settings.ts: neuer Setting-Keyai.ann(Statusidle/building/ready/failed, Modell, Dimension, Fehler).src/app/[locale]/(app)/admin/actions.ts:startVectorReindex()+getAnnStatus().src/components/admin/ann-index-card.tsx+admin/ai/page.tsx: Admin-UI mit Status und Rebuild-Button (pollt während des Builds).src/lib/ai/rag.ts:hybridSearchnutzt den HNSW-Index nur, wennannDimensionForeine Dimension liefert — sonst weiter der dimensionslose Scan (Default).populateAnnfüllt die Schattenspalte nach frischem Embedding.src/lib/jobs/index.ts:reindex-vectors-Queue/Worker.Guards: Alles ist best-effort und additiv. Ein Fehler beim ANN-Aufbau/-Befüllen bricht weder Ingestion noch Suche ab; ohne aufgebauten Index bleibt der bisherige Scan aktiv. Modell-/Dimensionswechsel wird durch sauberen Rebuild abgefangen.
Verifikation
npm run typecheck— 0 Fehlernpm run lint— saubernpm run test— 81 bestanden (3 skipped)npm run build— erfolgreichHinweise zum produktiven Test
npm run worker(bzw. Compose-Service) starten undWORKERS_IN_PROCESS=falseim Web-Tier setzen → Verarbeitung läuft im Worker, Web-Tier bleibt reaktiv.EXPLAINzeigt danach HNSW-Nutzung, Suchlatenz vor/nach vergleichbar.Noch offen (Folge-PRs)
S3-Storage-Treiber (C), Batch-API-Adapter (D), tus-Resumable-Uploads (E) — jeweils als eigener additiver PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_0191JikNRN8Q2HBtf6fpLXmH
Generated by Claude Code