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
Go: refactor (#20054)
Jin Hai72a541dd414a
diff --git a/cmd/ragflow_server.go b/cmd/ragflow_server.goindex 6fc51720d0..7f08a78d3d 100644--- a/cmd/ragflow_server.go+++ b/cmd/ragflow_server.go@@ -33,8 +33,8 @@ import ("ragflow/internal/agent/runtime"agenttool "ragflow/internal/agent/tool""ragflow/internal/channels"- native "ragflow/internal/deepdoc/native"- pdf "ragflow/internal/deepdoc/parser/pdf"+ "ragflow/internal/deepdoc/native"+ "ragflow/internal/deepdoc/parser/pdf"modelModule "ragflow/internal/entity/models""ragflow/internal/handler""ragflow/internal/ingestion/knowledge_compile"@@ -44,7 +44,7 @@ import ("ragflow/internal/server/local""ragflow/internal/service""ragflow/internal/service/chunk"- dataset "ragflow/internal/service/dataset"+ "ragflow/internal/service/dataset""ragflow/internal/service/document""ragflow/internal/service/file""ragflow/internal/service/nav"@@ -682,7 +682,7 @@ func runAdmin(ctx context.Context, serverName string, args *serverArgs) error {ginEngine := gin.New()// Mirror Quart's merge_slashes: collapse duplicate slashes before routing.ginEngine.RemoveExtraSlash = true- // Only honour X-Forwarded-For / X-Real-IP from the configured proxies+ // Only honor X-Forwarded-For / X-Real-IP from the configured proxies// (default: the loopback nginx bundled in the image), never from every peer.if err := common.ConfigureTrustedProxies(ginEngine, globalConfig.GetAPIServerConfig().TrustedProxies); err != nil {common.Fatal("Failed to configure trusted proxies", zap.Error(err))@@ -1205,7 +1205,7 @@ func startServer(ctx context.Context, serverName string, arguments *serverArgs)ginEngine := gin.New()// Mirror Quart's merge_slashes: collapse duplicate slashes before routing.ginEngine.RemoveExtraSlash = true- // Only honour X-Forwarded-For / X-Real-IP from the configured proxies+ // Only honor X-Forwarded-For / X-Real-IP from the configured proxies// (default: the loopback nginx bundled in the image), never from every// peer. c.ClientIP() feeds the agent webhook ip_whitelist gate and the// login audit records, so gin's trust-everything default would let anydiff --git a/internal/agent/component/switch.go b/internal/agent/component/switch.goindex 0be3658525..d1d2c1be5c 100644--- a/internal/agent/component/switch.go+++ b/internal/agent/component/switch.go@@ -410,7 +410,7 @@ func evaluateClause(clause map[string]any, state *runtime.CanvasState) (bool, erreturn ln < rn, nilcase ">=":return ln >= rn, nil- case "<=":+ default:return ln <= rn, nil}}diff --git a/internal/common/retry.go b/internal/common/retry.goindex a4de4be11b..2af4755a15 100644--- a/internal/common/retry.go+++ b/internal/common/retry.go@@ -113,7 +113,7 @@ func IsTransientError(err error) bool {if code >= 500 || code == 429 {return true}- if code >= 400 && code < 500 {+ if code >= 400 {return false}}diff --git a/internal/deepdoc/native/det_helpers.go b/internal/deepdoc/native/det_helpers.goindex 6318b389a4..8be80e734b 100644--- a/internal/deepdoc/native/det_helpers.go+++ b/internal/deepdoc/native/det_helpers.go@@ -268,16 +268,3 @@ func clipLine(mw, mh, x0, y0, x1, y1 int) (int, int, int, int) {}return x0, y0, x1, y1}--func math_min(a, b float64) float64 {- if a < b {- return a- }- return b-}-func math_max(a, b float64) float64 {- if a > b {- return a- }- return b-}diff --git a/internal/deepdoc/parser/pdf/table/table_cells.go b/internal/deepdoc/parser/pdf/table/table_cells.goindex 84c00f4ecf..cffdb4acbe 100644--- a/internal/deepdoc/parser/pdf/table/table_cells.go+++ b/internal/deepdoc/parser/pdf/table/table_cells.go@@ -656,7 +656,7 @@ func HeaderSetWithBlockType(rows [][]pdf.TSRCell, boxes []pdf.TextBox) map[int]bif bt == "Nu" {continue // numeric cell in a numeric table: ignored}- if colHit[ri][ci] || bt != "Nu" {+ if colHit[ri][ci] {h++}}diff --git a/internal/engine/serenedb/search.go b/internal/engine/serenedb/search.goindex d3c57e445e..0f8629c0a0 100644--- a/internal/engine/serenedb/search.go+++ b/internal/engine/serenedb/search.go@@ -107,7 +107,7 @@ func (e *serenedbEngine) Search(ctx context.Context, req *types.SearchRequest) (if scored && len(result.Chunks) > 1 {sortByScore(result.Chunks)}- if limit > 0 && len(result.Chunks) > limit {+ if len(result.Chunks) > limit {result.Chunks = result.Chunks[:limit]}if result.Total == 0 {diff --git a/internal/harness/graph/managed/managed.go b/internal/harness/graph/managed/managed.goindex fdefd0f5dc..1ace73a1b2 100644--- a/internal/harness/graph/managed/managed.go+++ b/internal/harness/graph/managed/managed.go@@ -662,23 +662,6 @@ func cloneMap(src map[string]any) map[string]any {return clone}-// DEFAULT_RUNTIME is the default runtime instance with nil values.-// Configurable is nil (not an empty map) so that direct mutation via Set-// panics with nil pointer dereference rather than silently corrupting a-// shared global. Callers must use Clone() to obtain a safe copy.-// This corresponds to Python's DEFAULT_RUNTIME in runtime.py-var DEFAULT_RUNTIME = &Runtime{- TaskID: "",- NodeName: "",- Step: 0,- Configurable: nil,- CheckpointNS: "",- Context: nil,- Store: nil,- StreamWriter: nil,- Previous: nil,-}-// GetTaskID returns the task ID from config.func GetTaskID(config map[string]interface{}) string {if config == nil {diff --git a/internal/harness/graph/pregel/traced_engine.go b/internal/harness/graph/pregel/traced_engine.goindex 8cc68e4381..d45ab95603 100644--- a/internal/harness/graph/pregel/traced_engine.go+++ b/internal/harness/graph/pregel/traced_engine.go@@ -225,10 +225,8 @@ func (te *TracedEngine) traceEvent(ctx context.Context, event any, rootSpan tracintSpan.SetStatus(codes.Ok, "")intSpan.End()case EventTypeError:- if rootSpan != nil {- rootSpan.SetStatus(codes.Error, fmt.Sprintf("%v", se.Error))- rootSpan.RecordError(se.Error)- }+ rootSpan.SetStatus(codes.Error, fmt.Sprintf("%v", se.Error))+ rootSpan.RecordError(se.Error)case EventTypeTaskStart:_, taskSpan := te.tracer.Start(ctx, SpanNodeExecute,trace.WithSpanKind(trace.SpanKindInternal),diff --git a/internal/ingestion/task/constants.go b/internal/ingestion/task/constants.godeleted file mode 100644index d7eebaa8b5..0000000000--- a/internal/ingestion/task/constants.go+++ /dev/null@@ -1,23 +0,0 @@-//-// 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 task--// Special doc_id values used in task messages (mirrors Python constants).-const (- // GRAPH_RAPTOR_FAKE_DOC_ID is the fake doc_id used for RAPTOR-generated chunks.- GRAPH_RAPTOR_FAKE_DOC_ID = "graph_raptor_fake_doc"-)diff --git a/internal/ingestion/task/golden_compare.go b/internal/ingestion/task/golden_compare.goindex d5f94b89e1..437e039f7a 100644--- a/internal/ingestion/task/golden_compare.go+++ b/internal/ingestion/task/golden_compare.go@@ -19,7 +19,7 @@ package taskimport ("time"- indexdoc "ragflow/internal/ingestion/task/indexdoc"+ "ragflow/internal/ingestion/task/indexdoc")// GoldenCompareResult is the structured output used by the local golden tools.diff --git a/internal/rag/agentic-rag/runtime/action_session.go b/internal/rag/agentic-rag/runtime/action_session.goindex fee5baf7bb..5819e9c442 100644--- a/internal/rag/agentic-rag/runtime/action_session.go+++ b/internal/rag/agentic-rag/runtime/action_session.go@@ -1675,11 +1675,9 @@ func (m *InvokerSessionModel) CompleteWithTemperature(ctx context.Context, messareturn nil, err}reply := &ModelReply{Content: resp.Content}- if resp != nil {- reply.Usage = resp.Usage- reply.Tokens = totalOf(resp)- reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)- }+ reply.Usage = resp.Usage+ reply.Tokens = totalOf(resp)+ reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)return reply, nil}@@ -1724,11 +1722,9 @@ func (m *InvokerSessionModel) Complete(ctx context.Context, messages []schema.Mereturn nil, err}reply := &ModelReply{Content: resp.Content}- if resp != nil {- reply.Usage = resp.Usage- reply.Tokens = totalOf(resp)- reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)- }+ reply.Usage = resp.Usage+ reply.Tokens = totalOf(resp)+ reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)return reply, nil}diff --git a/internal/service/connector_box_oauth_test.go b/internal/service/connector_box_oauth_test.goindex 139c73af8a..e4f6fec10e 100644--- a/internal/service/connector_box_oauth_test.go+++ b/internal/service/connector_box_oauth_test.go@@ -8,7 +8,7 @@ import ("testing""ragflow/internal/common"- kvrocks "ragflow/internal/engine/kvrocks"+ "ragflow/internal/engine/kvrocks")type roundTripFunc func(*http.Request) (*http.Response, error)diff --git a/internal/service/document/knowledge_compile_status.go b/internal/service/document/knowledge_compile_status.goindex cda55970ec..0683d78484 100644--- a/internal/service/document/knowledge_compile_status.go+++ b/internal/service/document/knowledge_compile_status.go@@ -24,7 +24,7 @@ import ("ragflow/internal/common""ragflow/internal/engine/types"kccommon "ragflow/internal/ingestion/component/knowledge_compiler/common"- knowledge_compile "ragflow/internal/ingestion/knowledge_compile"+ "ragflow/internal/ingestion/knowledge_compile""go.uber.org/zap")diff --git a/internal/service/ingestion_task_service.go b/internal/service/ingestion_task_service.goindex a4483561f1..f16648cb77 100644--- a/internal/service/ingestion_task_service.go+++ b/internal/service/ingestion_task_service.go@@ -9,7 +9,7 @@ import ("ragflow/internal/common""ragflow/internal/dao"- kvrocks "ragflow/internal/engine/kvrocks"+ "ragflow/internal/engine/kvrocks""ragflow/internal/entity""go.uber.org/zap"diff --git a/internal/service/memory.go b/internal/service/memory.goindex cd097fe819..521727be35 100644--- a/internal/service/memory.go+++ b/internal/service/memory.go@@ -21,6 +21,11 @@ import ("context""errors""fmt"+ "ragflow/internal/common"+ "ragflow/internal/entity"+ "ragflow/internal/entity/models"+ "ragflow/internal/utility"+"slices""sort""strconv"@@ -30,14 +35,10 @@ import ("go.uber.org/zap""gorm.io/gorm"- "ragflow/internal/common""ragflow/internal/dao""ragflow/internal/engine"enginetypes "ragflow/internal/engine/types"- "ragflow/internal/entity"- models "ragflow/internal/entity/models""ragflow/internal/service/nlp"- "ragflow/internal/utility")const (diff --git a/internal/service/memory_extractor.go b/internal/service/memory_extractor.goindex 1c2d7a55a5..6f5c328b0d 100644--- a/internal/service/memory_extractor.go+++ b/internal/service/memory_extractor.go@@ -46,7 +46,7 @@ import ("ragflow/internal/common""ragflow/internal/dao""ragflow/internal/entity"- models "ragflow/internal/entity/models"+ "ragflow/internal/entity/models""go.uber.org/zap""gorm.io/gorm"diff --git a/internal/service/memory_message_service.go b/internal/service/memory_message_service.goindex a1f2463253..51c8637895 100644--- a/internal/service/memory_message_service.go+++ b/internal/service/memory_message_service.go@@ -61,9 +61,9 @@ import ("ragflow/internal/common""ragflow/internal/dao"- kvrocks "ragflow/internal/engine/kvrocks"+ "ragflow/internal/engine/kvrocks""ragflow/internal/entity"- models "ragflow/internal/entity/models"+ "ragflow/internal/entity/models""ragflow/internal/utility""gorm.io/gorm"diff --git a/internal/syncer/connector/rest_api.go b/internal/syncer/connector/rest_api.goindex b1d364f4ca..ba13175bcc 100644--- a/internal/syncer/connector/rest_api.go+++ b/internal/syncer/connector/rest_api.go@@ -1669,11 +1669,7 @@ func restAPIQuoteString(s string) string {b.WriteString(`\f`)default:if r < 0x20 || r == 0x7f {- if r < 0x100 {- b.WriteString(fmt.Sprintf(`\x%02x`, r))- } else {- b.WriteString(fmt.Sprintf(`\u%04x`, r))- }+ b.WriteString(fmt.Sprintf(`\x%02x`, r))} else {b.WriteRune(r)}diff --git a/internal/tokenizer/spm.go b/internal/tokenizer/spm.goindex ca712052b9..03540bcfc5 100644--- a/internal/tokenizer/spm.go+++ b/internal/tokenizer/spm.go@@ -315,11 +315,11 @@ func (m *sentencePieceModel) parseNormalizerSpec(raw []byte) error {m.addDummyPrefix = oncase 4:m.removeExtraWhitespaces = on- case 5:+ default:m.escapeWhitespaces = on}default:- if err := r.skip(wire); err != nil {+ if err = r.skip(wire); err != nil {return fmt.Errorf("sentencepiece: normalizer_spec: %w", err)}}