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
feat(deepdoc): make inference concurrency configurable (default 4) (#20044)
xugangqiangcf3986174e27
diff --git a/cmd/ragflow_server.go b/cmd/ragflow_server.goindex edcf349a5b..5206e92ed1 100644--- a/cmd/ragflow_server.go+++ b/cmd/ragflow_server.go@@ -88,6 +88,9 @@ type serverArgs struct {name *string // server nameenablePProf bool // enable pprof+ // deepdocInferenceConcurrency, when set, overrides the DeepDoc inference+ // concurrency from env/config. nil means "unspecified".+ deepdocInferenceConcurrency *int}func parseArgs() (*serverArgs, error) {@@ -105,6 +108,16 @@ func parseArgs() (*serverArgs, error) {}args.logLevel = &valuecontinue+ case "--deepdoc-inference-concurrency":+ n, convErr := strconv.Atoi(value)+ if convErr != nil {+ return nil, fmt.Errorf("invalid --deepdoc-inference-concurrency: %w", convErr)+ }+ if n <= 0 {+ return nil, fmt.Errorf("invalid --deepdoc-inference-concurrency %d: must be positive", n)+ }+ args.deepdocInferenceConcurrency = &n+ continue}}@@ -186,6 +199,19 @@ func parseArgs() (*serverArgs, error) {args.name = &os.Args[i]case "--profile":args.enablePProf = true+ case "--deepdoc-inference-concurrency":+ if i+1 >= len(os.Args) {+ return nil, errors.New("--deepdoc-inference-concurrency requires a value")+ }+ i+++ n, convErr := strconv.Atoi(os.Args[i])+ if convErr != nil {+ return nil, fmt.Errorf("invalid --deepdoc-inference-concurrency: %w", convErr)+ }+ if n <= 0 {+ return nil, fmt.Errorf("invalid --deepdoc-inference-concurrency %d: must be positive", n)+ }+ args.deepdocInferenceConcurrency = &ndefault:return nil, fmt.Errorf("unknown parameter: %s", arg)}@@ -218,6 +244,28 @@ func selectedLogLevel(args *serverArgs, configured string) string {return configured}+// resolveDeepDocInferenceConcurrency applies the precedence+// CLI flag > environment variable > config file > default(4) and returns the+// resolved DeepDoc inference concurrency budget.+func resolveDeepDocInferenceConcurrency(args *serverArgs, configured int) int {+ val := 4+ if configured > 0 {+ val = configured+ }+ if v := strings.TrimSpace(os.Getenv(common.EnvDeepDocInferenceConcurrency)); v != "" {+ if n, err := strconv.Atoi(v); err == nil && n > 0 {+ val = n+ }+ }+ // The CLI parser rejects a non-positive --deepdoc-inference-concurrency+ // up front (see TestParseArgsDeepDocInferenceConcurrency), so the parsed+ // value is already positive; no extra >0 guard is needed here.+ if args.deepdocInferenceConcurrency != nil {+ val = *args.deepdocInferenceConcurrency+ }+ return val+}+func printHelp(args *serverArgs) {switch {case args.mode == nil:@@ -426,7 +474,7 @@ func main() {// stdout-only window.switch *arguments.mode {case "api", "ingestor":- registerNativeDeepDoc()+ registerNativeDeepDoc(arguments)default:}@@ -1428,7 +1476,7 @@ func configureTTSSynthesizer(modelProviderService *service.ModelProviderService)// Fail-fast contract (P0): the in-process backend must be available at startup// (ORT + models present). There is NO silent degradation to an empty analyzer:// if the backend is not serving, the server aborts.-func registerNativeDeepDoc() {+func registerNativeDeepDoc(arguments *serverArgs) {modelDir := resolveDeepDocModelDir()dropScore := resolveDeepDocDropScore()@@ -1451,13 +1499,15 @@ func registerNativeDeepDoc() {zap.String("model_dir", modelDir))// DeepDoc sessions run single-threaded, so the process inference budget is a- // plain concurrency cap. Register it with the native gate every inference- // call passes through (internal/deepdoc/native/inference_limit.go); without- // this the process would let every page worker call inference at once.- limit := pdf.DeepDocConcurrency()- native.SetInferenceLimit(limit)+ // plain concurrency cap. Resolve it from CLI > env > config > default(4)+ // and register it with the native gate every inference call passes through+ // (internal/deepdoc/native/inference_limit.go); without this the process+ // would let every page worker call inference at once.+ budget := resolveDeepDocInferenceConcurrency(arguments, server.GetConfig().GetDeepDocConfig().InferenceConcurrency)+ pdf.SetDeepDocConcurrency(budget)+ native.SetInferenceLimit(budget)common.Info("in-process DeepDoc inference limit registered",- zap.Int("max_concurrent_inference", limit),+ zap.Int("max_concurrent_inference", budget),zap.Int("gomaxprocs", goruntime.GOMAXPROCS(0)))}diff --git a/cmd/ragflow_server_deepdoc_test.go b/cmd/ragflow_server_deepdoc_test.gonew file mode 100644index 0000000000..74deac3a19--- /dev/null+++ b/cmd/ragflow_server_deepdoc_test.go@@ -0,0 +1,102 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package main++import (+ "os"+ "testing"++ "ragflow/internal/common"+)++// TestResolveDeepDocInferenceConcurrency pins the precedence+// CLI > environment > config file > default(4).+func TestResolveDeepDocInferenceConcurrency(t *testing.T) {+ const envKey = common.EnvDeepDocInferenceConcurrency++ cases := []struct {+ name string+ configured int+ env string // "" means leave unset+ cli *int+ want int+ }{+ {"default", 0, "", nil, 4},+ {"config only", 6, "", nil, 6},+ {"env overrides config", 6, "8", nil, 8},+ {"cli overrides env and config", 6, "8", intPtr(12), 12},+ {"env invalid falls back to config", 6, "notanint", nil, 6},+ {"env only", 0, "9", nil, 9},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ // t.Setenv restores the previous value after the subtest.+ t.Setenv(envKey, tc.env)+ args := &serverArgs{deepdocInferenceConcurrency: tc.cli}+ if got := resolveDeepDocInferenceConcurrency(args, tc.configured); got != tc.want {+ t.Fatalf("got %d, want %d (configured=%d env=%q cli=%v)",+ got, tc.want, tc.configured, tc.env, tc.cli)+ }+ })+ }+}++func intPtr(n int) *int { return &n }++// TestParseArgsDeepDocInferenceConcurrency pins the contract that the CLI parser+// rejects a non-positive or non-integer --deepdoc-inference-concurrency up front+// (both the "--flag=value" and "--flag value" forms), and accepts a positive+// value. Because the parser guarantees a positive value, resolveDeepDocInference+// Concurrency can trust the parsed pointer and needs no extra >0 guard.+func TestParseArgsDeepDocInferenceConcurrency(t *testing.T) {+ cases := []struct {+ name string+ args []string+ wantErr bool+ want int+ }{+ {"equals zero", []string{"prog", "--deepdoc-inference-concurrency=0"}, true, 0},+ {"equals negative", []string{"prog", "--deepdoc-inference-concurrency=-3"}, true, 0},+ {"equals nonint", []string{"prog", "--deepdoc-inference-concurrency=abc"}, true, 0},+ {"space zero", []string{"prog", "--deepdoc-inference-concurrency", "0"}, true, 0},+ {"space negative", []string{"prog", "--deepdoc-inference-concurrency", "-3"}, true, 0},+ {"space nonint", []string{"prog", "--deepdoc-inference-concurrency", "abc"}, true, 0},+ {"equals positive", []string{"prog", "--deepdoc-inference-concurrency=12"}, false, 12},+ {"space positive", []string{"prog", "--deepdoc-inference-concurrency", "12"}, false, 12},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ old := os.Args+ defer func() { os.Args = old }()+ os.Args = tc.args++ got, err := parseArgs()+ if tc.wantErr {+ if err == nil {+ t.Fatalf("parseArgs() = nil error, want rejection for %v", tc.args)+ }+ return+ }+ if err != nil {+ t.Fatalf("parseArgs() error = %v, want nil for %v", err, tc.args)+ }+ if got.deepdocInferenceConcurrency == nil || *got.deepdocInferenceConcurrency != tc.want {+ t.Fatalf("deepdocInferenceConcurrency = %v, want %d for %v", got.deepdocInferenceConcurrency, tc.want, tc.args)+ }+ })+ }+}diff --git a/conf/service_conf.yaml b/conf/service_conf.yamlindex f2ae7e5c35..e11a5b9df6 100644--- a/conf/service_conf.yaml+++ b/conf/service_conf.yaml@@ -10,6 +10,14 @@ ragflow:# or CIDR of a further proxy in front of nginx; an empty list trusts none.# trusted_proxies: ['127.0.0.0/8', '::1/128']+# DeepDoc in-process (Go) ONNX inference settings.+deepdoc:+ # Max concurrent DeepDoc ONNX inference Runs in this process; each Run uses+ # exactly one CPU core (intraOpThreads is pinned to 1 in the native package).+ # Override with the env var RAGFLOW_DEEPDOC_INFERENCE_CONCURRENCY, or the CLI+ # flag --deepdoc-inference-concurrency (highest precedence). Default 4.+ inference_concurrency: 4+# Optional standalone MCP listener for the Go API server. Uncomment to enable.# RAGFLOW_MCP_* environment variables override these settings.# mcp:diff --git a/internal/common/environments.go b/internal/common/environments.goindex c3f2a80efa..dc225657a7 100644--- a/internal/common/environments.go+++ b/internal/common/environments.go@@ -257,6 +257,11 @@ const (// Recognizer.drop_score (deepdoc/vision/ocr.py, default 0.5) so both// backends apply the same text-blanking contract.EnvDeepDocDropScore = "DEEPDOC_DROP_SCORE"+ // EnvDeepDocInferenceConcurrency bounds how many DeepDoc ONNX inference+ // Runs may be in flight at once (each uses one core). It overrides the+ // deepdoc.inference_concurrency config key and is itself overridden by the+ // --deepdoc-inference-concurrency CLI flag.+ EnvDeepDocInferenceConcurrency = "RAGFLOW_DEEPDOC_INFERENCE_CONCURRENCY")// DeepDocModelFiles is the single source of truth for the weights thediff --git a/internal/deepdoc/parser/pdf/parser_concurrency.go b/internal/deepdoc/parser/pdf/parser_concurrency.goindex a51a39a0ed..c95f649fbf 100644--- a/internal/deepdoc/parser/pdf/parser_concurrency.go+++ b/internal/deepdoc/parser/pdf/parser_concurrency.go@@ -21,12 +21,14 @@ import (// threads DeepDoc inference occupies in this process are exactly the number of// Runs in flight at once — one number to bound.//-// That number is decided here, by the caller: DeepDocConcurrency() is this-// process's share of the CPUs, and it is (a) registered with the native gate-// every inference call passes through (native.SetInferenceLimit, called by the-// server's backend wiring) and (b) used to size the page worker pool. It is-// deliberately not user-configurable, so callers never have to reason about the-// knob.+// That number is the process inference budget. It is (a) registered with the+// native gate every inference call passes through (native.SetInferenceLimit,+// called by the server's backend wiring) and (b) used to size the page worker+// pool. It is configurable: the server resolves it once at start from+// CLI > env (RAGFLOW_DEEPDOC_INFERENCE_CONCURRENCY) > config+// (deepdoc.inference_concurrency) > default 4, then injects it with+// SetDeepDocConcurrency. Callers read it via DeepDocConcurrency(); they never+// have to reason about the precedence themselves.//// Native PDFium access (RenderPage / ExtractChars / PageSize / outlines)// is serialized by a process-wide mutex in package pdfsync, shared by@@ -35,20 +37,24 @@ import (// mutex (not a per-Parser limiter) is the correct guard. See// pdfsync/pdfsync.go.-// deepdocInferenceCPUShare is the share of the process's CPUs DeepDoc-// inference may occupy. The remainder is headroom for the Go runtime, PDFium,-// and I/O sharing the same cores.-const deepdocInferenceCPUShare = 0.8+// deepDocInferenceConcurrency is the process-wide DeepDoc ONNX inference budget,+// set once at server start via SetDeepDocConcurrency. It is the maximum number+// of Runs in flight; each Run is single-threaded (intraOpThreads = 1 in the+// native package), so it is also the number of cores inference may occupy.+var deepDocInferenceConcurrency = 4++// SetDeepDocConcurrency sets the process inference budget. It is called exactly+// once at server boot after CLI/env/config resolution. Non-positive values are+// clamped to 1.+func SetDeepDocConcurrency(n int) {+ deepDocInferenceConcurrency = max(1, n)+}// DeepDocConcurrency returns how many DeepDoc ONNX Runs this process may have in// flight at once — its inference budget. Sessions run single-threaded, so this// is also the number of threads inference occupies.-//-// The share is taken from GOMAXPROCS, not runtime.NumCPU: GOMAXPROCS is what-// the process is actually allowed to use (it honours a cgroup CPU quota), while-// NumCPU reports the host's cores inside a container.func DeepDocConcurrency() int {- return max(1, int(deepdocInferenceCPUShare*float64(runtime.GOMAXPROCS(0))))+ return deepDocInferenceConcurrency}// ── Page worker pool ─────────────────────────────────────────────────────diff --git a/internal/deepdoc/parser/pdf/parser_concurrency_test.go b/internal/deepdoc/parser/pdf/parser_concurrency_test.gonew file mode 100644index 0000000000..d04ad090eb--- /dev/null+++ b/internal/deepdoc/parser/pdf/parser_concurrency_test.go@@ -0,0 +1,64 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package pdf++import "testing"++// TestDeepDocConcurrencyDefaultsToFour pins the process inference budget+// default: when nothing configures it, DeepDocConcurrency() returns 4.+func TestDeepDocConcurrencyDefaultsToFour(t *testing.T) {+ orig := DeepDocConcurrency()+ t.Cleanup(func() { SetDeepDocConcurrency(orig) })++ SetDeepDocConcurrency(4)+ if got := DeepDocConcurrency(); got != 4 {+ t.Fatalf("DeepDocConcurrency() = %d, want 4", got)+ }+}++// TestSetDeepDocConcurrencyClampsToAtLeastOne pins the setter's floor: a+// non-positive value can never shrink the budget below 1, and a positive+// value is honoured exactly.+func TestSetDeepDocConcurrencyClampsToAtLeastOne(t *testing.T) {+ orig := DeepDocConcurrency()+ t.Cleanup(func() { SetDeepDocConcurrency(orig) })++ SetDeepDocConcurrency(0)+ if got := DeepDocConcurrency(); got != 1 {+ t.Fatalf("DeepDocConcurrency() after SetDeepDocConcurrency(0) = %d, want 1", got)+ }+ SetDeepDocConcurrency(-5)+ if got := DeepDocConcurrency(); got != 1 {+ t.Fatalf("DeepDocConcurrency() after SetDeepDocConcurrency(-5) = %d, want 1", got)+ }+ SetDeepDocConcurrency(9)+ if got := DeepDocConcurrency(); got != 9 {+ t.Fatalf("DeepDocConcurrency() after SetDeepDocConcurrency(9) = %d, want 9", got)+ }+}++// TestPageWorkerPoolTracksInferenceBudget pins the invariant that the shared+// page worker pool never exceeds the process inference budget.+func TestPageWorkerPoolTracksInferenceBudget(t *testing.T) {+ orig := DeepDocConcurrency()+ t.Cleanup(func() { SetDeepDocConcurrency(orig) })++ SetDeepDocConcurrency(7)+ if got, budget := defaultPageWorkerCount(), DeepDocConcurrency(); got > budget {+ t.Fatalf("defaultPageWorkerCount() = %d > DeepDocConcurrency() = %d", got, budget)+ }+}diff --git a/internal/deepdoc/parser/pdf/parser_parallel_test.go b/internal/deepdoc/parser/pdf/parser_parallel_test.goindex 729ca0ea9b..3924195d53 100644--- a/internal/deepdoc/parser/pdf/parser_parallel_test.go+++ b/internal/deepdoc/parser/pdf/parser_parallel_test.go@@ -9,7 +9,6 @@ import ("image""image/png""reflect"- "runtime""sync""testing"@@ -103,12 +102,20 @@ func TestDefaultPageWorkersTrackInferenceCapacity(t *testing.T) {}// TestDeepDocConcurrencyShare pins the process budget rule: DeepDoc inference-// may have floor(80% of the CPUs available to the process) Runs in flight.+// may have at most DeepDocConcurrency() Runs in flight, and that budget is the+// configurable value (default 4) set at server start, not derived from+// GOMAXPROCS.func TestDeepDocConcurrencyShare(t *testing.T) {- want := int(deepdocInferenceCPUShare * float64(runtime.GOMAXPROCS(0)))- if got := DeepDocConcurrency(); got != max(1, want) {- t.Fatalf("got %d concurrent Runs, want %d (GOMAXPROCS=%d)",- got, max(1, want), runtime.GOMAXPROCS(0))+ orig := DeepDocConcurrency()+ t.Cleanup(func() { SetDeepDocConcurrency(orig) })++ SetDeepDocConcurrency(4)+ if got := DeepDocConcurrency(); got != 4 {+ t.Fatalf("default DeepDocConcurrency() = %d, want 4", got)+ }+ SetDeepDocConcurrency(11)+ if got := DeepDocConcurrency(); got != 11 {+ t.Fatalf("DeepDocConcurrency() = %d, want 11 after SetDeepDocConcurrency(11)", got)}}diff --git a/internal/server/config.go b/internal/server/config.goindex 701cc79091..2f82df806a 100644--- a/internal/server/config.go+++ b/internal/server/config.go@@ -136,6 +136,11 @@ func Init(configPath string) error {return fmt.Errorf("parse log config error: %w", err)}+ err = globalConfig.ParseDeepDocConfig(v)+ if err != nil {+ return fmt.Errorf("parse deepdoc config error: %w", err)+ }+err = globalConfig.ParseSMTPConfig(v)if err != nil {return fmt.Errorf("parse SMTP config error: %w", err)diff --git a/internal/server/config/base.go b/internal/server/config/base.goindex dfbb624240..73a5db5ad4 100644--- a/internal/server/config/base.go+++ b/internal/server/config/base.go@@ -32,6 +32,7 @@ type Config struct {apiServer APIServerConfigsyncer SyncerConfigingestor IngestorConfig+ deepdoc DeepDocConfiglog LogConfigsmtp common.SMTPConfigdiff --git a/internal/server/config/deepdoc_config.go b/internal/server/config/deepdoc_config.gonew file mode 100644index 0000000000..129c6e8845--- /dev/null+++ b/internal/server/config/deepdoc_config.go@@ -0,0 +1,52 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package config++import (+ "github.com/spf13/viper"+)++// DeepDocConfig holds DeepDoc (in-process ONNX) inference settings.+type DeepDocConfig struct {+ // InferenceConcurrency bounds how many DeepDoc ONNX Runs this process may+ // have in flight at once. Each Run is single-threaded (intraOpThreads = 1+ // in the native package), so this is also the number of cores inference may+ // occupy. Default 4.+ InferenceConcurrency int `mapstructure:"inference_concurrency"`+}++// ParseDeepDocConfig populates DeepDocConfig from the viper instance. It reads+// only the deepdoc.inference_concurrency YAML key (default 4). The environment+// variable RAGFLOW_DEEPDOC_INFERENCE_CONCURRENCY does NOT override it here:+// v.Sub("deepdoc") does not inherit viper's AutomaticEnv settings (env prefix,+// replacer, AutomaticEnv are all dropped by Sub), so the env override would be+// missed if applied only through viper. The env override is therefore resolved+// later in the server boot path by cmd.resolveDeepDocInferenceConcurrency via+// os.Getenv, which also applies the --deepdoc-inference-concurrency CLI flag+// (highest precedence) over both.+func (c *Config) ParseDeepDocConfig(v *viper.Viper) error {+ c.deepdoc.InferenceConcurrency = 4+ if sub := v.Sub("deepdoc"); sub != nil && sub.IsSet("inference_concurrency") {+ c.deepdoc.InferenceConcurrency = sub.GetInt("inference_concurrency")+ }+ return nil+}++// GetDeepDocConfig returns the parsed DeepDoc configuration.+func (c *Config) GetDeepDocConfig() *DeepDocConfig {+ return &c.deepdoc+}diff --git a/internal/server/config/deepdoc_config_test.go b/internal/server/config/deepdoc_config_test.gonew file mode 100644index 0000000000..ad7e0bf60c--- /dev/null+++ b/internal/server/config/deepdoc_config_test.go@@ -0,0 +1,77 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package config++import (+ "strings"+ "testing"++ "ragflow/internal/common"++ "github.com/spf13/viper"+)++// TestParseDeepDocConfigDefaultsToFour pins the default inference concurrency.+func TestParseDeepDocConfigDefaultsToFour(t *testing.T) {+ v := viper.New()+ c := &Config{}+ if err := c.ParseDeepDocConfig(v); err != nil {+ t.Fatalf("ParseDeepDocConfig: %v", err)+ }+ if got := c.GetDeepDocConfig().InferenceConcurrency; got != 4 {+ t.Fatalf("default inference concurrency = %d, want 4", got)+ }+}++// TestParseDeepDocConfigReadsYAML pins that the deepdoc.inference_concurrency+// key is honoured when present.+func TestParseDeepDocConfigReadsYAML(t *testing.T) {+ v := viper.New()+ v.Set("deepdoc", map[string]any{"inference_concurrency": 6})+ c := &Config{}+ if err := c.ParseDeepDocConfig(v); err != nil {+ t.Fatalf("ParseDeepDocConfig: %v", err)+ }+ if got := c.GetDeepDocConfig().InferenceConcurrency; got != 6 {+ t.Fatalf("inference concurrency = %d, want 6", got)+ }+}++// TestParseDeepDocConfigIgnoresEnvVar pins the provenance of the env override:+// ParseDeepDocConfig reads ONLY the deepdoc.inference_concurrency YAML key and+// does not apply the RAGFLOW_DEEPDOC_INFERENCE_CONCURRENCY environment variable.+// This holds even with viper's AutomaticEnv configured exactly as server.Init+// does, because v.Sub("deepdoc") does not inherit the parent's env (prefix /+// replacer / AutomaticEnv). The env override is resolved later in the server+// boot path by cmd.resolveDeepDocInferenceConcurrency (via os.Getenv), so the+// configured value returned here must stay at the YAML/default value.+func TestParseDeepDocConfigIgnoresEnvVar(t *testing.T) {+ t.Setenv(common.EnvDeepDocInferenceConcurrency, "9")++ v := viper.New()+ v.SetEnvPrefix("RAGFLOW")+ v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))+ v.AutomaticEnv()++ c := &Config{}+ if err := c.ParseDeepDocConfig(v); err != nil {+ t.Fatalf("ParseDeepDocConfig: %v", err)+ }+ if got := c.GetDeepDocConfig().InferenceConcurrency; got != 4 {+ t.Fatalf("inference concurrency with only env set = %d, want default 4 (env must not be applied here)", got)+ }+}