Documentation
¶
Index ¶
- Constants
- func CountOccurrencesCappedContext(ctx context.Context, parent Parent, opts Options, limit int) (int, error)
- func IsRawSupportRole(role string) bool
- func ParentProjectionHash(parent Parent) (string, error)
- func ParentProjectionHashContext(ctx context.Context, parent Parent) (string, error)
- func PreparedStreamPlanDigest(encoded []byte) string
- type Chunk
- type Cursor
- type Occurrence
- type Options
- type Parent
- type PreparedStreamOccurrenceLimitError
- type PreparedStreamPlan
- func ParsePreparedStreamPlan(parent Parent, opts Options, encoded []byte, maxOccurrences int) (PreparedStreamPlan, error)
- func ParsePreparedStreamPlanContext(ctx context.Context, parent Parent, opts Options, encoded []byte, ...) (PreparedStreamPlan, error)
- func PrepareStream(parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)
- func PrepareStreamCappedContext(ctx context.Context, parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)
- func PrepareStreamCommandContext(ctx context.Context, parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)
- func PrepareStreamContext(ctx context.Context, parent Parent, opts Options, maxOccurrences int) (PreparedStreamPlan, error)
- type PreparedStreamSession
- func (s *PreparedStreamSession) MarshalPlanBinary() ([]byte, string, error)
- func (s PreparedStreamSession) Plan() PreparedStreamPlan
- func (s PreparedStreamSession) PlanDigest() string
- func (s PreparedStreamSession) Stream(cursor Cursor, emit func(Chunk, Occurrence) error) (Cursor, bool, error)
- func (s PreparedStreamSession) StreamContext(ctx context.Context, cursor Cursor, emit func(Chunk, Occurrence) error) (Cursor, bool, error)
- type Projection
- type Section
Constants ¶
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 ¶
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 ¶
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 ¶
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.
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
}
type Cursor ¶
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 ¶
Occurrence records where a reusable content-local chunk occurs in one projected section. Offsets are rune offsets in the untrimmed Section.Text.
type Options ¶
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 ProjectSource ¶
func ProjectSource(source model.SourceDocument) Parent
type PreparedStreamOccurrenceLimitError ¶
func (*PreparedStreamOccurrenceLimitError) Error ¶
func (e *PreparedStreamOccurrenceLimitError) Error() string
type PreparedStreamPlan ¶
type PreparedStreamPlan struct {
// contains filtered or unexported fields
}
func ParsePreparedStreamPlan ¶
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 (*PreparedStreamSession) MarshalPlanBinary ¶
func (s *PreparedStreamSession) MarshalPlanBinary() ([]byte, string, error)
func (PreparedStreamSession) Plan ¶
func (s PreparedStreamSession) Plan() PreparedStreamPlan
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)