RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix(deps): use onnxruntime-v1.29.0-patch2 to restore Clip@13 in minimal ORT (#21051)
xugangqiang9cca46ac1c11
diff --git a/build.sh b/build.shindex 160e5d58b7..3d4165b502 100755--- a/build.sh+++ b/build.sh@@ -414,7 +414,9 @@ check_onnxruntime_deps() {return 1fi- # Pinned sha256 of the published onnxruntime-v${ort_version} archive.+ # Pinned sha256 of the published onnxruntime archive (currently the+ # onnxruntime-v1.29.0-patch2 re-issue, which re-adds Clip@13 to the minimal+ # operator set — see tools/scripts/download_dev_deps.py ORT_RELEASE_TAG).## Upstream does not re-issue this archive, so we pin the digest here and# verify the LOCAL copy against it — no network access at build time. This@@ -436,13 +438,13 @@ check_onnxruntime_deps() {local expected=""case "$asset" inonnxruntime-v*-linux-x86_64.zip)- expected="439308c93822d26cf04341cab3e77c595bbe88a12b54043210d14a0ca5574bd1" ;;+ expected="1d41cc9c2a174200e90fd622e8b0f95e6531426bc9c23cfb5a4b92001c274da1" ;;onnxruntime-v*-linux-aarch64.zip)- expected="59a30fc0754d2b3dafb2761f208610e9be962f6370a0e1223fbca39440fa02a0" ;;+ expected="712b65d37d7cf4bf1d41aff0763a084020c0e36a09073170bbaf61c018246a83" ;;onnxruntime-v*-osx-arm64.zip)- expected="e80f81e61750f7cfde8bada1f2175c5218d9d910a5ec61bc70dba4a1f7c950eb" ;;+ expected="f0bebbb13901196757820164fe4ae936149e42021ff40c6450822bd6cd6e958a" ;;onnxruntime-v*-osx-universal.zip)- expected="29e9ceeaa84eba4734bbc8b7a8473487e1deb8010a2b6bc1b1cd695a4d87e7f3" ;;+ expected="8c1bfab88e17de325376e7e5c2cbe163e5df48af362083912fdbac042f9c80da" ;;esacif [ -z "$expected" ]; thenecho " (no pinned digest for ${asset}; skipping sha256 check)"diff --git a/tools/scripts/convert_deepdoc_model.py b/tools/scripts/convert_deepdoc_model.pynew file mode 100755index 0000000000..b78395c974--- /dev/null+++ b/tools/scripts/convert_deepdoc_model.py@@ -0,0 +1,158 @@+#!/usr/bin/env python3+"""Convert a DeepDoc ONNX model into the .ort FlatBuffer the Go DeepDoc backend loads.++WHY THIS EXISTS+---------------+The in-process Go DeepDoc backend links the *reduced-operator* ONNX Runtime+static library (the ~48MB libonnxruntime.a under+~/ragflow-native-libs/onnxruntime/static_lib/...). That library only implements+the modern ONNX op versions. For example, Split takes `split` as an *input+tensor* from opset 13 on — which is exactly how OSS tsr.onnx (opset 17) already+uses it, so OSS models load fine.++Some models were exported at an older opset. EE's tsr.onnx is opset 11, where+Split's `split` is an *attribute*; loading it on the reduced library fails with+"Could not find an implementation for Split(11)". This is NOT a Go bug and NOT a+broken library — the model was simply exported with an op style the library+doesn't register.++This script rewrites the model to a target opset (default 17 — the version the+reduced library supports, matching OSS) via onnx.version_converter, then+serializes it to .ort with the ORT 1.29.0 tool. After that the model runs on the+EXISTING reduced library with no rebuild.++ORT VERSION MATTERS+-------------------+The .ort FlatBuffer is version-sensitive. You MUST run this with the same+onnxruntime the Go binary links (currently 1.29.0). The script refuses to+continue on a different version.++USAGE+-----+ # EE TSR (opset 11 -> 17): writes tsr.ort next to tsr.onnx+ python convert_deepdoc_model.py --input ee_deepdoc_models/tsr/tsr.onnx++ # explicit output dir / opset+ python convert_deepdoc_model.py --input model.onnx --out-dir ./models --opset 17++The produced file is <stem>.ort (model.onnx -> model.ort), ready to drop into+DEEPDOC_MODEL_DIR. The intermediate upgraded .onnx is removed unless+--keep-onnx is given.+"""++import argparse+import os+import shutil+import subprocess+import sys+import tempfile++import onnx+from onnx import version_converter++# The ORT version the Go binary links. .ort files are not forward/backward+# compatible across ORT majors, so this MUST match.+REQUIRED_ORT_VERSION = "1.29.0"++# Opset the reduced ONNX Runtime static library actually supports for the ops+# DeepDoc models use (Split, Slice, Gather, Softmax, ...). OSS tsr.onnx already+# ships at this opset; EE tsr.onnx must be upgraded to it.+DEFAULT_TARGET_OPSET = 17+++def find_ort_version():+ try:+ import onnxruntime as ort++ return ort.__version__+ except ImportError: # pragma: no cover - defensive+ return None+++def model_opset(model: onnx.ModelProto) -> int:+ """Max imported opset for the default (ai.onnx) domain."""+ best = 0+ for imp in model.opset_import:+ if imp.domain in ("", "ai.onnx"):+ best = max(best, imp.version)+ return best+++def main() -> int:+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)+ ap.add_argument("--input", required=True, help="source .onnx model")+ ap.add_argument("--out-dir", default=None, help="output directory (default: alongside --input)")+ ap.add_argument("--opset", type=int, default=DEFAULT_TARGET_OPSET, help=f"target opset (default {DEFAULT_TARGET_OPSET})")+ ap.add_argument("--keep-onnx", action="store_true", help="keep the intermediate upgraded .onnx")+ args = ap.parse_args()++ if not os.path.isfile(args.input):+ print(f"ERROR: input not found: {args.input}", file=sys.stderr)+ return 2++ ort_ver = find_ort_version()+ if ort_ver is None:+ print("ERROR: onnxruntime is not importable in this Python environment.", file=sys.stderr)+ return 2+ if ort_ver != REQUIRED_ORT_VERSION:+ print(f"ERROR: onnxruntime {ort_ver} found, but {REQUIRED_ORT_VERSION} is required (the Go backend links ORT {REQUIRED_ORT_VERSION}; .ort files are version-specific).", file=sys.stderr)+ return 2++ stem = os.path.splitext(os.path.basename(args.input))[0]+ out_dir = args.out_dir or os.path.dirname(os.path.abspath(args.input))+ os.makedirs(out_dir, exist_ok=True)+ final_ort = os.path.join(out_dir, f"{stem}.ort")++ print(f"[1/4] loading {args.input}")+ model = onnx.load(args.input)+ cur = model_opset(model)+ print(f" current ai.onnx opset = {cur}, target = {args.opset}")++ if cur < args.opset:+ print(f"[2/4] upgrading opset {cur} -> {args.opset} via version_converter")+ model = version_converter.convert_version(model, args.opset)+ new_op = model_opset(model)+ print(f" upgraded ai.onnx opset = {new_op}")+ else:+ print(f"[2/4] opset {cur} already >= {args.opset}; no upgrade needed")++ work = tempfile.mkdtemp(prefix="ortconv_")+ try:+ up_onnx = os.path.join(work, f"{stem}.onnx")+ print(f"[3/4] saving upgraded onnx -> {up_onnx}")+ onnx.save(model, up_onnx)++ print(f" converting to .ort (ORT {ort_ver})")+ subprocess.run(+ [sys.executable, "-m", "onnxruntime.tools.convert_onnx_models_to_ort", up_onnx, "--output_dir", work],+ check=True,+ )+ src_ort = os.path.join(work, f"{stem}.ort")+ if not os.path.isfile(src_ort):+ # converter may name it differently; pick the single .ort produced+ orts = [f for f in os.listdir(work) if f.endswith(".ort")]+ if len(orts) != 1:+ print(f"ERROR: expected one .ort in {work}, found {orts}", file=sys.stderr)+ return 1+ src_ort = os.path.join(work, orts[0])++ shutil.move(src_ort, final_ort)+ finally:+ if not args.keep_onnx:+ shutil.rmtree(work, ignore_errors=True)++ # Sanity: confirm the .ort loads and report IO shapes.+ import onnxruntime as ort++ sess = ort.InferenceSession(final_ort, providers=["CPUExecutionProvider"])+ inp = sess.get_inputs()[0]+ out = sess.get_outputs()[0]+ print(f"[4/4] verified {final_ort}")+ print(f" input {inp.name} {inp.shape}")+ print(f" output {out.name} {out.shape}")+ print(f"DONE -> {final_ort}")+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/tools/scripts/download_dev_deps.py b/tools/scripts/download_dev_deps.pyindex a67fea2eba..5d73fee453 100755--- a/tools/scripts/download_dev_deps.py+++ b/tools/scripts/download_dev_deps.py@@ -77,14 +77,25 @@ import requests## Source of the native static archives: infiniflow/ragflow-build (our own# ORT-only minimal build), NOT the third-party csukuangfj/onnxruntime-libs-# account. The release tag is `onnxruntime-v{ORT_VERSION}` and it publishes one-# asset per target: `onnxruntime-v{ORT_VERSION}-<target>.zip` (see ort_target).-# The archive is occasionally re-issued under this SAME tag/asset name with+# account. The release tag is `ORT_RELEASE_TAG` (see below; currently+# onnxruntime-v1.29.0-patch2) and it publishes one asset per target:+# `onnxruntime-v{ORT_VERSION}-<target>.zip` (see ort_target). The archive is+# occasionally re-issued under this SAME tag/asset name with# patched content (e.g. the build that exports SessionGetInitializer*); the# downloader detects that via a `{asset}.sha256` sidecar and# re-downloads/re-extracts, so a stale local copy never silently lingers.ORT_VERSION = "1.29.0"+# Release tag on infiniflow/ragflow-build. v1.29.0's Linux x86_64 minimal build+# reduced operators to required_operators.config, which omitted Clip@13 — so+# Clip(opset 13) models (e.g. the DeepDoc rec/tsr weights) failed to load with+# "Could not find an implementation for Clip(13)". onnxruntime-v1.29.0-patch2+# re-adds Clip to the ai.onnx;13 allow list and rebuilds. Its asset name,+# extracted dir and normalized dir all keep the bare version, so ONLY the+# release tag changes here (revert to onnxruntime-v{ORT_VERSION} once a stock+# build ships Clip@13).+ORT_RELEASE_TAG = "onnxruntime-v1.29.0-patch2"+# pdf_oxide go-ffi release. Bare module version (the "v" is added by# pdf_oxide_url); matches the value build.sh uses to validate the embedded# .a stamp.@@ -213,7 +224,7 @@ def ort_asset_name(version: str, target: str) -> str:def ort_url(version: str, target: str) -> str:- return f"{gh_proxy()}https://github.com/infiniflow/ragflow-build/releases/download/onnxruntime-v{version}/{ort_asset_name(version, target)}"+ return f"{gh_proxy()}https://github.com/infiniflow/ragflow-build/releases/download/{ORT_RELEASE_TAG}/{ort_asset_name(version, target)}"def ort_extracted_dir(version: str, target: str) -> str: