semanticrefresh

package
v0.8.18 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 17 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 (
	ErrorBackendBroken    = "semantic_backend_broken"
	ErrorRunConflict      = "semantic_run_conflict"
	ErrorProjection       = "semantic_projection_failed"
	ErrorEmbedding        = "semantic_embedding_failed"
	ErrorEmbeddingCircuit = "semantic_embedding_circuit_open"
	ErrorFlush            = "semantic_flush_failed"
	ErrorCompaction       = "semantic_compaction_failed"
	ErrorVerify           = "semantic_verify_failed"
	ErrorNativeRoot       = "semantic_native_root_failed"
	ErrorReadiness        = "semantic_readiness_not_ready"
	ErrorLockUnavailable  = "semantic_lock_unavailable"
	ErrorCancelled        = "semantic_refresh_cancelled"
)
View Source
const (
	DefaultProjectionBatch = 100
	DefaultEmbeddingBatch  = 16
)
View Source
const ProgressInterval = 5 * time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type Debt

type Debt struct {
	DirtyParents      int `json:"dirty_parents"`
	PendingEmbeddings int `json:"pending_embeddings"`
	DueRetries        int `json:"due_retries"`
	ScheduledRetries  int `json:"scheduled_retries"`
	BlockedEmbeddings int `json:"blocked_embeddings"`
	FailedEmbeddings  int `json:"failed_embeddings"`
	Indexed           int `json:"indexed"`
	L0Ready           int `json:"l0_ready"`
	Tombstones        int `json:"tombstones"`
	Segments          int `json:"segments"`
}

type Outcome

type Outcome string
const (
	OutcomeSkipped   Outcome = "skipped"
	OutcomeCompleted Outcome = "completed"
)

type PipelineOptions

type PipelineOptions struct {
	Profile         embedding.Profile
	Provider        embedding.Provider
	Native          NativeLifecycle
	CacheDir        string
	ExactMaxChunks  int
	ProjectionBatch int
	EmbeddingBatch  int
	Now             func() time.Time
	Sleep           func(context.Context, time.Duration) error
}

type PipelineStore

type PipelineStore interface {
	semanticbuild.ChunkStore
	semanticbuild.EmbedStore
	semanticbuild.FlushStore
	semanticbuild.CompactionStore
	semanticbuild.VerifyStore
	ProjectionWorkRevision(context.Context) (int64, error)
	RetrievalPurgeEpoch(context.Context) (int64, error)
	RetrievalDatabaseID(context.Context) (string, error)
	CountDirtyRetrievalParents(context.Context, int64) (int, error)
	CountRetrievalVectorsAfter(context.Context, string, string) (int, error)
	RetrievalEmbeddingProfile(context.Context, string) (store.RetrievalEmbeddingProfileRow, error)
	RetrievalDanglingGenerationRecovery(context.Context, string) (*store.RetrievalDanglingGenerationRecovery, error)
	ReactivateRetrievalDanglingGeneration(context.Context, store.RetrievalDanglingGenerationRecovery) error
	SemanticReadinessSnapshotAt(context.Context, embedding.Profile, int, time.Time) (semanticreadiness.Snapshot, error)
}

type Progress

type Progress struct {
	RunID, ProfileID, Checkpoint, Readiness string
	Stage                                   store.SemanticRefreshStage
	Counters                                store.SemanticRefreshCounters
	Debt                                    Debt
	Work                                    StageWork
	At                                      time.Time
}

type ProgressCallback

type ProgressCallback func(Progress) error

type ProgressEmitter

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

ProgressEmitter serializes visible callbacks and coalesces durable heartbeat writes for one running refresh run. Callers must pass only rows returned by a completed ledger update to Publish.

func StartProgressEmitter

func StartProgressEmitter(
	ctx context.Context,
	ledger ProgressLedger,
	run store.SemanticRefreshRun,
	debt Debt,
	callback ProgressCallback,
) (*ProgressEmitter, error)

StartProgressEmitter durably emits the initial running snapshot before it starts the five-second heartbeat loop.

func (*ProgressEmitter) Context

func (e *ProgressEmitter) Context() context.Context

Context returns the derived work context cancelled by a progress ledger or callback failure.

func (*ProgressEmitter) Publish

func (e *ProgressEmitter) Publish(run store.SemanticRefreshRun, debt Debt) error

Publish queues a checkpoint row only after the caller has durably persisted it. Heartbeats after this call reuse that exact snapshot. A Publish invoked while a callback is active is accepted asynchronously so callback-to-Publish reentrancy can unwind before the queued callback is dispatched.

func (*ProgressEmitter) PublishWork added in v0.8.9

func (e *ProgressEmitter) PublishWork(work StageWork) error

PublishWork serializes a transient stage-local measurement against the most recent persisted run and debt snapshot. The measurement is retained for heartbeats but is never written into the refresh run ledger.

func (*ProgressEmitter) Stop

func (e *ProgressEmitter) Stop() error

