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
+24 -9
View File
@@ -55,7 +55,7 @@ show_help() {
echo "用法: $0 [命令] [选项]"
echo ""
echo "命令:"
echo " start 启动基础设施服务(postgres, redis, docreader)"
echo " start 启动基础设施服务(postgres, redis, docreader, langfuse)"
echo " stop 停止所有服务"
echo " restart 重启所有服务"
echo " logs 查看服务日志"
@@ -65,12 +65,14 @@ show_help() {
echo " help 显示此帮助信息"
echo ""
echo "可选 Profile(用于 start 命令):"
echo " --minio 启动 MinIO 对象存储"
echo " --qdrant 启动 Qdrant 向量数据库"
echo " --neo4j 启动 Neo4j 图数据库"
echo " --jaeger 启动 Jaeger 链路追踪"
echo " --dex 启动 Dex(OIDC 身份认证)"
echo " --full 启动所有可选服务"
echo " --minio 启动 MinIO 对象存储"
echo " --qdrant 启动 Qdrant 向量数据库"
echo " --neo4j 启动 Neo4j 图数据库"
echo " --jaeger 启动 Jaeger 链路追踪"
echo " --dex 启动 Dex(OIDC 身份认证)"
echo " --langfuse 启动 Langfuse(默认已开启)"
echo " --no-langfuse 不启动 Langfuse"
echo " --full 启动所有可选服务"
echo ""
echo "示例:"
echo " $0 start # 启动基础服务"
@@ -121,8 +123,10 @@ start_services() {
# 解析 profile 参数
shift # 移除 "start" 命令本身
PROFILES="--profile full"
ENABLED_SERVICES=""
# 默认启动基础设施(postgres / redis / docreader)+ langfuse,
# 其余可选服务通过 --minio / --qdrant / --neo4j / --jaeger / --dex / --full 按需开启。
PROFILES="--profile langfuse"
ENABLED_SERVICES="langfuse"
while [ $# -gt 0 ]; do
case "$1" in
@@ -146,6 +150,14 @@ start_services() {
PROFILES="$PROFILES --profile dex"
ENABLED_SERVICES="$ENABLED_SERVICES dex"
;;
--langfuse)
PROFILES="$PROFILES --profile langfuse"
ENABLED_SERVICES="$ENABLED_SERVICES langfuse"
;;
--no-langfuse)
PROFILES="${PROFILES//--profile langfuse/}"
ENABLED_SERVICES="${ENABLED_SERVICES//langfuse/}"
;;
--full)
PROFILES="--profile full"
ENABLED_SERVICES="minio qdrant neo4j jaeger dex"
@@ -185,6 +197,9 @@ start_services() {
if [[ "$ENABLED_SERVICES" == *"dex"* ]]; then
echo " - Dex: localhost:5556"
fi
if [[ "$ENABLED_SERVICES" == *"langfuse"* ]]; then
echo " - Langfuse: http://localhost:${LANGFUSE_WEB_PORT:-3000}"
fi
echo ""
log_info "接下来的步骤:"