retrievalchunk

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 13 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 (
	Version           = "retrieval-chunker-v3"
	ProjectionVersion = "retrieval-projection-v2"
	MaxUTF8Bytes      = 1800

	// V3ByteCeiling, V3MaximumOverlapUTF8Bytes, and
	// V3MinimumForwardUTF8Bytes are the published deterministic planning
	// bounds for chunker v3. Natural boundaries may be dense, so the only
	// guaranteed forward byte advance is one. Readiness therefore uses exact
	// capped v3 occurrence planning rather than a byte-ratio approximation.
	V3ByteCeiling                   = MaxUTF8Bytes
	V3MaximumOverlapUTF8Bytes       = 0
	V3MinimumForwardUTF8Bytes       = 1
	V3MaximumPlanningInputUTF8Bytes = 128 << 20
	// Bound section metadata independently from text bytes. Empty sections
	// still consume normalized-section and duplicate-key map entries.
	V3MaximumPlanningSections = 4_096
	// Exact capped readiness planning may allocate rune/anchor/window state
	// only below this normalized-input ceiling. The allocation-free preflight
	// still scans up to V3MaximumPlanningInputUTF8Bytes and proves ordinary
	// oversized content over budget; sparse giant input fails closed.
	V3MaximumExactPlanningInputUTF8Bytes = 8 << 20
)

Variables

This section is empty.

Functions

func CountOccurrencesCappedContext

func CountOccurrencesCappedContext(ctx context.Context, parent Parent, opts Options, limit int) (int, error)

CountOccurrencesCappedContext returns the exact chunker-v3 occurrence count when it is at most limit, and limit+1 as a stable over-budget sentinel. The preflight is deliberately only a proof of overage, never an estimator: v3 windows are a zero-overlap partition and every untrimmed window is at most MaxUTF8Bytes. Greedily covering every non-whitespace rune start with the furthest possible interval of that size is a lower bound on final emitted windows, regardless of natural anchors. This lets readiness reject giant parents without cloning the unread tail into []rune, anchor candidates, or prepared windows. Inputs not proven over budget use the ordinary exact planner so all counts through limit remain identical.

func IsRawSupportRole

func IsRawSupportRole(role string) bool

IsRawSupportRole reports whether a projected section contains source evidence rather than derived synthesis. OCR and transcript remain distinct roles so changing support classification does not change chunk identity provenance.

func ParentProjectionHash

func ParentProjectionHash(parent Parent) (string, error)

ParentProjectionHash returns the exact projection-v2 parent identity without materializing its chunks. It validates the same parent/section contract as Stream and BuildProjection.

func ParentProjectionHashContext

func ParentProjectionHashContext(ctx context.Context, parent Parent) (string, error)

ParentProjectionHashContext computes the same projection identity while bounding metadata and input scanning and honoring command cancellation. Hash construction is streaming, so it uses the 128 MiB command-planning ceiling rather than readiness's separate 8 MiB exact-window allocation ceiling.

func PreparedStreamPlanDigest

func PreparedStreamPlanDigest(encoded []byte) string

Types

type Chunk

type Chunk struct {
	ID                string
	ParentKind        string
	ParentSourceKey   string
	EvidenceRole      string
	SectionKey        string
	Ordinal           int
	SectionOrdinal    int
	StartChar         int
	EndChar           int
	Heading           string
	HeadingHash       string
	Derived           bool
	ProjectionVersion string
	ChunkerVersion    string
	InputContentHash  string
	TextHash          string
	Text              string
}

func Build

func Build(parent Parent, opts Options) ([]Chunk, error)

Build is retained for v1 callers until occurrence persistence lands. New callers must use BuildProjection so they do not mistake a content window for one parent-local location.

type Cursor

type Cursor struct {
	SectionKey   string
	NextBoundary int
}

Cursor is a durable v3 streaming position. SectionKey is the normalized, parent-bound section identity and NextBoundary is the next untrimmed rune boundary to emit within that section.

func Stream

func Stream(parent Parent, opts Options, cursor Cursor, emit func(Chunk, Occurrence) error) (Cursor, bool, error)

Stream emits v3 windows from cursor without retaining the complete projection. When emit returns an error, the returned cursor is positioned after the successfully delivered window so callers can durably checkpoint the batch before resuming.

func StreamPrepared

func StreamPrepared(parent Parent, opts Options, plan PreparedStreamPlan, cursor Cursor, emit func(Chunk, Occurrence) error) (Cursor, bool, error)

type Occurrence

type Occurrence struct {
	ChunkID    string
	SectionKey string
	StartChar  int
	EndChar    int
}

Occurrence records where a reusable content-local chunk occurs in one projected section. Offsets are rune offsets in the untrimmed Section.Text.

type Options