Stop prevents new ticks and checkpoint events and cancels derived work. Outside an active callback it joins the dispatcher before returning. A Stop observed while a callback is active requests stop and returns without joining so callback-to-Stop reentrancy cannot self-join; a later Stop is idempotent and joins after that callback unwinds.

type ProgressLedger

type ProgressLedger interface {
	TouchSemanticRefreshRunProgress(context.Context, string, time.Time) error
}

type RefreshError

type RefreshError struct {
	Code       string                     `json:"code"`
	Stage      store.SemanticRefreshStage `json:"stage,omitempty"`
	RunID      string                     `json:"run_id,omitempty"`
	Checkpoint string                     `json:"checkpoint,omitempty"`
	Readiness  string                     `json:"readiness,omitempty"`
	Debt       Debt                       `json:"remaining_debt"`
	Message    string                     `json:"message"`
	// contains filtered or unexported fields
}

func NewError

func NewError(
	code string,
	run store.SemanticRefreshRun,
	readiness string,
	debt Debt,
	cause error,
) *RefreshError

func (*RefreshError) Error

func (e *RefreshError) Error() string

func (*RefreshError) MarshalJSON

func (e *RefreshError) MarshalJSON() ([]byte, error)

func (*RefreshError) Unwrap

func (e *RefreshError) Unwrap() error

type Request

type Request struct {
	ProfileID                       string
	PurgeEpoch, ProjectionWatermark int64
	Capability                      semanticindex.Capability
	Progress                        ProgressCallback
	Now                             func() time.Time
	NewRunIDFunc                    func() (string, error)
}

func (Request) Validate

func (r Request) Validate() error

type Result

type Result struct {
	Outcome     Outcome                   `json:"outcome"`
	SkipReason  string                    `json:"skip_reason,omitempty"`
	Capability  semanticindex.Capability  `json:"capability"`
	Run         *store.SemanticRefreshRun `json:"run,omitempty"`
	Debt        Debt                      `json:"remaining_debt"`
	StartedAt   time.Time                 `json:"started_at"`
	CompletedAt time.Time                 `json:"completed_at"`
	Duration    time.Duration             `json:"duration"`
	Stages      []StageStats              `json:"stages"`
}

func Run

func Run(
	ctx context.Context,
	ledger RunLedger,
	executor StageExecutor,
	request Request,
) (Result, error)

Run executes one bounded semantic refresh stage at a time and durably checkpoints every stage boundary before advancing.

type RootExpectation

type RootExpectation struct {
	CacheDir, DatabaseID, ProfileID, GenerationID string
	DescriptorSHA256                              string
	SnapshotRevision, PurgeEpoch                  int64
	Dimensions                                    int
	BackendVersion                                string
}

type RunLedger

type RunLedger interface {
	StartOrResumeSemanticRefreshRun(
		context.Context,
		store.StartSemanticRefreshRunInput,
	) (store.SemanticRefreshRun, bool, error)
	UpdateSemanticRefreshRun(
		context.Context,
		store.SemanticRefreshRunUpdate,
	) (store.SemanticRefreshRun, error)
	TouchSemanticRefreshRunProgress(context.Context, string, time.Time) error
}

type StageExecutor

type StageExecutor interface {
	Execute(context.Context, store.SemanticRefreshRun, StageProgressCallback) (StageOutcome, error)
}

func NewLockedPipeline

func NewLockedPipeline(executor StageExecutor, scope *semanticlock.Scope) (StageExecutor, error)

NewLockedPipeline wraps one semantic stage executor so each Execute call owns one exclusive maintenance lease. Publication stages also own generation exclusively, in the required maintenance-before-generation order.

func NewPipeline

func NewPipeline(st PipelineStore, options PipelineOptions) (StageExecutor, error)

type StageOutcome

type StageOutcome struct {
	NextStage           store.SemanticRefreshStage
	Checkpoint          string
	EmbeddingRevision   int64
	Counters            store.SemanticRefreshCounters
	CurrentGenerationID string
	Readiness           string
	Debt                Debt
	Complete            bool
	SuccessorWatermark  *int64
}

type StageProgressCallback added in v0.8.9

type StageProgressCallback func(StageWork) error

type StageStats added in v0.8.8

type StageStats struct {
	Stage         store.SemanticRefreshStage    `json:"stage"`
	Duration      time.Duration                 `json:"duration"`
	Units         int                           `json:"units"`
	Status        string                        `json:"status"`
	RunIDs        []string                      `json:"run_ids"`
	Counters      store.SemanticRefreshCounters `json:"counters"`
	RemainingDebt Debt                          `json:"remaining_debt"`
	ErrorCode     string                        `json:"error_code,omitempty"`
}

type StageWork added in v0.8.9

type StageWork struct {
	Current    int64 `json:"current"`
	Total      int64 `json:"total"`
	TotalKnown bool  `json:"total_known"`
	Pass       int   `json:"pass"`
}

StageWork is a transient, stage-local measurement for interactive progress. It is deliberately separate from the durable semantic refresh counters.

func (StageWork) Validate added in v0.8.9

func (w StageWork) Validate() error

Jump to

Keyboard shortcuts

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