feat(docreader): speed up scanned-PDF parsing, stream image results, isolate heavy async queues

Large scanned PDFs (hundreds of pages) were slow and fragile end-to-end.
This change addresses the parse, transport, and task-scheduling layers:

docreader (parse + transport):
- Parallelize per-page scanned rendering across processes (forkserver/fork),
  with serial fallback. ~4-7x faster on large scanned PDFs; pdfium is not
  thread-safe so we fan out across processes. Configurable via
  DOCREADER_PDF_RENDER_PARALLELISM.
- Add server-streaming ReadStream RPC: emit one meta frame then one frame per
  image, so documents with many page images are no longer capped by the unary
  gRPC message-size limit (a 874-page PDF produced ~193MiB of images, far over
  the 50MB cap) and memory is bounded on both ends. Unary Read is kept for
  backward compatibility; the Go production reader switches to ReadStream.

VLM:
- Make the VLM HTTP timeout configurable (VLM_HTTP_TIMEOUT_SECONDS) and raise
  the default 90s -> 180s so dense scanned-page OCR does not time out with
  "context deadline exceeded".

Async task queues:
- Isolate high-volume, model-heavy fan-out tasks into dedicated asynq queues so
  a single large document cannot saturate the shared worker pool and block
  user-facing document parsing:
    image:multimodal  -> "multimodal"
    chunk:extract     -> "graph"
    question:generation -> "question"
- Register the new queues in the server weight map and the cancel inspector's
  scanned-queue set (so cancelling a knowledge still purges its pending tasks).
This commit is contained in:
wizardchen
2026-06-02 09:50:09 +08:00
committed by lyingbug
parent 2ba1237598
commit 7b1bb1054f
26 changed files with 1994 additions and 188 deletions
+23
View File
@@ -1,5 +1,28 @@
package types
// Asynq queue names. MUST stay in sync with the Queues weight map in
// router.NewAsynqServer — a task enqueued to a queue that the server does not
// list will never be consumed.
const (
QueueCritical = "critical"
QueueDefault = "default"
QueueLow = "low"
// QueueMultimodal isolates high-volume, slow VLM image tasks (OCR + caption)
// so a single large scanned PDF (hundreds–thousands of page images) cannot
// saturate the shared worker pool and block user-facing document parsing in
// the default queue.
QueueMultimodal = "multimodal"
// QueueGraph isolates high-volume, slow graph-extraction tasks (one per
// chunk, LLM-backed, only when Neo4j is enabled). Same rationale as
// QueueMultimodal: a large document must not flood the default queue.
QueueGraph = "graph"
// QueueQuestion isolates high-volume, slow question-generation tasks (one
// per 20-chunk batch, LLM-backed). Keeps a large document's hundreds of
// question batches from starving the lightweight tasks in the low queue
// (summary, deletes, wiki ingest).
QueueQuestion = "question"
)
const (
TypeChunkExtract = "chunk:extract"
TypeDocumentProcess = "document:process" // 文档处理任务