semanticbuild

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 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 (
	MaxEmbeddingBatchSize          = 5_000
	MaxConsecutiveProviderFailures = 3
	DefaultRetryInitialBackoff     = time.Second
	DefaultRetryMaxBackoff         = 30 * time.Second
)

Variables

View Source
var ErrEmbedCircuitOpen = errors.New("semantic embedding circuit opened after three consecutive retryable provider failures")

Functions

func Profile

func Profile(info embedding.Info) embedding.Profile

Types

type ChunkOptions

type ChunkOptions struct {
	Limit int
	// Deprecated: nonblank source cursors are rejected because the durable dirty
	// ledger provides the resume position.
	AfterSourceKey string
	Progress       func(ChunkProgress) error
	MaxDuration    time.Duration
	UntilIdle      bool
	Now            func() time.Time
	// contains filtered or unexported fields
}

type ChunkProgress

type ChunkProgress struct {
	Progress
	Created int `json:"created"`
	Updated int `json:"updated"`
	Deleted int `json:"deleted"`
	// Deprecated: the durable dirty ledger resumes automatically.
	NextAfterSourceKey string                               `json:"next_after_source_key,omitempty"`
	HasMore            bool                                 `json:"has_more"`
	Checkpoint         *store.RetrievalProjectionCheckpoint `json:"checkpoint,omitempty"`
}

func RunChunk

func RunChunk(ctx context.Context, st ChunkStore, opts ChunkOptions) (ChunkProgress, error)

func RunProjectionBatch

func RunProjectionBatch(ctx context.Context, st ChunkStore, opts ProjectionBatchOptions) (ChunkProgress, error)

RunProjectionBatch performs exactly one page of projection work at the caller-supplied watermark. It never reads or advances ProjectionWorkRevision.

type ChunkStore

type ChunkStore interface {
	ProjectionWorkRevision(context.Context) (int64, error)
	RetrievalPurgeEpoch(context.Context) (int64, error)
	ListDirtyRetrievalParents(context.Context, int64, int) ([]store.RetrievalParentWork, error)
	ApplyRetrievalProjection(context.Context, store.ApplyRetrievalProjectionInput) (store.ChunkReplaceResult, error)
	LoadRetrievalProjectionStaging(context.Context, retrievalchunk.Parent, int64) (store.RetrievalProjectionCheckpoint, bool, error)
	StageRetrievalProjectionBatch(context.Context, store.StageRetrievalProjectionInput) (store.RetrievalProjectionCheckpoint, error)
	PromoteRetrievalProjectionStaging(context.Context, store.RetrievalProjectionCheckpoint) (store.ChunkReplaceResult, error)
	BlockRetrievalProjectionTooLarge(context.Context, retrievalchunk.Parent, int64, string, int64) error
}

type CompactionOptions

type CompactionOptions struct {
	Profile                                           embedding.Profile
	Backend, BackendVersion, DistanceMetric, CacheDir string
}

CompactionOptions identifies the immutable embedding profile and derived backend provenance for one replacement-root attempt.

type CompactionResult

type CompactionResult struct {
	Plan                         SegmentCompactionPlan
	GenerationID                 string
	ReplacementSegmentHashes     []string
	Indexed, StreamedLiveMembers int
}

CompactionResult records the pure selection outcome. Later fields are added only after payload/root publication succeeds.

func Compact

Compact is the entrypoint for bounded physical compaction. The initial implementation establishes the injected, non-serving selection boundary; it never falls back to a whole-corpus scan.

type CompactionStore

type CompactionStore interface {
	RetrievalDatabaseID(context.Context) (string, error)
	RetrievalActiveSegmentCompactionSnapshot(context.Context, string) (store.RetrievalActiveSegmentCompactionSnapshot, error)
	StreamRetrievalActiveSegmentMembers(context.Context, store.RetrievalActiveSegmentMemberStreamRequest, store.RetrievalActiveSegmentMemberVisitor) (int, error)
	RetrievalIndexGenerationSegments(context.Context, string) ([]store.RetrievalIndexSegmentRow, error)
	CompleteRetrievalIndexGeneration(context.Context, store.CompleteRetrievalIndexGenerationInput) error
}

CompactionStore is the non-serving persistence boundary for one bounded physical compaction. The executor will use only the selected snapshot rows and existing generation activation CAS.

type EmbedBatchOptions

type EmbedBatchOptions struct {
	BatchSize           int
	RetryCooldown       time.Duration
	RetryInitialBackoff time.Duration
	RetryMaxBackoff     time.Duration
	Now                 func() time.Time
	Sleep               func(context.Context, time.Duration) error
	BeforeProvider      func(context.Context, int) error
}

type EmbedBatchResult

