Documentation
¶
Index ¶
- Constants
- func BatchJobProgress(state *BatchState) jobs.Progress
- func DedupePapers(papers []library.PaperRecord) []library.PaperRecord
- func LoadBatchResults(path string) ([]library.PaperRecord, error)
- func LoadCheckpointResults(path string, count *int) ([]library.PaperRecord, error)
- func PairKey(source, query string) string
- func PendingPairs(state *BatchState, queries, sources []string, ...) int
- func RetryBatch(ctx context.Context, s *BatchState, prior []library.PaperRecord, ...) (int, error)
- func RunBatch(ctx context.Context, state *BatchState, prior []library.PaperRecord, ...) (resumedPairs int, err error)
- func RunBatchJob(ctx context.Context, dir, id string, input BatchJobInput, resume bool, ...) (jobs.Job, error)
- func WriteBatchState(dir string, state BatchState) error
- type BatchFailure
- type BatchHooks
- type BatchJobInput
- type BatchPair
- type BatchProgress
- type BatchState
- type Concept
- type ConceptInput
- type Coverage
- type FieldQuery
- type QueryCoverage
- type SearchBudget
- type Strategy
- type StrategyInput
- type WatchedSchedule
Constants ¶
const BatchJobKind = "search.batch"
BatchJobKind identifies a persistent search sweep for every host surface.
const BatchStateFile = "batch-state.json"
Variables ¶
This section is empty.
Functions ¶
func BatchJobProgress ¶ added in v0.2.0
func BatchJobProgress(state *BatchState) jobs.Progress
BatchJobProgress counts committed pairs in the active worklist, not stale pairs retained from an earlier search with different queries or sources.
func DedupePapers ¶ added in v0.2.0
func DedupePapers(papers []library.PaperRecord) []library.PaperRecord
DedupePapers is the same DOI/title identity policy used by aggregate output and marginal yield, so duplicate source hits never inflate coverage.
func LoadBatchResults ¶ added in v0.2.0
func LoadBatchResults(path string) ([]library.PaperRecord, error)
func LoadCheckpointResults ¶ added in v0.2.0
func LoadCheckpointResults(path string, count *int) ([]library.PaperRecord, error)
LoadCheckpointResults ignores any uncommitted (even torn) trailing append.
func PendingPairs ¶ added in v0.2.0
func PendingPairs(state *BatchState, queries, sources []string, configurationErrors map[string]string) int
func RetryBatch ¶ added in v0.2.0
func RetryBatch(ctx context.Context, s *BatchState, prior []library.PaperRecord, pending []BatchFailure, h BatchHooks) (int, error)
RetryBatch retries only the supplied failures through the same budgeted service as a full sweep. Other pending pairs remain for batch --resume.
func RunBatch ¶ added in v0.2.0
func RunBatch(ctx context.Context, state *BatchState, prior []library.PaperRecord, configurationErrors map[string]string, continueOnError bool, h BatchHooks) (resumedPairs int, err error)
RunBatch executes a budgeted sweep. Hooks persist artifacts; Completed must durably append results before returning their raw-file path. Checkpoint then commits that result prefix with pair identity and coverage. Supply a budget from DepthBudget and load prior records with LoadCheckpointResults on resume.
func RunBatchJob ¶ added in v0.2.0
func RunBatchJob(ctx context.Context, dir, id string, input BatchJobInput, resume bool, handler func(context.Context, *jobs.Run, BatchJobInput, bool) error) (jobs.Job, error)
RunBatchJob owns registration, lease and resume identity for every host. With an ID it restores saved inputs; without one it starts a request (or extends a checkpoint if resume is true). The adapter's handler publishes the artifacts and calls RunBatch with the supplied lease before returning.
func WriteBatchState ¶ added in v0.2.0
func WriteBatchState(dir string, state BatchState) error
Types ¶
type BatchFailure ¶ added in v0.2.0
type BatchHooks ¶ added in v0.2.0
type BatchHooks struct {
// Job attaches durable progress to the same lease used by CLI and MCP hosts.
Job *jobs.Run
Search func(context.Context, string, string) ([]library.PaperRecord, error)
Checkpoint func() error
Completed func(source, query string, queryIndex int, papers []library.PaperRecord) (rawFile string, err error)
Failed func(source, query string, err error) error
// contains filtered or unexported fields
}
BatchHooks keep output transactions and rendering in callers, while the service owns dispatch, resume, deduplication, coverage and stopping policy.
type BatchJobInput ¶ added in v0.2.0
type BatchJobInput struct {
// ResumeFrom identifies the checkpoint deliberately inherited at creation.
// Nil means a fresh job even if older artifacts still exist. A pointer to
// an empty ID denotes a legacy checkpoint that predates persistent jobs.
ResumeFrom *string `json:"resume_from,omitempty"`
Queries []string `json:"queries"`
Sources []string `json:"sources"`
Limit int `json:"limit"`
Depth string `json:"depth,omitempty"`
MaxRequests int `json:"max_requests,omitempty"`
ContinueOnError bool `json:"continue_on_error"`
WriteStats bool `json:"write_stats"`
FetchPDFs bool `json:"fetch_pdfs"`
Project string `json:"project,omitempty"`
}
BatchJobInput saves resolved inputs rather than references to mutable query files. Credentials and connector endpoints remain in host configuration. The artifact options are shared with adapters so resumption also republishes the original outputs and project import, not just the network worklist.
type BatchProgress ¶ added in v0.2.0
type BatchProgress struct {
Budget SearchBudget `json:"budget"`
StopReason sources.StopReason `json:"stop_reason"`
RequestsUsed int `json:"requests_used"`
Coverage Coverage `json:"coverage"`
ConsecutiveErrors int `json:"consecutive_errors"`
}
type BatchState ¶ added in v0.2.0
type BatchState struct {
JobID string `json:"job_id,omitempty"`
SchemaVersion string `json:"schemaVersion"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
Queries []string `json:"queries"`
Sources []string `json:"sources"`
Limit int `json:"limit"`
Completed []BatchPair `json:"completed,omitempty"`
Failures []BatchFailure `json:"failures,omitempty"`
Interrupted bool `json:"interrupted,omitempty"`
// ResultCount bounds the committed prefix of results.jsonl. A nil value
// identifies legacy checkpoints, whose entire result file is retained.
ResultCount *int `json:"result_count,omitempty"`
BatchProgress
}
BatchState is the durable checkpoint shared by CLI and service consumers. RequestsUsed is persisted before dispatch, so interrupted calls consume budget.
func ReadBatchState ¶ added in v0.2.0
func ReadBatchState(dir string) (BatchState, bool, error)
func (*BatchState) ClearFailure ¶ added in v0.2.0
func (s *BatchState) ClearFailure(source, query string)
func (*BatchState) HasCompleted ¶ added in v0.2.0
func (s *BatchState) HasCompleted(source, query string) bool
func (*BatchState) RecordCompleted ¶ added in v0.2.0
func (s *BatchState) RecordCompleted(p BatchPair)
func (*BatchState) RecordFailure ¶ added in v0.2.0
func (s *BatchState) RecordFailure(f BatchFailure)
func (*BatchState) Resume ¶ added in v0.2.0
func (s *BatchState) Resume(queries, sources []string, limit int)
Resume retains cumulative usage, coverage and unattempted failures. Old checkpoints infer a minimum usage from their attempted pairs.
type ConceptInput ¶
ConceptInput is caller-provided concept metadata before normalization.
type Coverage ¶ added in v0.2.0
type Coverage struct {
UniqueRecords int `json:"unique_records"`
Queries []QueryCoverage `json:"queries"`
ConsecutiveLowYield int `json:"consecutive_low_yield"`
}
type FieldQuery ¶
FieldQuery stores a field-specific query fragment.
type QueryCoverage ¶ added in v0.2.0
type SearchBudget ¶ added in v0.2.0
type SearchBudget struct {
Depth string `json:"depth"`
MaxQueryVariants int `json:"max_query_variants"`
MaxSources int `json:"max_sources"`
MaxAPICalls int `json:"max_api_calls"`
LowYieldThreshold int `json:"low_yield_threshold"`
SaturationQueries int `json:"saturation_queries"`
MaxConsecutiveErrors int `json:"max_consecutive_errors"`
}
SearchBudget uses MaxAPICalls like sources.GraphExpansionBudget. One unit is one connector Search invocation, including a failure or interrupted attempt.
func DepthBudget ¶ added in v0.2.0
func DepthBudget(depth string) (SearchBudget, error)
type Strategy ¶
type Strategy struct {
SchemaVersion string
ID string
Title string
Concepts []Concept
Fields []FieldQuery
Schedule WatchedSchedule
}
Strategy is a saved, versioned scholarly search strategy.
func NewStrategy ¶
func NewStrategy(input StrategyInput) (Strategy, error)
NewStrategy validates and normalizes a saved search strategy.
func (Strategy) BooleanQuery ¶
BooleanQuery renders concepts as OR groups joined by AND plus field-scoped clauses.
func (Strategy) ProvenanceMetadata ¶
ProvenanceMetadata returns stable metadata for provenance events that reference this strategy.
type StrategyInput ¶
type StrategyInput struct {
ID string
Title string
Concepts []ConceptInput
Fields []FieldQuery
Schedule WatchedSchedule
}
StrategyInput is caller-provided search strategy metadata before normalization.
type WatchedSchedule ¶
WatchedSchedule stores optional watched-search refresh metadata.