pipeline

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package pipeline provides the experimental portable document parsing runtime.

Runtime owns deterministic orchestration, extraction policies, diagnostics, caching and artifact formatting. Hosts explicitly provide document loading, section splitting and model execution; the package never discovers provider credentials, product configuration or concrete backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectChaptersPriority

func DetectChaptersPriority(ctx context.Context, model Model, pages []string, modelName string, spec *configs.DocSpec, opt *DetectOptions) (map[string][]int, error)

DetectChaptersPriority uses priority groups and bounded parallel batches to identify 1-based chapter pages with an explicitly supplied model adapter.

Types

type ArtifactPolicy

type ArtifactPolicy string
const (
	ArtifactPolicyDefault ArtifactPolicy = ""
	ArtifactPolicyFull    ArtifactPolicy = "full"
	ArtifactPolicySummary ArtifactPolicy = "summary"
	ArtifactPolicyNone    ArtifactPolicy = "none"
)

type Dependencies

type Dependencies struct {
	Loader    DocumentLoader
	Sectioner Sectioner
	Model     Model
	Observer  Observer
}

Dependencies are the explicit construction seam for the document Runtime.

type DetectOptions

type DetectOptions struct {
	// Groups 按优先级分组的章节 key 列表,groups[0] 为最高优先级。
	// 若为空,将根据常见年报章节推导一个默认分组,并把未出现的章节置于最后一组。
	Groups [][]string

	// HeaderLines 页眉行数(默认使用 spec.Meta.HeaderLines)
	HeaderLines int
	// LineClip 每行最大字符数(默认 120)
	LineClip int
	// BatchPages 每个批次包含的页数(默认 100)
	BatchPages int
	// MaxConcurrent 最大并发批次数(默认 3)
	MaxConcurrent int

	// RetryOptions LLM 重试参数(为空则使用章节识别的默认:90s/1次重试/3m总时长)
	RetryOptions *RetryOptions
}

DetectOptions 控制优先级分组与并发等参数

type DocumentExtractionMode

type DocumentExtractionMode string

DocumentExtractionMode controls the preferred source order used by the host document loader.

const (
	DocumentExtractionModeDefault        DocumentExtractionMode = ""
	DocumentExtractionModeLegacy         DocumentExtractionMode = "legacy"
	DocumentExtractionModeTableFirst     DocumentExtractionMode = "table_first"
	DocumentExtractionModeTextLayerFirst DocumentExtractionMode = "text_layer_first"
	DocumentExtractionModeOCRFirst       DocumentExtractionMode = "ocr_first"
	DocumentExtractionModeAuto           DocumentExtractionMode = "auto"
)

func NormalizeDocumentExtractionMode

func NormalizeDocumentExtractionMode(raw string) (DocumentExtractionMode, error)

NormalizeDocumentExtractionMode normalizes documented aliases without selecting a concrete extractor.

type DocumentLoader

type DocumentLoader interface {
	Extract(context.Context, ExtractRequest) (*ExtractedDocument, error)
}

DocumentLoader supplies file decoding, OCR selection and concrete PDF access.

type DocumentLoaderFunc

type DocumentLoaderFunc func(context.Context, ExtractRequest) (*ExtractedDocument, error)

DocumentLoaderFunc adapts a function to DocumentLoader.

func (DocumentLoaderFunc) Extract

type ExtractRequest

type ExtractRequest struct {
	Path           string
	PageLimit      int
	PDFParseMode   PDFParseMode
	ExtractionMode DocumentExtractionMode
}

ExtractRequest describes a host-owned document extraction operation.

type ExtractedDocument

type ExtractedDocument struct {
	Pages       []string
	TextSource  string
	PDFResponse *pdfparser.TableResponse
}

ExtractedDocument is the substrate-neutral result consumed by Runtime.

type Model

type Model interface {
	Complete(context.Context, ModelRequest) (string, error)
}

Model is the only model capability required by Runtime. Provider selection, credentials, authorization, networking and retry execution remain host-owned.

type ModelFunc

type ModelFunc func(context.Context, ModelRequest) (string, error)

ModelFunc adapts a function to Model.

func (ModelFunc) Complete

func (f ModelFunc) Complete(ctx context.Context, req ModelRequest) (string, error)

type ModelRequest