type EmbedBatchResult struct {
	Progress
	Revision int64 `json:"revision"`
	HasMore  bool  `json:"has_more"`
}

func RunEmbedBatch

func RunEmbedBatch(ctx context.Context, st EmbedStore, provider embedding.Provider, opts EmbedBatchOptions) (EmbedBatchResult, error)

type EmbedOptions

type EmbedOptions struct {
	Limit         int
	BatchSize     int
	RetryCooldown time.Duration
	UntilIdle     bool
	MaxDuration   time.Duration
	Now           func() time.Time
	Clock         func() time.Time
	Progress      func(Progress) error
	// contains filtered or unexported fields
}

type EmbedStore

type EmbedStore interface {
	ListChunksNeedingEmbeddingForProfileAt(context.Context, embedding.Profile, string, int, time.Time) ([]store.RetrievalChunkRow, error)
	CountChunksNeedingEmbeddingForProfileAt(context.Context, embedding.Profile, time.Time) (int, error)
	RetrievalPurgeEpoch(context.Context) (int64, error)
	RetrievalEmbeddingProfile(context.Context, string) (store.RetrievalEmbeddingProfileRow, error)
	PutRetrievalEmbeddingBatch(context.Context, store.PutRetrievalEmbeddingBatchInput) (int64, error)
}

type FlushOptions

type FlushOptions struct {
	Profile                                           embedding.Profile
	Backend, BackendVersion, DistanceMetric, CacheDir string
	Limit                                             int
}

type FlushResult

type FlushResult struct {
	GenerationID, SegmentHash string
	Indexed, Flushed, L0Ready int
	SnapshotRevision          int64
}

func Flush

Flush creates exactly one immutable segment from the oldest revision-prefix of the L0 tail. The caller supplies an opaque backend payload builder; this package never selects or links a native backend itself.

type FlushStore

type FlushStore interface {
	RetrievalDatabaseID(context.Context) (string, error)
	NextRetrievalFlushWindow(context.Context, string, int) (store.RetrievalFlushWindow, error)
	RetrievalIndexGenerationSegments(context.Context, string) ([]store.RetrievalIndexSegmentRow, error)
	CompleteRetrievalIndexGeneration(context.Context, store.CompleteRetrievalIndexGenerationInput) error
}

type Progress

type Progress struct {
	Stage              string     `json:"stage"`
	Interrupted        bool       `json:"interrupted"`
	Scanned            int        `json:"scanned"`
	Current            int        `json:"current"`
	Generated          int        `json:"generated"`
	Quarantined        int        `json:"quarantined"`
	Blocked            int        `json:"blocked"`
	Failed             int        `json:"failed"`
	Remaining          int        `json:"remaining"`
	SnapshotCount      int        `json:"snapshot_count"`
	SnapshotsTruncated bool       `json:"snapshots_truncated"`
	LastSnapshot       *Progress  `json:"last_snapshot,omitempty"`
	Snapshots          []Progress `json:"-"`
}

func RunEmbed

func RunEmbed(ctx context.Context, st EmbedStore, provider embedding.Provider, opts EmbedOptions) (Progress, error)

type ProjectionBatchOptions

type ProjectionBatchOptions struct {
	Watermark          int64
	ExpectedPurgeEpoch int64
	Limit              int
	Progress           func(ChunkProgress) error
	Now                func() time.Time
}

ProjectionBatchOptions selects one bounded projection page from an immutable caller-owned work watermark. It deliberately cannot allocate a watermark: refresh runs allocate successor watermarks after their pinned work is idle.

type SegmentCompactionClass

type SegmentCompactionClass string
const (
	SegmentCompactionClassExactL0 SegmentCompactionClass = "exact_l0"
	SegmentCompactionClass5K      SegmentCompactionClass = "5k"
	SegmentCompactionClass10K     SegmentCompactionClass = "10k"
	SegmentCompactionClass20K     SegmentCompactionClass = "20k"
	SegmentCompactionClass40K     SegmentCompactionClass = "40k"
	SegmentCompactionClass80K     SegmentCompactionClass = "80k"
	SegmentCompactionClassCapped  SegmentCompactionClass = "capped"
	SegmentCompactionClassInvalid SegmentCompactionClass = "invalid"
)

func ClassifySegmentCompactionCount

func ClassifySegmentCompactionCount(live int) SegmentCompactionClass

ClassifySegmentCompactionCount maps an already-filtered live membership count to its storage tier. Counts below the minimum belong in exact L0; a physical ANN segment never exceeds the capped upper bound.

type SegmentCompactionInput

type SegmentCompactionInput struct {
	SegmentHash               string
	CreatedOrder              int64
	LiveCount, TombstoneCount int
}

