Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: NOT generate graph all entities/relations as a graph chunk (#19474)

Wang Qi3dbca958dba2
diff --git a/internal/ingestion/component/knowledge_compiler/component_test.go b/internal/ingestion/component/knowledge_compiler/component_test.go
index bf6cae2b22..8bd8b1c363 100644
--- a/internal/ingestion/component/knowledge_compiler/component_test.go
+++ b/internal/ingestion/component/knowledge_compiler/component_test.go
@@ -211,37 +211,23 @@ func TestKnowledgeCompiler_Structure_EndToEnd(t *testing.T) {
if !ok {
t.Fatalf("chunks = %T, want []any", out["chunks"])
}
- // 2 input chunks + 3 entities + 2 relations + 1 graph = 8 total (the
+ // 2 input chunks + 3 entities + 2 relations = 7 total (the
// compiled knowledge units are merged into the upstream input chunks).
- if len(chunks) != 8 {
- t.Fatalf("len(chunks) = %d, want 8 (2 input + 3 entities + 2 relations + 1 graph)", len(chunks))
+ if len(chunks) != 7 {
+ t.Fatalf("len(chunks) = %d, want 7 (2 input + 3 entities + 2 relations)", len(chunks))
}
- // Exactly one graph product, parseable to {entities, relations} (mirrors
- // Python's _struct_rebuild_graph_json).
- var graph map[string]any
+ // Entity and relation products are emitted individually, without an
+ // additional graph-summary chunk.
for _, c := range chunks {
cm, ok := c.(map[string]any)
if !ok {
continue
}
if kind, _ := cm["kc_kind"].(string); kind == "graph" {
- if err := json.Unmarshal([]byte(cm["text"].(string)), &graph); err != nil {
- t.Fatalf("unmarshal graph: %v", err)
- }
+ t.Fatal("graph chunk emitted")
}
}
- if graph == nil {
- t.Fatal("no graph chunk emitted")
- }
- entities, _ := graph["entities"].([]any)
- relations, _ := graph["relations"].([]any)
- if len(entities) != 3 {
- t.Fatalf("graph entities = %d, want 3 (Alpha/Beta/Gamma)", len(entities))
- }
- if len(relations) != 2 {
- t.Fatalf("graph relations = %d, want 2", len(relations))
- }
}
func TestKnowledgeCompiler_UnknownVariant(t *testing.T) {
@@ -644,8 +630,8 @@ func TestKnowledgeCompiler_EmitsChunks(t *testing.T) {
}
}
}
- if compiled != 6 {
- t.Fatalf("compiled structure chunks = %d, want 6 (3 entities + 2 relations + 1 graph)", compiled)
+ if compiled != 5 {
+ t.Fatalf("compiled structure chunks = %d, want 5 (3 entities + 2 relations)", compiled)
}
}
diff --git a/internal/ingestion/component/knowledge_compiler/golden/fixtures/structure_wiki_baseline.json b/internal/ingestion/component/knowledge_compiler/golden/fixtures/structure_wiki_baseline.json
index eff2c2ac19..7f1990ded7 100644
--- a/internal/ingestion/component/knowledge_compiler/golden/fixtures/structure_wiki_baseline.json
+++ b/internal/ingestion/component/knowledge_compiler/golden/fixtures/structure_wiki_baseline.json
@@ -1,7 +1,7 @@
{
- "note": "Locked Go-side product-count gate for structure/wiki (PORT_PLAN.md 缺口 E). These counts are the golden contract for the fixed corpus with the deterministic mock LLM/embedder. They must be reconciled against the Python baseline (rag/advanced_rag/knowlege_compile/structure.py, wiki.py) when a live run is available; a change here is a deliberate, reviewed contract update. 2026-07-27: structure gate now feeds a graph-kind parser_config (hypergraph path): 12 corpus chunks pack into one batch, the mock extracts 5 entities (Alpha..Epsilon) + 6 relations (fixed Greek pairs) + 1 graph summary = 12 (previously 6 under the legacy tuples contract).",
+ "note": "Locked Go-side product-count gate for structure/wiki (PORT_PLAN.md 缺口 E). These counts are the golden contract for the fixed corpus with the deterministic mock LLM/embedder. They must be reconciled against the Python baseline (rag/advanced_rag/knowlege_compile/structure.py, wiki.py) when a live run is available; a change here is a deliberate, reviewed contract update. 2026-09-10: structure gate feeds a graph-kind parser_config (hypergraph path): 12 corpus chunks pack into one batch, and the mock extracts 5 entities (Alpha..Epsilon) + 6 relations (fixed Greek pairs) without a graph summary = 11.",
"schema_version": 1,
"fixed_corpus_chunks": 12,
- "structure_products": 12,
+ "structure_products": 11,
"wiki_products": 1
}
diff --git a/internal/ingestion/component/knowledge_compiler/golden_test.go b/internal/ingestion/component/knowledge_compiler/golden_test.go
index 7ffa3b16d2..3cd621a36d 100644
--- a/internal/ingestion/component/knowledge_compiler/golden_test.go
+++ b/internal/ingestion/component/knowledge_compiler/golden_test.go
@@ -162,7 +162,7 @@ func TestGolden_Structure_ProductCount(t *testing.T) {
}
}
- // Exactly one graph product summarizing {nodes, edges}.
+ // Entity and relation products are emitted without a graph summary.
graphCount, nodeCount, edgeCount := 0, 0, 0
for _, p := range prods {
kind, _ := p.GetExtraString("kc_kind")
@@ -175,8 +175,8 @@ func TestGolden_Structure_ProductCount(t *testing.T) {
edgeCount++
}
}
- if graphCount != 1 {
- t.Fatalf("structure: graphCount = %d, want 1", graphCount)
+ if graphCount != 0 {
+ t.Fatalf("structure: graphCount = %d, want 0", graphCount)
}
if nodeCount == 0 || edgeCount == 0 {
t.Fatalf("structure: expected entities+relations, got nodes=%d edges=%d", nodeCount, edgeCount)
diff --git a/internal/ingestion/component/knowledge_compiler/structure/structure.go b/internal/ingestion/component/knowledge_compiler/structure/structure.go
index c25fb49cd2..60f207564d 100644
--- a/internal/ingestion/component/knowledge_compiler/structure/structure.go
+++ b/internal/ingestion/component/knowledge_compiler/structure/structure.go
@@ -156,16 +156,16 @@ func Run(ctx context.Context, deps common.Deps, param common.Param, inputs commo
}
// ---- GRAPH ----
- graphProduct, err := buildGraphProduct(ctx, deps, cfg, prods)
- if err != nil {
- return common.Outputs{}, err
- }
+ // graphProduct, err := buildGraphProduct(ctx, deps, cfg, prods)
+ // if err != nil {
+ // return common.Outputs{}, err
+ // }
// Buffer every product (plus the graph) in one slice; the component merges
// them into the upstream chunk stream (matching Python, which appends
// compiled units onto the chunk list).
products := append([]common.Product{}, prods...)
- products = append(products, graphProduct)
+ // products = append(products, graphProduct)
out := common.Outputs{
Products: products,
diff --git a/internal/ingestion/component/knowledge_compiler/structure/structure_test.go b/internal/ingestion/component/knowledge_compiler/structure/structure_test.go
index 4b409830fa..24336a80f4 100644
--- a/internal/ingestion/component/knowledge_compiler/structure/structure_test.go
+++ b/internal/ingestion/component/knowledge_compiler/structure/structure_test.go
@@ -463,8 +463,8 @@ func TestStructureRunGraphKind(t *testing.T) {
graphs++
}
}
- if entities != 3 || relations != 2 || graphs != 1 {
- t.Fatalf("products = %d entities + %d relations + %d graph, want 3+2+1", entities, relations, graphs)
+ if entities != 3 || relations != 2 || graphs != 0 {
+ t.Fatalf("products = %d entities + %d relations + %d graph, want 3+2+0", entities, relations, graphs)
}
if out.DuplicatesDropped != 1 {
t.Fatalf("DuplicatesDropped = %d, want 1 (the cross-chunk Beta)", out.DuplicatesDropped)
@@ -480,17 +480,6 @@ func TestStructureRunGraphKind(t *testing.T) {
if parsePayload(betaProduct.Content) == nil {
t.Fatalf("entity content is not payload JSON: %q", betaProduct.Content)
}
-
- // Graph summary mirrors Python's {entities, relations} shape.
- g := parsePayload(graphContentOf(out))
- if g == nil {
- t.Fatal("graph product missing/unparseable")
- }
- gEnts, _ := g["entities"].([]any)
- gRels, _ := g["relations"].([]any)
- if len(gEnts) != 3 || len(gRels) != 2 {
- t.Fatalf("graph = %d entities + %d relations, want 3+2", len(gEnts), len(gRels))
- }
}
func TestStructureListKindSkipsRelations(t *testing.T) {
@@ -779,14 +768,3 @@ func TestCosineDecider(t *testing.T) {
t.Fatalf("expected keep at 0.5, got %v", got)
}
}
-
-// ---- helpers ----
-
-func graphContentOf(out common.Outputs) string {
- for _, p := range out.Products {
- if p.Meta["kind"] == "graph" {
- return p.Content
- }
- }
- return ""
-}