diff --git a/backend/Dockerfile b/backend/Dockerfile index 651802bf..b55fae5c 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -43,7 +43,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies -COPY backend/requirements.txt . +COPY backend/requirements.txt backend/requirements-ocr.txt ./ RUN --mount=type=cache,target=/root/.cache/pip \ set -eux; \ PIP_ARGS="--no-cache-dir --retries 10 --timeout 60"; \ @@ -54,9 +54,13 @@ RUN --mount=type=cache,target=/root/.cache/pip \ PIP_ARGS="$PIP_ARGS --extra-index-url ${PIP_EXTRA_INDEX_URL}"; \ fi; \ pip install $PIP_ARGS -r requirements.txt && \ - pip uninstall -y opencv-python && \ - pip install $PIP_ARGS opencv-python-headless && \ - python -c "import networkx, openpyxl" + pip install $PIP_ARGS \ + "$(grep '^opencv-python-headless' requirements-ocr.txt)" && \ + pip install $PIP_ARGS --no-deps \ + "$(grep '^rapidocr-onnxruntime' requirements-ocr.txt)" && \ + pip install $PIP_ARGS \ + pyclipper Shapely six onnxruntime && \ + python -c "import cv2; from rapidocr_onnxruntime import RapidOCR; import networkx, openpyxl" # Copy backend code and the Text2SQL schema required at runtime COPY backend/ . diff --git a/backend/requirements-ocr.txt b/backend/requirements-ocr.txt new file mode 100644 index 00000000..0664f3b2 --- /dev/null +++ b/backend/requirements-ocr.txt @@ -0,0 +1,13 @@ +# OCR stack for edkb_system (knowledge-base document image text). +# Docker: installed by backend/Dockerfile (headless first, rapidocr --no-deps). +# Local dev (avoid downloading opencv-python twice): +# pip install -r requirements.txt +# pip install "opencv-python-headless>=4.5.1.48,<5" +# pip install rapidocr-onnxruntime==1.4.4 --no-deps +# pip install pyclipper Shapely six onnxruntime +opencv-python-headless>=4.5.1.48,<5 +rapidocr-onnxruntime==1.4.4 +pyclipper +Shapely +six +onnxruntime diff --git a/backend/requirements.txt b/backend/requirements.txt index 2cae437b..c6acd8ae 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -23,8 +23,8 @@ pywin32; sys_platform == "win32" # File Parsing & edkb_system dependencies from xinxin2 networkx==3.5 python-docx==1.2.0 -rapidocr-onnxruntime==1.4.4 -opencv-python-headless +# OCR stack (opencv + rapidocr) installed via requirements-ocr.txt in Dockerfile +# to avoid pip pulling the larger opencv-python wheel as a rapidocr dependency. pillow==11.3.0 numpy==2.3.3 pypdf==6.1.0 diff --git a/docs/knowledge_base_runtime_deploy.md b/docs/knowledge_base_runtime_deploy.md index 12f86738..44ae2c1e 100644 --- a/docs/knowledge_base_runtime_deploy.md +++ b/docs/knowledge_base_runtime_deploy.md @@ -62,6 +62,7 @@ - 若当前环境无法访问 Docker Hub,可在执行前设置 `KB_REDIS_IMAGE`,例如改为企业私有仓库中的 Redis 镜像。 - 若当前环境无法访问 Docker Hub,也可同时设置 `PYTHON_BASE_IMAGE`、`NODE_BASE_IMAGE`、`NGINX_BASE_IMAGE`,把后端/前端基础镜像切到企业私有仓库。 - 若后端 `pip install -r requirements.txt` 速度过慢或不稳定,可设置 `PIP_INDEX_URL` / `PIP_EXTRA_INDEX_URL`。 +- OCR 依赖(OpenCV/RapidOCR)在 `backend/requirements-ocr.txt`,由 `backend/Dockerfile` 分步安装,避免同时下载 `opencv-python` 与 `opencv-python-headless` 两个大 wheel。 - 若要沿用旧 `xinxin2` 文件目录,切换前需先把历史知识库文件迁入主平台卷,并保证 `KB_STORAGE_ROOT` 指向迁移后的新路径。 - 若仍要调用外部 integration API,才需要配置 `INTEGRATION_API_BASE` 与 `INTEGRATION_API_KEY`,此时 `INTEGRATION_API_MODE` 设为 `external`。 - 当前知识库主链路的 `worker_kb` 轮询数据库即可工作,`kb-redis` 以 profile 方式保留,用于后续异步队列扩展或外接 Redis 场景。