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
refactor: knowledge compilation templates (#20383)
Jin Haifb2699f9b339
diff --git a/Dockerfile b/Dockerfileindex edf6e94357..55e2b74958 100644--- a/Dockerfile+++ b/Dockerfile@@ -254,7 +254,7 @@ COPY rag/prompts rag/prompts# Wiki page-structure presets read at runtime by the Go backend# (CompilationTemplateService.LoadWikiPresets).-COPY api/db/init_data/compilation_templates ./api/db/init_data/compilation_templates+COPY internal/ingestion/knowledge_compile/templates ./internal/ingestion/knowledge_compile/templates# Copy compiled web pagesdiff --git a/internal/ingestion/component/knowledge_compiler/tree/raptor.go b/internal/ingestion/component/knowledge_compiler/tree/raptor.goindex 833ac75dfd..0003efc78c 100644--- a/internal/ingestion/component/knowledge_compiler/tree/raptor.go+++ b/internal/ingestion/component/knowledge_compiler/tree/raptor.go@@ -667,13 +667,7 @@ func toFloat64Matrix(vecs [][]float32) [][]float64 {return out}-// defaultRaptorPrompt is the summary task template. It mirrors the production-// prompt from api/db/init_data/compilation_templates/tree.yaml (the tree-// compilation template), NOT the Python fallback in compiler.py:128. The-// {cluster_content} placeholder is filled with the joined cluster text. The-// YAML literal block carries a base indent of 6 spaces before {cluster_content};-// those 6 spaces are part of the prompt and MUST be preserved. A caller may-// override it via extra["prompt"] (Python: raptor_cfg["prompt"]).+// defaultRaptorPrompt is the summary task template.const defaultRaptorPrompt = "Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:\n {cluster_content}\nThe above is the content you need to summarize."// raptorSystemHelper mirrors the leading "You're a helpful assistant.\n\nHelp mediff --git a/internal/ingestion/component/knowledge_compiler/tree/raptor_test.go b/internal/ingestion/component/knowledge_compiler/tree/raptor_test.goindex fbe0eea028..c8a71607dc 100644--- a/internal/ingestion/component/knowledge_compiler/tree/raptor_test.go+++ b/internal/ingestion/component/knowledge_compiler/tree/raptor_test.go@@ -177,11 +177,7 @@ func TestBuildTreeNoPanicWhenAllSummariesFail(t *testing.T) {// TestDefaultRaptorPromptMatchesTreeYAML locks the default summary prompt to the// production tree.yaml template. It must equal the Python tree compilation-// template prompt (api/db/init_data/compilation_templates/tree.yaml), NOT the-// compiler.py:128 fallback. Critically, the YAML literal block carries a base-// indent of 6 spaces before {cluster_content}; those 6 spaces are part of the-// prompt and must be preserved (Python does self._prompt.format(...), splicing-// the cluster text after the 6-space indent).+// template prompt.func TestDefaultRaptorPromptMatchesTreeYAML(t *testing.T) {want := "Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:\n {cluster_content}\nThe above is the content you need to summarize."if defaultRaptorPrompt != want {diff --git a/api/db/init_data/compilation_templates/knowledge_graph.yaml b/internal/ingestion/knowledge_compile/templates/knowledge_graph.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/knowledge_graph.yamlrename to internal/ingestion/knowledge_compile/templates/knowledge_graph.yamldiff --git a/api/db/init_data/compilation_templates/mind_map.yaml b/internal/ingestion/knowledge_compile/templates/mind_map.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/mind_map.yamlrename to internal/ingestion/knowledge_compile/templates/mind_map.yamldiff --git a/api/db/init_data/compilation_templates/page_index.yaml b/internal/ingestion/knowledge_compile/templates/page_index.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/page_index.yamlrename to internal/ingestion/knowledge_compile/templates/page_index.yamldiff --git a/api/db/init_data/compilation_templates/session_essence.yaml b/internal/ingestion/knowledge_compile/templates/session_essence.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/session_essence.yamlrename to internal/ingestion/knowledge_compile/templates/session_essence.yamldiff --git a/api/db/init_data/compilation_templates/session_graph.yaml b/internal/ingestion/knowledge_compile/templates/session_graph.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/session_graph.yamlrename to internal/ingestion/knowledge_compile/templates/session_graph.yamldiff --git a/api/db/init_data/compilation_templates/timeline.yaml b/internal/ingestion/knowledge_compile/templates/timeline.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/timeline.yamlrename to internal/ingestion/knowledge_compile/templates/timeline.yamldiff --git a/api/db/init_data/compilation_templates/tree.yaml b/internal/ingestion/knowledge_compile/templates/tree.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/tree.yamlrename to internal/ingestion/knowledge_compile/templates/tree.yamldiff --git a/api/db/init_data/compilation_templates/wiki.yaml b/internal/ingestion/knowledge_compile/templates/wiki.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/wiki.yamlrename to internal/ingestion/knowledge_compile/templates/wiki.yamldiff --git a/api/db/init_data/compilation_templates/wiki/brand.yaml b/internal/ingestion/knowledge_compile/templates/wiki/brand.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/wiki/brand.yamlrename to internal/ingestion/knowledge_compile/templates/wiki/brand.yamldiff --git a/api/db/init_data/compilation_templates/wiki/engineering.yaml b/internal/ingestion/knowledge_compile/templates/wiki/engineering.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/wiki/engineering.yamlrename to internal/ingestion/knowledge_compile/templates/wiki/engineering.yamldiff --git a/api/db/init_data/compilation_templates/wiki/general.yaml b/internal/ingestion/knowledge_compile/templates/wiki/general.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/wiki/general.yamlrename to internal/ingestion/knowledge_compile/templates/wiki/general.yamldiff --git a/api/db/init_data/compilation_templates/wiki/market.yaml b/internal/ingestion/knowledge_compile/templates/wiki/market.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/wiki/market.yamlrename to internal/ingestion/knowledge_compile/templates/wiki/market.yamldiff --git a/api/db/init_data/compilation_templates/wiki/product.yaml b/internal/ingestion/knowledge_compile/templates/wiki/product.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/wiki/product.yamlrename to internal/ingestion/knowledge_compile/templates/wiki/product.yamldiff --git a/api/db/init_data/compilation_templates/wiki/user_interview.yaml b/internal/ingestion/knowledge_compile/templates/wiki/user_interview.yamlsimilarity index 100%rename from api/db/init_data/compilation_templates/wiki/user_interview.yamlrename to internal/ingestion/knowledge_compile/templates/wiki/user_interview.yamldiff --git a/internal/service/compilation_template_service.go b/internal/service/compilation_template_service.goindex 73decaab90..a65c842e86 100644--- a/internal/service/compilation_template_service.go+++ b/internal/service/compilation_template_service.go@@ -127,10 +127,8 @@ func (s *CompilationTemplateService) ListBuiltins(ctx context.Context, tenantID}// LoadWikiPresets loads the wiki page-structure presets from the-// init_data/compilation_templates/wiki/*.yaml files, filesystem-fresh per call.func (s *CompilationTemplateService) LoadWikiPresets() ([]*WikiPreset, error) {- wikiDir := filepath.Join(utility.GetProjectBaseDirectory(),- "api", "db", "init_data", "compilation_templates", "wiki")+ wikiDir := filepath.Join(utility.GetProjectBaseDirectory(), "internal", "ingestion", "knowledge_compile", "templates", "wiki")entries, err := os.ReadDir(wikiDir)if err != nil {if os.IsNotExist(err) {@@ -288,8 +286,7 @@ func (s *CompilationTemplateService) sortBuiltins(templates []*BuiltinTemplate)}func loadBuiltinTemplates() ([]*BuiltinTemplate, error) {- dir := filepath.Join(utility.GetProjectBaseDirectory(),- "api", "db", "init_data", "compilation_templates")+ dir := filepath.Join(utility.GetProjectBaseDirectory(), "internal", "ingestion", "knowledge_compile", "templates")entries, err := os.ReadDir(dir)if err != nil {if os.IsNotExist(err) {diff --git a/internal/service/compilation_template_service_test.go b/internal/service/compilation_template_service_test.goindex feb88d8076..14db93cf6a 100644--- a/internal/service/compilation_template_service_test.go+++ b/internal/service/compilation_template_service_test.go@@ -129,7 +129,7 @@ func TestLoadWikiPresets_FrontendContract(t *testing.T) {t.Fatalf("LoadWikiPresets: %v", err)}if len(presets) == 0 {- t.Fatal("expected wiki presets to load from api/db/init_data")+ t.Fatal("expected wiki presets to load from internal/ingestion/knowledge_compile")}for _, preset := range presets {if preset.Instruction == "" {@@ -165,7 +165,7 @@ func TestLoadBuiltinTemplates_AllYAMLDefinitions(t *testing.T) {}t.Cleanup(func() { _ = os.Chdir(origWd) })- dir := filepath.Join("api", "db", "init_data", "compilation_templates")+ dir := filepath.Join("internal", "ingestion", "knowledge_compile", "templates")entries, err := os.ReadDir(dir)if err != nil {t.Fatalf("read builtin template directory: %v", err)@@ -193,7 +193,7 @@ func TestLoadBuiltinTemplates_AllYAMLDefinitions(t *testing.T) {if template.Config["kind"] == nil {t.Errorf("builtin template %q has no config.kind", template.ID)}- if _, err := common.KindToVariant(template.Kind); err != nil {+ if _, err = common.KindToVariant(template.Kind); err != nil {t.Errorf("builtin template %q kind %q is not supported: %v", template.ID, template.Kind, err)}// Tree intentionally carries empty entity/relation stubs for the shared@@ -204,7 +204,7 @@ func TestLoadBuiltinTemplates_AllYAMLDefinitions(t *testing.T) {"kind": template.Kind,"config": map[string]interface{}(template.Config),}- if err := ValidateTemplatePayload(payload, true); err != nil {+ if err = ValidateTemplatePayload(payload, true); err != nil {t.Errorf("builtin template %q failed validation: %v", template.ID, err)}}