mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-08 08:28:02 +08:00
## Problem During ingestion, `indexdoc.ProcessChunksForPipeline` stamped `ck["kb_id"]` on every chunk. This was both: - **a dead write** — `elasticsearch.InsertChunks` unconditionally overwrites the value with `datasetID` (`chunk.go:211`), so the producer's value never reached the index; - **the wrong shape** — it was emitted as `[]string`, while both engines actually need a single string. This is the `kb_id` slice of the ingestion -> engine schema leak tracked in #17371: ingestion was carrying index-physical schema knowledge it should not own. ## Fix Make the search engines the single owner of `kb_id` at the write boundary, and stop ingestion from emitting it: - **Elasticsearch** (`chunk.go:211`) already sets `docCopy["kb_id"] = datasetID` — unchanged. - **Infinity** (`chunk.go`) `InsertChunks` now stamps `insertChunks[i]["kb_id"] = datasetID` right after `transformChunkFields` (previously it only *read/normalized* the producer value, which forced ingestion to supply it). Both engines are now consistent. - `ProcessChunksForPipeline` no longer stamps `kb_id` and the now-leaky `kbID` parameter is removed. The same removal is propagated to `ProcessPipelineOutputForGolden` and the `compare_pipeline_golden` dev tool (its `-kb-id` flag is dropped). The stored `kb_id` value is byte-for-byte unchanged: `datasetID` passed to `InsertChunks` is `taskCtx.Doc.KbID`, i.e. the same id that was previously set on the producer chunk. ## Verification - `bash build.sh --test ./internal/ingestion/task/indexdoc/... ./internal/engine/infinity/...` — both green. - `internal/ingestion/task` has **two pre-existing** failures (`TestPipelineExecutor_Run_RealCanvasDSL_UsesGeneralPipeline`, `TestRunPipeline_RealPipelineOutput_ProducesIndexFields`) that assert `inserted chunk count = 1, want 2` — a parser/assertion mismatch (the Go parser merges the 2-paragraph fixture into 1 chunk). They are unrelated to this change, which never touches chunk counting. The `kb_id`-related test failure this change would otherwise introduce is fixed by updating the tests below. - Updated the pinning unit test: `TestProcessChunksForPipeline_SetsDocID` (formerly `...SetsDocIDAndKBID`) now asserts `kb_id` is **not** set by the producer. Removed the `kb_id` assertion and the now-dead `taskChunkFieldEqualsStr` helper from `pipeline_real_integration_test.go`. ## Scope This closes only the `kb_id` portion of #17371. The remaining index-physical fields (`docnm_kwd`, `create_timestamp_flt`, `page_num_int`/`top_int`/ `position_int`, etc.) are intentionally left for a follow-up (P2).
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package task
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
indexdoc "ragflow/internal/ingestion/task/indexdoc"
|
|
)
|
|
|
|
func TestProcessPipelineOutputForGolden_Markdown(t *testing.T) {
|
|
input := map[string]any{
|
|
"markdown": "# Title\n\nContent",
|
|
}
|
|
|
|
result, err := ProcessPipelineOutputForGolden(input, "doc-1", "sample.md")
|
|
if err != nil {
|
|
t.Fatalf("ProcessPipelineOutputForGolden: %v", err)
|
|
}
|
|
|
|
if len(result.NormalizedChunks) != 1 {
|
|
t.Fatalf("normalized len = %d, want 1", len(result.NormalizedChunks))
|
|
}
|
|
if got := result.NormalizedChunks[0]["text"]; got != "# Title\n\nContent" {
|
|
t.Fatalf("normalized text = %v, want markdown string", got)
|
|
}
|
|
if len(result.ProcessedChunks) != 1 {
|
|
t.Fatalf("processed len = %d, want 1", len(result.ProcessedChunks))
|
|
}
|
|
if got := result.ProcessedChunks[0]["content_with_weight"]; got != "# Title\n\nContent" {
|
|
t.Fatalf("content_with_weight = %v, want markdown string", got)
|
|
}
|
|
if _, exists := result.ProcessedChunks[0]["text"]; exists {
|
|
t.Fatal("processed chunk should not keep text key")
|
|
}
|
|
}
|
|
|
|
func TestProcessChunksForPipeline_StableFields(t *testing.T) {
|
|
now := time.Date(2026, 7, 3, 20, 0, 0, 0, time.FixedZone("CST", 8*3600))
|
|
chunks := []map[string]any{
|
|
{
|
|
"text": "hello",
|
|
"questions": "Q1\nQ2",
|
|
"keywords": "kw1,kw2",
|
|
"summary": "sum",
|
|
"metadata": map[string]any{"author": "Alice"},
|
|
},
|
|
}
|
|
|
|
meta, err := indexdoc.ProcessChunksForPipeline(chunks, "doc-1", "sample.md", now)
|
|
if err != nil {
|
|
t.Fatalf("ProcessChunksForPipeline: %v", err)
|
|
}
|
|
|
|
chunk := chunks[0]
|
|
if chunk["doc_id"] != "doc-1" {
|
|
t.Fatalf("doc_id = %v", chunk["doc_id"])
|
|
}
|
|
if chunk["docnm_kwd"] != "sample.md" {
|
|
t.Fatalf("docnm_kwd = %v", chunk["docnm_kwd"])
|
|
}
|
|
if chunk["content_with_weight"] != "hello" {
|
|
t.Fatalf("content_with_weight = %v", chunk["content_with_weight"])
|
|
}
|
|
if _, ok := chunk["id"].(string); !ok {
|
|
t.Fatalf("id should be string, got %T", chunk["id"])
|
|
}
|
|
if _, exists := chunk["questions"]; exists {
|
|
t.Fatal("questions should be removed")
|
|
}
|
|
if _, exists := chunk["keywords"]; exists {
|
|
t.Fatal("keywords should be removed")
|
|
}
|
|
if _, exists := chunk["summary"]; exists {
|
|
t.Fatal("summary should be removed")
|
|
}
|
|
if meta["author"] != "Alice" {
|
|
t.Fatalf("metadata merge failed: %v", meta)
|
|
}
|
|
}
|