type ModelRequest struct {
	ModelName string
	Prompt    string
	Chunks    []string
	Retry     RetryOptions
}

ModelRequest is one text completion required by document coordination.

type Observer

type Observer interface {
	Observe(context.Context, StageEvent)
}

Observer receives optional runtime progress without controlling behavior.

type ObserverFunc

type ObserverFunc func(context.Context, StageEvent)

ObserverFunc adapts a function to Observer.

func (ObserverFunc) Observe

func (f ObserverFunc) Observe(ctx context.Context, event StageEvent)

type Options

type Options struct {
	ModelName      string
	OutputDir      string // Optional. Empty output dirs are allocated under the system temp directory.
	MaxChunkChars  int    // 默认 12000
	PDFParseMode   *PDFParseMode
	ExtractionMode *DocumentExtractionMode
	ArtifactPolicy ArtifactPolicy
}

type PDFParseMode

type PDFParseMode int

PDFParseMode controls the host document loader's PDF extraction strategy.

const (
	PDFParseSimple PDFParseMode = iota
	PDFParseNormal
	PDFParseForceOCR
)

type ParseBudget

type ParseBudget struct {
	TotalTimeout time.Duration
}

type ParseCacheOptions

type ParseCacheOptions struct {
	Policy ParseCachePolicy
	Dir    string
}

type ParseCachePolicy

type ParseCachePolicy string
const (
	ParseCachePolicyDefault   ParseCachePolicy = ""
	ParseCachePolicyNone      ParseCachePolicy = "none"
	ParseCachePolicyRead      ParseCachePolicy = "read"
	ParseCachePolicyWrite     ParseCachePolicy = "write"
	ParseCachePolicyReadWrite ParseCachePolicy = "read_write"
)

type ParseRequest

type ParseRequest struct {
	DocPath        string
	SpecPath       string
	ModelName      string
	OutputDir      string
	MaxChunkChars  int
	PageLimit      int
	PDFParseMode   *PDFParseMode
	ExtractionMode *DocumentExtractionMode
	ArtifactPolicy ArtifactPolicy
	Cache          ParseCacheOptions
	TraceMode      string
	Budget         ParseBudget
}

type RetryOptions

type RetryOptions struct {
	MaxRetries        int
	AttemptTimeout    time.Duration
	TotalTimeout      time.Duration
	BackoffBase       time.Duration
	BackoffMultiplier float64
	BackoffJitter     float64
}

RetryOptions communicates the legacy-compatible retry intent to a host model adapter. The portable pipeline never discovers providers or credentials and does not own network retry policy.

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime coordinates the portable document pipeline over host-provided I/O. It is safe for concurrent Run calls when the injected dependencies are safe.

func New

func New(deps Dependencies) (*Runtime, error)

New constructs a Runtime without discovering host configuration.

func (*Runtime) ParseDocument

func (r *Runtime) ParseDocument(docPath, specPath string, opts Options) (*types.DocumentResult, error)

ParseDocument preserves the concise legacy-shaped call on an explicitly constructed Runtime.

func (*Runtime) Run

Run executes the portable document pipeline with explicit host dependencies.

type SectionRequest

type SectionRequest struct {
	ConfigPath string
	Pages      []string
}

SectionRequest is the complete input to a host-provided section splitter.

type Sectioner

type Sectioner interface {
	Split(context.Context, SectionRequest) ([]*section.Node, error)
}

Sectioner owns the concrete section-rule backend while returning portable section trees to Runtime.

type SectionerFunc

type SectionerFunc func(context.Context, SectionRequest) ([]*section.Node, error)

SectionerFunc adapts a function to Sectioner.

func (SectionerFunc) Split

func (f SectionerFunc) Split(ctx context.Context, req SectionRequest) ([]*section.Node, error)

type StageEvent

type StageEvent struct {
	Stage  string
	Status string
	Detail string
}

StageEvent is a display-safe observation emitted at a major pipeline boundary.

Directories

Path Synopsis
internal
logging
Package logging contains intentionally silent logging hooks for deterministic document helpers.
Package logging contains intentionally silent logging hooks for deterministic document helpers.
Package section defines the substrate-neutral section tree exchanged between the document pipeline and a host-provided section splitter.
Package section defines the substrate-neutral section tree exchanged between the document pipeline and a host-provided section splitter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL