Files
ragflow/internal/ingestion/component/knowledge_compiler/common/batch.go
Zhichang Yu 90f46b0b4d Go port: doc-level metadata extraction and knowledge compiler (#17536)
Ports doc-level auto-metadata extraction to Go and adds the
knowledge_compiler component with scheduler/routing. Fixes Extractor
metadata injection type assertion and enable_metadata default-on.
2026-07-29 21:06:48 +08:00

24 lines
743 B
Go

package common
import "context"
// BatchHandler processes one batch of chunks. Returning an error aborts the
// pipeline (RunChunkedPipeline propagates it).
type BatchHandler func(ctx context.Context, batch []Chunk) error
// RunChunkedPipeline packs chunks into token-budgeted batches and invokes h for
// each, in order, honouring ctx cancellation. It is the Go equivalent of
// Python's run_chunked_pipeline engine step.
func RunChunkedPipeline(ctx context.Context, chunks []Chunk, maxTokens int, tok Tokenizer, h BatchHandler) error {
batches := PackBatches(chunks, maxTokens, tok)
for _, b := range batches {
if err := ctx.Err(); err != nil {
return err
}
if err := h(ctx, b); err != nil {
return err
}
}
return nil
}