type SegmentCompactionKind

type SegmentCompactionKind string
const (
	SegmentCompactionNone      SegmentCompactionKind = "none"
	SegmentCompactionSingleton SegmentCompactionKind = "singleton"
	SegmentCompactionPair      SegmentCompactionKind = "pair"
)

type SegmentCompactionOutput

type SegmentCompactionOutput struct {
	LiveCount int
	Class     SegmentCompactionClass
}

type SegmentCompactionPlan

type SegmentCompactionPlan struct {
	Kind    SegmentCompactionKind
	Inputs  []SegmentCompactionInput
	Outputs []SegmentCompactionOutput
}

func PlanSegmentCompaction

func PlanSegmentCompaction(inputs []SegmentCompactionInput) (SegmentCompactionPlan, error)

PlanSegmentCompaction chooses one bounded maintenance action from immutable segment facts. It deliberately does not inspect vectors, SQLite membership, or cache paths; later orchestration must revalidate this plan before writing.

type SegmentPayloadBuilder

type SegmentPayloadBuilder interface {
	Build(context.Context, []store.RetrievalEmbeddingRow) (func(io.Writer) error, error)
}

type Status

type Status struct {
	Status            string                     `json:"status"`
	Reason            string                     `json:"reason"`
	Searchable        bool                       `json:"searchable"`
	Mode              string                     `json:"mode"`
	ProfileID         string                     `json:"profile_id"`
	BackendCapability semanticindex.Capability   `json:"backend_capability"`
	Store             semanticreadiness.Snapshot `json:"store"`
	LatestRun         *store.SemanticRefreshRun  `json:"latest_run"`
	Problems          []string                   `json:"problems"`
	Next              []string                   `json:"next_steps"`
}

func ReadStatus

func ReadStatus(
	ctx context.Context,
	st StatusStore,
	profile embedding.Profile,
	configured bool,
	enabled bool,
	exactMaxChunks int,
	capability semanticindex.Capability,
	now time.Time,
) (Status, error)

func ReadStatusWithNativeValidation

func ReadStatusWithNativeValidation(
	ctx context.Context,
	st StatusStore,
	profile embedding.Profile,
	configured bool,
	enabled bool,
	exactMaxChunks int,
	capability semanticindex.Capability,
	now time.Time,
	validateNativeRoot func(context.Context, semanticreadiness.Snapshot) error,
) (Status, error)

ReadStatusWithNativeValidation reports status after optionally checking that an admitted native root can be opened by the runtime.

type StatusStore

type StatusStore interface {
	SemanticReadinessSnapshotAt(context.Context, embedding.Profile, int, time.Time) (semanticreadiness.Snapshot, error)
	LatestSemanticRefreshRun(context.Context, string) (*store.SemanticRefreshRun, error)
}

type StreamingSegmentPayloadBuilder

type StreamingSegmentPayloadBuilder interface {
	Begin(context.Context, int) (StreamingSegmentPayloadSession, error)
}

StreamingSegmentPayloadBuilder creates a bounded session that accepts source embeddings one at a time. It is separate from SegmentPayloadBuilder so the established flush contract remains stable while compaction can avoid materializing its full source-row slice.

type StreamingSegmentPayloadSession

type StreamingSegmentPayloadSession interface {
	Add(context.Context, store.RetrievalEmbeddingRow) error
	Finish(context.Context) (func(io.Writer) error, error)
	Close() error
}

StreamingSegmentPayloadSession accepts exactly the count declared at Begin. Finish returns a self-contained opaque payload writer and releases any native state; Close is idempotent and releases a session abandoned before Finish.

type VerifyOptions

type VerifyOptions struct {
	Profile        embedding.Profile
	Limit          int
	Resume         string
	RepairCounters bool
	Progress       func(VerifyProgress) error
}

type VerifyProgress

type VerifyProgress struct {
	Progress
	Resume           string `json:"resume,omitempty"`
	HasMore          bool   `json:"has_more"`
	CountersRepaired bool   `json:"counters_repaired"`
}

func RunVerify

func RunVerify(ctx context.Context, st VerifyStore, opts VerifyOptions) (VerifyProgress, error)

type VerifyStore

type VerifyStore interface {
	RepairRetrievalRuntimeReadinessCounters(context.Context) error
	RetrievalEmbeddingVerificationState(context.Context, string) (store.RetrievalEmbeddingVerificationState, error)
	ListRetrievalVectors(context.Context, string, store.VectorPage) ([]store.RetrievalVectorRow, error)
	BlockCorruptRetrievalEmbedding(context.Context, *store.RetrievalEmbeddingCorruptionError) error
}

Jump to

Keyboard shortcuts

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