search

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const BatchJobKind = "search.batch"

BatchJobKind identifies a persistent search sweep for every host surface.

View Source
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 PairKey added in v0.2.0

func PairKey(source, query string) string

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 BatchFailure struct {
	Source  string `json:"source"`
	Query   string `json:"query"`
	Error   string `json:"error"`
	Skipped bool   `json:"skipped,omitempty"`
}

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 BatchPair added in v0.2.0

type BatchPair struct {
	Source  string `json:"source"`
	Query   string `json:"query"`
	RawFile string `json:"rawFile"`
	Records int    `json:"records"`
}

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 Concept

type Concept struct {
	Name     string
	Terms    []string
	Synonyms []string
}

Concept is one Boolean search concept with expansion terms.

type ConceptInput

type ConceptInput struct {
	Name     string
	Terms    []string
	Synonyms []string
}

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

type FieldQuery struct {
	Field string
	Query string
}

FieldQuery stores a field-specific query fragment.

type QueryCoverage added in v0.2.0

type QueryCoverage struct {
	Query     string `json:"query"`
	NewUnique int    `json:"new_unique"`
	Complete  bool   `json:"complete"`
}

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

func (s Strategy) BooleanQuery() string

BooleanQuery renders concepts as OR groups joined by AND plus field-scoped clauses.

func (Strategy) ProvenanceMetadata

func (s Strategy) ProvenanceMetadata() map[string]string

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

type WatchedSchedule struct {
	Enabled  bool
	Interval string
}

WatchedSchedule stores optional watched-search refresh metadata.

Jump to

Keyboard shortcuts

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