type Options struct {
	TargetRunes  int
	MaxRunes     int
	OverlapRunes int
}

func DefaultOptions

func DefaultOptions() Options

type Parent

type Parent struct {
	Kind        string
	SourceKey   string
	ContentHash string
	Title       string
	SourceType  string
	Author      string
	Sections    []Section
}

func ProjectItem

func ProjectItem(item model.Item) Parent

func ProjectSource

func ProjectSource(source model.SourceDocument) Parent

type PreparedStreamOccurrenceLimitError

type PreparedStreamOccurrenceLimitError struct {
	OccurrenceCount int
	Limit           int
}

func (*PreparedStreamOccurrenceLimitError) Error

type PreparedStreamPlan

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

func ParsePreparedStreamPlan

func ParsePreparedStreamPlan(parent Parent, opts Options, encoded []byte, maxOccurrences int) (PreparedStreamPlan, error)

func ParsePreparedStreamPlanContext

func ParsePreparedStreamPlanContext(ctx context.Context, parent Parent, opts Options, encoded []byte, maxOccurrences int) (PreparedStreamPlan, error)

ParsePreparedStreamPlanContext validates persisted seek state under the same section, input, occurrence, and cancellation bounds as fresh command planning. A checkpoint created by an older unbounded command cannot bypass the current v3 planner ceilings on resume.

func PrepareStream

func PrepareStream(parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)

PrepareStream computes the content-defined boundary plan once. The opaque result can be persisted and reused across batches without rescanning section text from the beginning. maxOccurrences <= 0 means no caller-imposed limit.

func PrepareStreamCappedContext

func PrepareStreamCappedContext(ctx context.Context, parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)

PrepareStreamCappedContext is the readiness planner. It performs the allocation-free v3 preflight before materializing an exact boundary plan. Dense inputs can stop at the maxOccurrences+1 sentinel while sparse inputs fail closed above readiness's separate exact-planning allocation ceiling.

func PrepareStreamCommandContext

func PrepareStreamCommandContext(ctx context.Context, parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)

PrepareStreamCommandContext is the projection-worker planner. It shares the allocation-free occurrence preflight, cancellation checks, 4,096-section metadata cap, and 128 MiB input ceiling, but intentionally does not apply readiness's narrower 8 MiB exact-planning cap. Projection execution is independently bounded by its 50k chunk, 200k occurrence, and 128 MiB staged state contract.

func PrepareStreamContext

func PrepareStreamContext(ctx context.Context, parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)

PrepareStreamContext computes the same deterministic plan as PrepareStream while allowing readiness/status callers to cancel bounded planning before a large dirty parent monopolizes a read transaction.

func (PreparedStreamPlan) MarshalBinary

func (p PreparedStreamPlan) MarshalBinary() ([]byte, error)

func (PreparedStreamPlan) OccurrenceCount

func (p PreparedStreamPlan) OccurrenceCount() int

type PreparedStreamSession

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

PreparedStreamSession owns the normalized parent and its validated plan for one projection invocation. Reusing it across batches avoids re-normalizing and re-hashing the complete parent at every durable checkpoint.

func ParsePreparedStreamSessionContext

func ParsePreparedStreamSessionContext(ctx context.Context, parent Parent, opts Options, encoded []byte, maxOccurrences int) (PreparedStreamSession, error)

func PrepareStreamCommandSessionContext

func PrepareStreamCommandSessionContext(ctx context.Context, parent Parent, opts Options, maxOccurrences int) (PreparedStreamSession, error)

func (*PreparedStreamSession) MarshalPlanBinary

func (s *PreparedStreamSession) MarshalPlanBinary() ([]byte, string, error)

func (PreparedStreamSession) Plan

func (PreparedStreamSession) PlanDigest

func (s PreparedStreamSession) PlanDigest() string

func (PreparedStreamSession) Stream

func (s PreparedStreamSession) Stream(cursor Cursor, emit func(Chunk, Occurrence) error) (Cursor, bool, error)

func (PreparedStreamSession) StreamContext

func (s PreparedStreamSession) StreamContext(ctx context.Context, cursor Cursor, emit func(Chunk, Occurrence) error) (Cursor, bool, error)

type Projection

type Projection struct {
	ParentHash  string
	Chunks      []Chunk
	Occurrences []Occurrence
}

Projection is the v2 parent projection. Chunks are unique content windows; occurrences retain the parent-local locations without polluting chunk IDs.

func BuildProjection

func BuildProjection(parent Parent, opts Options) (Projection, error)

type Section

type Section struct {
	// Key is a durable content-section identity. It intentionally excludes the
	// section text so changing a word does not invalidate all later windows.
	Key     string
	Role    string
	Heading string
	Text    string
	Derived bool
}

Jump to

Keyboard shortcuts

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