merlyn/server/utils
Marcello Fitton 42a41201a8
feat: Document Embedding Status Events | Refactor Document Embedding to Job Queue and Forked Process (#5254)
* implement native embedder job queue

* persist embedding progress across renders

* add development worker timeouts

* change to static method

* native reranker

* remove useless return

* lint

* simplify

* make embedding worker timeout value configurable by admin

* add event emission for missing data

* lint

* remove onProgress callback argument

* make rerank to rerankDirect

* persists progress state across app reloads

* remove chunk level progress reporting

* remove unuse dvariable

* make NATIVE_RERANKING_WORKER_TIMEOUT user configurable

* remove dead code

* scope embedding progress per-user and clear stale state on SSE reconnect

* lint

* revert vector databases and embedding engines to call their original methods

* simplify rerank

* simplify progress fetching by removing updateProgressFromApi

* remove duplicate jsdoc

* replace sessionStorage persistence with server-side history replay for embedding progress

* fix old comment

* fix: ignore premature SSE all_complete when embedding hasn't started yet

The SSE connection opens before the embedding API call fires, so the
server sees no buffered history and immediately sends all_complete.
Firefox dispatches this eagerly enough that it closes the EventSource
before real progress events arrive, causing the progress UI to clear
and fall back to the loading spinner. Chrome's EventSource timing
masks the race.

Track slugs where startEmbedding was called but no real progress event
has arrived yet via awaitingProgressRef. Ignore the first all_complete
for those slugs and keep the connection open for the real events.

* reduce duplication with progress emissions

* remove dead code

* refactor: streamline embedding progress handling

Removed unnecessary tracking of slugs for premature all_complete events in the EmbeddingProgressProvider. Updated the server-side logic to avoid sending all_complete when no embedding is in progress, allowing the connection to remain open for real events. Adjusted the embedding initiation flow to ensure the server processes the job before the SSE connection opens, improving the reliability of progress updates.

* fix stale comment

* remove unused function

* fix event emissions for document creation failure

* refactor: move Reranking Worker Idle Timeout input to LanceDBOptions component

Extracted the Reranking Worker Idle Timeout input from GeneralEmbeddingPreference and integrated it into the LanceDBOptions component. This change enhances modularity and maintains a cleaner structure for the settings interface.

* lint

* remove unused hadHistory vars

* refactor workspace directory by hoisting component and converting into functions

* moved EmbeddingProgressProvider to wrap Document Manager Modal

* refactor embed progress SSE connection to use fetchEventSource instead of native EventSource API.

* refactor message handlng into a function and reduce duplication

* refactor: utilize writeResponseChunk for event emissions in document embedding progress SSE

* refactor: explicit in-proc embedding and rerank methods that are called by workers instead of process.send checks

* Abstract EmbeddingProgressBus and Worker Queue into modules

* remove error and toast messages on embed process result

* use safeJsonParse

* add chunk-level progress events with per-document progress bar in UI

* remove unused parameter

* rename all worker timeout references to use ttl | remove ttl updating from UI

* refactor: pass embedding context through job payload instead of global state

* lint

* add graceful shutdown for workers

* apply figma styles

* refactor embedding worker to use bree

* use existing WorkerQueue class as the management layer for jobs

* lint

* revert all reranking worker changes back to master state

Removes the reranking worker queue, rerankViaWorker/rerankInProcess
renames, and NATIVE_RERANKING_WORKER_TTL config so this branch
only contains the embedding worker job queue feature.

* remove breeManaged flag — WorkerQueue always spawns via Bree

* fix prompt embedding bug

* have embedTextInput call embedChunksInProcess

* add message field to `process.send()`

* remove nullish check and error throw

* remove bespoke graceful shutdown logix

* add spawnWorker method and asbtract redudant flows into helper methods

* remove unneeded comment

* remove recomputation of TTL value

* frontend cleanup and refactor

* wip on backend refactor

* backend overhaul

* small lint

* second pass

* add logging, update endpoint

* simple refactor

* add reporting to all embedder providers

* fix styles

---------

Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
2026-04-06 17:00:15 -07:00
..
agentFlows admin only flow-plugin path validation 2026-04-05 11:57:48 -07:00
agents Merge branch 'master' of github.com:Mintplex-Labs/anything-llm 2026-03-30 21:47:13 -07:00
AiProviders feat: add optional API key support for Lemonade provider (#5281) 2026-03-30 14:44:12 -07:00
BackgroundWorkers feat: Document Embedding Status Events | Refactor Document Embedding to Job Queue and Forked Process (#5254) 2026-04-06 17:00:15 -07:00
boot Telegram bot connector (#5190) 2026-03-23 15:10:21 -07:00
chats Reapply "Remove illegal chars for Windows on files (#5364)" 2026-04-06 14:05:25 -07:00
collectorApi Filesystem Agent Skill overhaul (#5260) 2026-03-26 14:07:46 -07:00
comKey [BETA] Live document sync (#1719) 2024-06-21 13:38:50 -07:00
database Remove WelcomeMessages from app - no longer used (#5206) 2026-03-13 12:55:59 -07:00
DocumentManager Enable ability to do full-text query on documents (#758) 2024-02-21 13:15:45 -08:00
EmbeddingEngines feat: Document Embedding Status Events | Refactor Document Embedding to Job Queue and Forked Process (#5254) 2026-04-06 17:00:15 -07:00
EmbeddingRerankers/native chore: add ESLint to /server (#5126) 2026-03-05 16:32:45 -08:00
EncryptionManager Telegram bot connector (#5190) 2026-03-23 15:10:21 -07:00
files Reapply "Remove illegal chars for Windows on files (#5364)" 2026-04-06 14:05:25 -07:00
helpers feat: Document Embedding Status Events | Refactor Document Embedding to Job Queue and Forked Process (#5254) 2026-04-06 17:00:15 -07:00
http add user id to chat feedback 2026-03-13 16:51:02 -07:00
logger patch logger for full logs 2024-07-19 18:35:41 -07:00
MCP MCP tool manager (#5230) 2026-03-18 15:33:49 -07:00
middleware Telegram bot connector (#5190) 2026-03-23 15:10:21 -07:00
PasswordRecovery Merge commit from fork 2026-01-02 15:50:50 -08:00
prisma Fix Typos in Comments and Documentation (#3987) 2025-06-12 13:59:38 -07:00
PushNotifications Web push notifications (#4942) 2026-02-02 10:56:58 -08:00
telegramBot Redesign Telegram bot settings UI (#5306) 2026-03-31 13:34:59 -07:00
telemetry Prune telemetry events 2025-04-29 13:54:00 -07:00
TextSplitter Native Embedder model selection (incl: Multilingual support) (#3835) 2025-07-22 10:07:20 -07:00
TextToSpeech chore: add ESLint to /server (#5126) 2026-03-05 16:32:45 -08:00
vectorDbProviders chore: add ESLint to /server (#5126) 2026-03-05 16:32:45 -08:00
vectorStore PGvector vector database support (#3788) 2025-05-09 12:27:11 -07:00
EmbeddingWorkerManager.js feat: Document Embedding Status Events | Refactor Document Embedding to Job Queue and Forked Process (#5254) 2026-04-06 17:00:15 -07:00