Files
ragflow/internal/ingestion/task/golden_compare.go
Jack b59d6e8ba1 refactor(ingestion/task): extract index-doc mapping into task/indexdoc package (#17749)
## Summary
Extract the pipeline-output → search-engine index document mapping
helpers out of the `task` package into a dedicated, dependency-light
leaf package `internal/ingestion/task/indexdoc`.

These functions are pure transforms (they only depend on
`common`/`utility`) and are not task-orchestration concerns:
- `NormalizeChunks`, `DeepCopyChunks` (was unexported `deepCopyChunks`),
`toChunkMaps` → `indexdoc/normalize.go`
- `ProcessChunksForPipeline`, `RenameTextToContentWithWeight`,
`GetEmbeddingTokenConsumption`, `cleanupConsumedChunkFields`,
`mergeChunkMetadata`, `processChunkPositions`,
`AggregateTableDocMetadata`, `resolveTableColumnConfig` →
`indexdoc/process.go`
- `AddPositions` → `indexdoc/position.go`
- `EmbeddingTokenConsumptionKey` constant → `indexdoc/constants.go`
(task/constants.go keeps only `GRAPH_RAPTOR_FAKE_DOC_ID`)

Call sites in `pipeline_executor.go` and `golden_compare.go` now
reference the `indexdoc` package; package-task tests qualify the moved
symbols.

## Why
The `task` package had grown into a "orchestration + pure mapping +
debug" mix. Splitting the pure mapping helpers into a leaf package
sharpens package boundaries, removes a misleading top-level
`ingestion/chunk` candidate (there are already `parser/chunk` and
`service/chunk`), and lets the golden tool / future reuse pull in the
mapping logic without dragging in `task`'s `dao`/`engine`/`service`
dependency graph (Go subpackage import does not pull in the parent).

## Test plan
- `build.sh --test ./internal/ingestion/task/...` — **green** (task
4.7s, indexdoc 0.007s), matching the pre-change baseline.
- `gofmt` clean; `build.sh` builds both `ragflow-cli` and
`ragflow_server` successfully.
- Integration/E2E tiers are delegated to CI (need real MySQL/MinIO/ES
services).

Note: `pipeline_e2e_test.go` has a **pre-existing** compile error
(`server.ElasticsearchConfig` / `server.InfinityConfig` are now defined
under `internal/server/config/`, not re-exported by `internal/server`).
This is unrelated to this change — the diff to that file is only the
added `indexdoc` import and the qualified `EmbeddingTokenConsumptionKey`
reference.
2026-08-04 10:05:27 +08:00

60 lines
1.8 KiB
Go

//
// 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
import (
"time"
indexdoc "ragflow/internal/ingestion/task/indexdoc"
)
// GoldenCompareResult is the structured output used by the local golden tools.
type GoldenCompareResult struct {
NormalizedChunks []map[string]any `json:"normalized_chunks"`
ProcessedChunks []map[string]any `json:"processed_chunks"`
MergedMetadata map[string]any `json:"merged_metadata"`
}
// ProcessPipelineOutputForGolden replays the deterministic pipeline post-processing
// steps from a pipeline.run()-style output without embedding or external writes.
func ProcessPipelineOutputForGolden(
pipelineOutput map[string]any,
docID string,
kbID string,
docName string,
) (GoldenCompareResult, error) {
normalized := indexdoc.NormalizeChunks(pipelineOutput)
if normalized == nil {
normalized = []map[string]any{}
}
processed := indexdoc.DeepCopyChunks(normalized)
metadata, err := indexdoc.ProcessChunksForPipeline(processed, docID, kbID, docName, time.Now())
if err != nil {
return GoldenCompareResult{}, err
}
if metadata == nil {
metadata = map[string]any{}
}
return GoldenCompareResult{
NormalizedChunks: normalized,
ProcessedChunks: processed,
MergedMetadata: metadata,
}, nil
}